@@ -2312,6 +2312,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23122312 let typeck_results = tcx. typeck ( self . mir_def_id ( ) ) ;
23132313
23142314 struct ExprFinder < ' hir > {
2315+ tcx : TyCtxt < ' hir > ,
23152316 issue_span : Span ,
23162317 expr_span : Span ,
23172318 body_expr : Option < & ' hir hir:: Expr < ' hir > > ,
@@ -2336,9 +2337,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23362337 // };
23372338 // corresponding to the desugaring of a for loop `for <pat> in <head> { <body> }`.
23382339 if let hir:: ExprKind :: Call ( path, [ arg] ) = ex. kind
2339- && let hir:: ExprKind :: Path ( hir :: QPath :: LangItem ( LangItem :: IntoIterIntoIter , _ ) ) =
2340- path . kind
2340+ && let hir:: ExprKind :: Path ( qpath ) = path . kind
2341+ && self . tcx . qpath_is_lang_item ( qpath , LangItem :: IntoIterIntoIter )
23412342 && arg. span . contains ( self . issue_span )
2343+ && ex. span . desugaring_kind ( ) == Some ( DesugaringKind :: ForLoop )
23422344 {
23432345 // Find `IntoIterator::into_iter(<head>)`
23442346 self . head = Some ( arg) ;
@@ -2355,10 +2357,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23552357 ..
23562358 } ) = stmt. kind
23572359 && let hir:: ExprKind :: Call ( path, _args) = call. kind
2358- && let hir:: ExprKind :: Path ( hir :: QPath :: LangItem ( LangItem :: IteratorNext , _ ) ) =
2359- path . kind
2360- && let hir:: PatKind :: Struct ( path , [ field, ..] , _) = bind. pat . kind
2361- && let hir :: QPath :: LangItem ( LangItem :: OptionSome , pat_span ) = path
2360+ && let hir:: ExprKind :: Path ( qpath ) = path . kind
2361+ && self . tcx . qpath_is_lang_item ( qpath , LangItem :: IteratorNext )
2362+ && let hir:: PatKind :: Struct ( qpath , [ field, ..] , _) = bind. pat . kind
2363+ && self . tcx . qpath_is_lang_item ( qpath , LangItem :: OptionSome )
23622364 && call. span . contains ( self . issue_span )
23632365 {
23642366 // Find `<pat>` and the span for the whole `for` loop.
@@ -2370,7 +2372,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23702372 self . loop_bind = Some ( ident) ;
23712373 }
23722374 self . head_span = Some ( * head_span) ;
2373- self . pat_span = Some ( pat_span ) ;
2375+ self . pat_span = Some ( bind . pat . span ) ;
23742376 self . loop_span = Some ( stmt. span ) ;
23752377 }
23762378
@@ -2385,6 +2387,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
23852387 }
23862388 }
23872389 let mut finder = ExprFinder {
2390+ tcx,
23882391 expr_span : span,
23892392 issue_span,
23902393 loop_bind : None ,
0 commit comments