@@ -606,12 +606,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
606606 }
607607 }
608608 Some ( ( false , err_label_span, message) ) => {
609- struct V {
609+ struct BindingFinder {
610610 span : Span ,
611611 hir_id : Option < hir:: HirId > ,
612612 }
613613
614- impl < ' tcx > Visitor < ' tcx > for V {
614+ impl < ' tcx > Visitor < ' tcx > for BindingFinder {
615615 fn visit_stmt ( & mut self , s : & ' tcx hir:: Stmt < ' tcx > ) {
616616 if let hir:: StmtKind :: Local ( local) = s. kind {
617617 if local. pat . span == self . span {
@@ -622,20 +622,23 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
622622 }
623623 }
624624 let hir_map = self . infcx . tcx . hir ( ) ;
625- let pat = loop {
626- // Poor man's try block
627- let def_id = self . body . source . def_id ( ) ;
628- let hir_id =
629- hir_map. local_def_id_to_hir_id ( def_id. as_local ( ) . unwrap ( ) ) ;
630- let node = hir_map. find ( hir_id) ;
631- let Some ( hir:: Node :: Item ( item) ) = node else { break None ; } ;
632- let hir:: ItemKind :: Fn ( .., body_id) = item. kind else { break None ; } ;
633- let body = self . infcx . tcx . hir ( ) . body ( body_id) ;
634- let mut v = V { span : err_label_span, hir_id : None } ;
625+ let def_id = self . body . source . def_id ( ) ;
626+ let hir_id = hir_map. local_def_id_to_hir_id ( def_id. expect_local ( ) ) ;
627+ let node = hir_map. find ( hir_id) ;
628+ let hir_id = if let Some ( hir:: Node :: Item ( item) ) = node
629+ && let hir:: ItemKind :: Fn ( .., body_id) = item. kind
630+ {
631+ let body = hir_map. body ( body_id) ;
632+ let mut v = BindingFinder {
633+ span : err_label_span,
634+ hir_id : None ,
635+ } ;
635636 v. visit_body ( body) ;
636- break v. hir_id ;
637+ v. hir_id
638+ } else {
639+ None
637640 } ;
638- if let Some ( hir_id) = pat
641+ if let Some ( hir_id) = hir_id
639642 && let Some ( hir:: Node :: Local ( local) ) = hir_map. find ( hir_id)
640643 {
641644 let ( changing, span, sugg) = match local. ty {
0 commit comments