@@ -214,7 +214,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
214
214
let generics = tcx. generics_of ( self . mir_def_id ) ;
215
215
let param = generics. type_param ( & param_ty, tcx) ;
216
216
if let Some ( generics) =
217
- tcx. hir ( ) . get_generics ( tcx. closure_base_def_id ( self . mir_def_id ) )
217
+ tcx. hir ( ) . get_generics ( tcx. closure_base_def_id ( self . mir_def_id . to_def_id ( ) ) )
218
218
{
219
219
suggest_constraining_type_param (
220
220
tcx,
@@ -865,49 +865,42 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
865
865
format ! ( "`{}` would have to be valid for `{}`..." , name, region_name) ,
866
866
) ;
867
867
868
- if let Some ( def_id) = self . mir_def_id . as_local ( ) {
869
- let fn_hir_id = self . infcx . tcx . hir ( ) . as_local_hir_id ( def_id) ;
870
- err. span_label (
871
- drop_span,
872
- format ! (
873
- "...but `{}` will be dropped here, when the {} returns" ,
874
- name,
875
- self . infcx
876
- . tcx
877
- . hir( )
878
- . opt_name( fn_hir_id)
879
- . map( |name| format!( "function `{}`" , name) )
880
- . unwrap_or_else( || {
881
- match & self
882
- . infcx
883
- . tcx
884
- . typeck_tables_of( def_id)
885
- . node_type( fn_hir_id)
886
- . kind
887
- {
888
- ty:: Closure ( ..) => "enclosing closure" ,
889
- ty:: Generator ( ..) => "enclosing generator" ,
890
- kind => bug!( "expected closure or generator, found {:?}" , kind) ,
891
- }
892
- . to_string( )
893
- } )
894
- ) ,
895
- ) ;
868
+ let fn_hir_id = self . infcx . tcx . hir ( ) . as_local_hir_id ( self . mir_def_id ) ;
869
+ err. span_label (
870
+ drop_span,
871
+ format ! (
872
+ "...but `{}` will be dropped here, when the {} returns" ,
873
+ name,
874
+ self . infcx
875
+ . tcx
876
+ . hir( )
877
+ . opt_name( fn_hir_id)
878
+ . map( |name| format!( "function `{}`" , name) )
879
+ . unwrap_or_else( || {
880
+ match & self
881
+ . infcx
882
+ . tcx
883
+ . typeck_tables_of( self . mir_def_id)
884
+ . node_type( fn_hir_id)
885
+ . kind
886
+ {
887
+ ty:: Closure ( ..) => "enclosing closure" ,
888
+ ty:: Generator ( ..) => "enclosing generator" ,
889
+ kind => bug!( "expected closure or generator, found {:?}" , kind) ,
890
+ }
891
+ . to_string( )
892
+ } )
893
+ ) ,
894
+ ) ;
896
895
897
- err. note (
898
- "functions cannot return a borrow to data owned within the function's scope, \
899
- functions can only return borrows to data passed as arguments",
900
- ) ;
901
- err. note (
902
- "to learn more, visit <https://doc.rust-lang.org/book/ch04-02-\
903
- references-and-borrowing.html#dangling-references>",
904
- ) ;
905
- } else {
906
- err. span_label (
907
- drop_span,
908
- format ! ( "...but `{}` dropped here while still borrowed" , name) ,
909
- ) ;
910
- }
896
+ err. note (
897
+ "functions cannot return a borrow to data owned within the function's scope, \
898
+ functions can only return borrows to data passed as arguments",
899
+ ) ;
900
+ err. note (
901
+ "to learn more, visit <https://doc.rust-lang.org/book/ch04-02-\
902
+ references-and-borrowing.html#dangling-references>",
903
+ ) ;
911
904
912
905
if let BorrowExplanation :: MustBeValidFor { .. } = explanation {
913
906
} else {
@@ -1237,7 +1230,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1237
1230
) -> DiagnosticBuilder < ' cx > {
1238
1231
let tcx = self . infcx . tcx ;
1239
1232
1240
- let ( _, escapes_from) = tcx. article_and_description ( self . mir_def_id ) ;
1233
+ let ( _, escapes_from) = tcx. article_and_description ( self . mir_def_id . to_def_id ( ) ) ;
1241
1234
1242
1235
let mut err =
1243
1236
borrowck_errors:: borrowed_data_escapes_closure ( tcx, escape_span, escapes_from) ;
@@ -1572,14 +1565,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
1572
1565
) -> Option < AnnotatedBorrowFnSignature < ' tcx > > {
1573
1566
// Define a fallback for when we can't match a closure.
1574
1567
let fallback = || {
1575
- let is_closure = self . infcx . tcx . is_closure ( self . mir_def_id ) ;
1568
+ let is_closure = self . infcx . tcx . is_closure ( self . mir_def_id . to_def_id ( ) ) ;
1576
1569
if is_closure {
1577
1570
None
1578
1571
} else {
1579
1572
let ty = self . infcx . tcx . type_of ( self . mir_def_id ) ;
1580
1573
match ty. kind {
1581
- ty:: FnDef ( _, _) | ty:: FnPtr ( _) => self
1582
- . annotate_fn_sig ( self . mir_def_id , self . infcx . tcx . fn_sig ( self . mir_def_id ) ) ,
1574
+ ty:: FnDef ( _, _) | ty:: FnPtr ( _) => self . annotate_fn_sig (
1575
+ self . mir_def_id . to_def_id ( ) ,
1576
+ self . infcx . tcx . fn_sig ( self . mir_def_id ) ,
1577
+ ) ,
1583
1578
_ => None ,
1584
1579
}
1585
1580
}
0 commit comments