@@ -2456,7 +2456,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
24562456 let target_span = tables
24572457 . generator_interior_types
24582458 . iter ( )
2459- . zip ( tables. generator_interior_exprs . iter ( ) )
24602459 . find ( |( ty:: GeneratorInteriorTypeCause { ty, .. } , _) | {
24612460 // Careful: the regions for types that appear in the
24622461 // generator interior are not generally known, so we
@@ -2578,37 +2577,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25782577 } ;
25792578
25802579 span. push_span_label ( original_span, message) ;
2581- err. set_span ( span. clone ( ) ) ;
2580+ err. set_span ( span) ;
25822581
25832582 format ! ( "is not {}" , trait_name)
25842583 } else {
25852584 format ! ( "does not implement `{}`" , trait_ref. print_only_trait_path( ) )
25862585 } ;
25872586
25882587 // 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 ( ) ;
25902590 let mut span = MultiSpan :: from_span ( await_span) ;
25912591 span. push_span_label (
25922592 await_span,
25932593 format ! ( "{} occurs here, with `{}` maybe used later" , await_or_yield, snippet) ,
25942594 ) ;
25952595
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-
26122596 span. push_span_label ( target_span, format ! ( "has type `{}`" , target_ty) ) ;
26132597
26142598 // If available, use the scope span to annotate the drop location.
@@ -2627,6 +2611,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
26272611 ) ,
26282612 ) ;
26292613
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+
26302630 // Add a note for the item obligation that remains - normally a note pointing to the
26312631 // bound that introduced the obligation (e.g. `T: Send`).
26322632 debug ! ( "note_obligation_cause_for_async_await: next_code={:?}" , next_code) ;
0 commit comments