@@ -606,12 +606,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
606
606
}
607
607
}
608
608
Some ( ( false , err_label_span, message) ) => {
609
- struct V {
609
+ struct BindingFinder {
610
610
span : Span ,
611
611
hir_id : Option < hir:: HirId > ,
612
612
}
613
613
614
- impl < ' tcx > Visitor < ' tcx > for V {
614
+ impl < ' tcx > Visitor < ' tcx > for BindingFinder {
615
615
fn visit_stmt ( & mut self , s : & ' tcx hir:: Stmt < ' tcx > ) {
616
616
if let hir:: StmtKind :: Local ( local) = s. kind {
617
617
if local. pat . span == self . span {
@@ -622,20 +622,23 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
622
622
}
623
623
}
624
624
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
+ } ;
635
636
v. visit_body ( body) ;
636
- break v. hir_id ;
637
+ v. hir_id
638
+ } else {
639
+ None
637
640
} ;
638
- if let Some ( hir_id) = pat
641
+ if let Some ( hir_id) = hir_id
639
642
&& let Some ( hir:: Node :: Local ( local) ) = hir_map. find ( hir_id)
640
643
{
641
644
let ( changing, span, sugg) = match local. ty {
0 commit comments