@@ -504,19 +504,26 @@ fn sanity_check_found_hidden_type<'tcx>(
504
504
_ => l,
505
505
} ,
506
506
} ) ;
507
- // Get the hidden type, and in case it is in a nested opaque type, find that opaque type's
508
- // usage in the function signature and use the generic arguments from the usage site.
507
+ // Get the hidden type.
509
508
let mut hidden_ty = tcx. type_of ( key. def_id ) . instantiate ( tcx, key. args ) ;
509
+ // In case it is in a nested opaque type, find that opaque type's
510
+ // usage in the function signature and use the generic arguments from the usage site.
511
+ // We need to do because RPITs ignore the lifetimes of the function,
512
+ // as they have their own copies of all the lifetimes they capture.
513
+ // So the only way to get the lifetimes represented in terms of the function,
514
+ // is to look how they are used in the function signature (or do some other fancy
515
+ // recording of this mapping at ast -> hir lowering time).
510
516
if let hir:: OpaqueTyOrigin :: FnReturn ( ..) | hir:: OpaqueTyOrigin :: AsyncFn ( ..) = origin {
511
517
if hidden_ty != ty. ty {
512
- hidden_ty = find_and_apply_rpit_substs (
518
+ hidden_ty = find_and_apply_rpit_args (
513
519
tcx,
514
520
hidden_ty,
515
521
defining_use_anchor. to_def_id ( ) ,
516
522
key. def_id . to_def_id ( ) ,
517
523
) ?;
518
524
}
519
525
}
526
+
520
527
// If the hidden types differ, emit a type mismatch diagnostic.
521
528
if hidden_ty == ty. ty {
522
529
Ok ( ( ) )
@@ -527,13 +534,13 @@ fn sanity_check_found_hidden_type<'tcx>(
527
534
}
528
535
}
529
536
530
- fn find_and_apply_rpit_substs < ' tcx > (
537
+ fn find_and_apply_rpit_args < ' tcx > (
531
538
tcx : TyCtxt < ' tcx > ,
532
539
mut hidden_ty : Ty < ' tcx > ,
533
540
function : DefId ,
534
541
opaque : DefId ,
535
542
) -> Result < Ty < ' tcx > , ErrorGuaranteed > {
536
- // Find use of the RPIT in the function signature and thus find the right substs to
543
+ // Find use of the RPIT in the function signature and thus find the right args to
537
544
// convert it into the parameter space of the function signature. This is needed,
538
545
// because that's what `type_of` returns, against which we compare later.
539
546
let ret = tcx. fn_sig ( function) . instantiate_identity ( ) . output ( ) ;
0 commit comments