@@ -2456,7 +2456,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2456
2456
let target_span = tables
2457
2457
. generator_interior_types
2458
2458
. iter ( )
2459
- . zip ( tables. generator_interior_exprs . iter ( ) )
2460
2459
. find ( |( ty:: GeneratorInteriorTypeCause { ty, .. } , _) | {
2461
2460
// Careful: the regions for types that appear in the
2462
2461
// generator interior are not generally known, so we
@@ -2578,37 +2577,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2578
2577
} ;
2579
2578
2580
2579
span. push_span_label ( original_span, message) ;
2581
- err. set_span ( span. clone ( ) ) ;
2580
+ err. set_span ( span) ;
2582
2581
2583
2582
format ! ( "is not {}" , trait_name)
2584
2583
} else {
2585
2584
format ! ( "does not implement `{}`" , trait_ref. print_only_trait_path( ) )
2586
2585
} ;
2587
2586
2588
2587
// Look at the last interior type to get a span for the `.await`.
2589
- let await_span = tables. generator_interior_types . iter ( ) . map ( |i| i. span ) . last ( ) . unwrap ( ) ;
2588
+ let await_span =
2589
+ tables. generator_interior_types . iter ( ) . map ( |( i, _) | i. span ) . last ( ) . unwrap ( ) ;
2590
2590
let mut span = MultiSpan :: from_span ( await_span) ;
2591
2591
span. push_span_label (
2592
2592
await_span,
2593
2593
format ! ( "{} occurs here, with `{}` maybe used later" , await_or_yield, snippet) ,
2594
2594
) ;
2595
2595
2596
- if let Some ( expr_id) = expr {
2597
- let expr = hir. expect_expr ( expr_id) ;
2598
- let is_ref = tables. expr_adjustments ( expr) . iter ( ) . any ( |adj| adj. is_region_borrow ( ) ) ;
2599
- let parent = hir. get_parent_node ( expr_id) ;
2600
- if let Some ( hir:: Node :: Expr ( e) ) = hir. find ( parent) {
2601
- let method_span = hir. span ( parent) ;
2602
- if tables. is_method_call ( e) && is_ref {
2603
- err. span_help (
2604
- method_span,
2605
- "consider moving this method call into a `let` \
2606
- binding to create a shorter lived borrow"
2607
- ) ;
2608
- }
2609
- }
2610
- }
2611
-
2612
2596
span. push_span_label ( target_span, format ! ( "has type `{}`" , target_ty) ) ;
2613
2597
2614
2598
// If available, use the scope span to annotate the drop location.
@@ -2627,6 +2611,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2627
2611
) ,
2628
2612
) ;
2629
2613
2614
+ if let Some ( expr_id) = expr {
2615
+ let expr = hir. expect_expr ( expr_id) ;
2616
+ let is_ref = tables. expr_adjustments ( expr) . iter ( ) . any ( |adj| adj. is_region_borrow ( ) ) ;
2617
+ let parent = hir. get_parent_node ( expr_id) ;
2618
+ if let Some ( hir:: Node :: Expr ( e) ) = hir. find ( parent) {
2619
+ let method_span = hir. span ( parent) ;
2620
+ if tables. is_method_call ( e) && is_ref {
2621
+ err. span_help (
2622
+ method_span,
2623
+ "consider moving this method call into a `let` \
2624
+ binding to create a shorter lived borrow",
2625
+ ) ;
2626
+ }
2627
+ }
2628
+ }
2629
+
2630
2630
// Add a note for the item obligation that remains - normally a note pointing to the
2631
2631
// bound that introduced the obligation (e.g. `T: Send`).
2632
2632
debug ! ( "note_obligation_cause_for_async_await: next_code={:?}" , next_code) ;
0 commit comments