@@ -214,7 +214,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
214214 let generics = tcx. generics_of ( self . mir_def_id ) ;
215215 let param = generics. type_param ( & param_ty, tcx) ;
216216 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 ( ) ) )
218218 {
219219 suggest_constraining_type_param (
220220 tcx,
@@ -865,49 +865,42 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
865865 format ! ( "`{}` would have to be valid for `{}`..." , name, region_name) ,
866866 ) ;
867867
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+ ) ;
896895
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+ ) ;
911904
912905 if let BorrowExplanation :: MustBeValidFor { .. } = explanation {
913906 } else {
@@ -1237,7 +1230,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12371230 ) -> DiagnosticBuilder < ' cx > {
12381231 let tcx = self . infcx . tcx ;
12391232
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 ( ) ) ;
12411234
12421235 let mut err =
12431236 borrowck_errors:: borrowed_data_escapes_closure ( tcx, escape_span, escapes_from) ;
@@ -1572,14 +1565,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15721565 ) -> Option < AnnotatedBorrowFnSignature < ' tcx > > {
15731566 // Define a fallback for when we can't match a closure.
15741567 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 ( ) ) ;
15761569 if is_closure {
15771570 None
15781571 } else {
15791572 let ty = self . infcx . tcx . type_of ( self . mir_def_id ) ;
15801573 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+ ) ,
15831578 _ => None ,
15841579 }
15851580 }
0 commit comments