@@ -49,7 +49,7 @@ use rustc_middle::ty::print::{with_forced_trimmed_paths, with_no_trimmed_paths};
49
49
#[ derive( Debug ) ]
50
50
pub enum GeneratorInteriorOrUpvar {
51
51
// span of interior type
52
- Interior ( Span , Option < ( Option < Span > , Span , Option < hir :: HirId > , Option < Span > ) > ) ,
52
+ Interior ( Span , Option < ( Span , Option < Span > ) > ) ,
53
53
// span of upvar
54
54
Upvar ( Span ) ,
55
55
}
@@ -249,7 +249,6 @@ pub trait TypeErrCtxtExt<'tcx> {
249
249
outer_generator : Option < DefId > ,
250
250
trait_pred : ty:: TraitPredicate < ' tcx > ,
251
251
target_ty : Ty < ' tcx > ,
252
- typeck_results : & ty:: TypeckResults < ' tcx > ,
253
252
obligation : & PredicateObligation < ' tcx > ,
254
253
next_code : Option < & ObligationCauseCode < ' tcx > > ,
255
254
) ;
@@ -2316,7 +2315,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2316
2315
if ty_matches ( ty:: Binder :: dummy ( decl. ty ) ) && !decl. ignore_for_traits {
2317
2316
interior_or_upvar_span = Some ( GeneratorInteriorOrUpvar :: Interior (
2318
2317
decl. source_info . span ,
2319
- Some ( ( None , source_info. span , None , from_awaited_ty) ) ,
2318
+ Some ( ( source_info. span , from_awaited_ty) ) ,
2320
2319
) ) ;
2321
2320
break ' find_source;
2322
2321
}
@@ -2336,15 +2335,13 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2336
2335
debug ! ( ?interior_or_upvar_span) ;
2337
2336
if let Some ( interior_or_upvar_span) = interior_or_upvar_span {
2338
2337
let is_async = self . tcx . generator_is_async ( generator_did) ;
2339
- let typeck_results = generator_data. 0 ;
2340
2338
self . note_obligation_cause_for_async_await (
2341
2339
err,
2342
2340
interior_or_upvar_span,
2343
2341
is_async,
2344
2342
outer_generator,
2345
2343
trait_ref,
2346
2344
target_ty,
2347
- typeck_results,
2348
2345
obligation,
2349
2346
next_code,
2350
2347
) ;
@@ -2365,7 +2362,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2365
2362
outer_generator : Option < DefId > ,
2366
2363
trait_pred : ty:: TraitPredicate < ' tcx > ,
2367
2364
target_ty : Ty < ' tcx > ,
2368
- typeck_results : & ty:: TypeckResults < ' tcx > ,
2369
2365
obligation : & PredicateObligation < ' tcx > ,
2370
2366
next_code : Option < & ObligationCauseCode < ' tcx > > ,
2371
2367
) {
@@ -2423,9 +2419,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2423
2419
format ! ( "does not implement `{}`" , trait_pred. print_modifiers_and_trait_path( ) )
2424
2420
} ;
2425
2421
2426
- let mut explain_yield = |interior_span : Span ,
2427
- yield_span : Span ,
2428
- scope_span : Option < Span > | {
2422
+ let mut explain_yield = |interior_span : Span , yield_span : Span | {
2429
2423
let mut span = MultiSpan :: from_span ( yield_span) ;
2430
2424
let snippet = match source_map. span_to_snippet ( interior_span) {
2431
2425
// #70935: If snippet contains newlines, display "the value" instead
@@ -2457,22 +2451,14 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2457
2451
interior_span,
2458
2452
format ! ( "has type `{target_ty}` which {trait_explanation}" ) ,
2459
2453
) ;
2460
- if let Some ( scope_span) = scope_span {
2461
- let scope_span = source_map. end_point ( scope_span) ;
2462
-
2463
- let msg = format ! ( "{snippet} is later dropped here" ) ;
2464
- span. push_span_label ( scope_span, msg) ;
2465
- }
2466
2454
err. span_note (
2467
- span,
2468
- format ! (
2469
- "{future_or_generator} {trait_explanation} as this value is used across {an_await_or_yield}"
2470
- ) ,
2471
- ) ;
2455
+ span,
2456
+ format ! ( "{future_or_generator} {trait_explanation} as this value is used across {an_await_or_yield}" ) ,
2457
+ ) ;
2472
2458
} ;
2473
2459
match interior_or_upvar_span {
2474
2460
GeneratorInteriorOrUpvar :: Interior ( interior_span, interior_extra_info) => {
2475
- if let Some ( ( scope_span , yield_span, expr , from_awaited_ty) ) = interior_extra_info {
2461
+ if let Some ( ( yield_span, from_awaited_ty) ) = interior_extra_info {
2476
2462
if let Some ( await_span) = from_awaited_ty {
2477
2463
// The type causing this obligation is one being awaited at await_span.
2478
2464
let mut span = MultiSpan :: from_span ( await_span) ;
@@ -2490,51 +2476,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2490
2476
) ;
2491
2477
} else {
2492
2478
// Look at the last interior type to get a span for the `.await`.
2493
- explain_yield ( interior_span, yield_span, scope_span) ;
2494
- }
2495
-
2496
- if let Some ( expr_id) = expr {
2497
- let expr = hir. expect_expr ( expr_id) ;
2498
- debug ! ( "target_ty evaluated from {:?}" , expr) ;
2499
-
2500
- let parent = hir. parent_id ( expr_id) ;
2501
- if let Some ( hir:: Node :: Expr ( e) ) = hir. find ( parent) {
2502
- let parent_span = hir. span ( parent) ;
2503
- let parent_did = parent. owner . to_def_id ( ) ;
2504
- // ```rust
2505
- // impl T {
2506
- // fn foo(&self) -> i32 {}
2507
- // }
2508
- // T.foo();
2509
- // ^^^^^^^ a temporary `&T` created inside this method call due to `&self`
2510
- // ```
2511
- //
2512
- let is_region_borrow = typeck_results
2513
- . expr_adjustments ( expr)
2514
- . iter ( )
2515
- . any ( |adj| adj. is_region_borrow ( ) ) ;
2516
-
2517
- // ```rust
2518
- // struct Foo(*const u8);
2519
- // bar(Foo(std::ptr::null())).await;
2520
- // ^^^^^^^^^^^^^^^^^^^^^ raw-ptr `*T` created inside this struct ctor.
2521
- // ```
2522
- debug ! ( parent_def_kind = ?self . tcx. def_kind( parent_did) ) ;
2523
- let is_raw_borrow_inside_fn_like_call =
2524
- match self . tcx . def_kind ( parent_did) {
2525
- DefKind :: Fn | DefKind :: Ctor ( ..) => target_ty. is_unsafe_ptr ( ) ,
2526
- _ => false ,
2527
- } ;
2528
- if ( typeck_results. is_method_call ( e) && is_region_borrow)
2529
- || is_raw_borrow_inside_fn_like_call
2530
- {
2531
- err. span_help (
2532
- parent_span,
2533
- "consider moving this into a `let` \
2534
- binding to create a shorter lived borrow",
2535
- ) ;
2536
- }
2537
- }
2479
+ explain_yield ( interior_span, yield_span) ;
2538
2480
}
2539
2481
}
2540
2482
}
0 commit comments