@@ -506,13 +506,6 @@ fn sanity_check_found_hidden_type<'tcx>(
506
506
} ) ;
507
507
// Get the hidden type.
508
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).
516
509
if let hir:: OpaqueTyOrigin :: FnReturn ( ..) | hir:: OpaqueTyOrigin :: AsyncFn ( ..) = origin {
517
510
if hidden_ty != ty. ty {
518
511
hidden_ty = find_and_apply_rpit_args (
@@ -534,6 +527,36 @@ fn sanity_check_found_hidden_type<'tcx>(
534
527
}
535
528
}
536
529
530
+ /// In case it is in a nested opaque type, find that opaque type's
531
+ /// usage in the function signature and use the generic arguments from the usage site.
532
+ /// We need to do because RPITs ignore the lifetimes of the function,
533
+ /// as they have their own copies of all the lifetimes they capture.
534
+ /// So the only way to get the lifetimes represented in terms of the function,
535
+ /// is to look how they are used in the function signature (or do some other fancy
536
+ /// recording of this mapping at ast -> hir lowering time).
537
+ ///
538
+ /// As an example:
539
+ /// ```text
540
+ /// trait Id {
541
+ /// type Assoc;
542
+ /// }
543
+ /// impl<'a> Id for &'a () {
544
+ /// type Assoc = &'a ();
545
+ /// }
546
+ /// fn func<'a>(x: &'a ()) -> impl Id<Assoc = impl Sized + 'a> { x }
547
+ /// // desugared to
548
+ ///
549
+ /// // hidden type is `&'bDup ()`
550
+ /// // During wfcheck the hidden type of `Inner` is `&'a ()`, but
551
+ /// // `typeof(Inner<'b, 'bDup>) = &'bDup ()`.
552
+ /// // So we walk the signature of `func` to find the use of `Inner<'static, 'a>`
553
+ /// // and then use that to replace the lifetimes in the hidden type, obtaining
554
+ /// // `&'a ()`.
555
+ /// type Outer<'b, 'bDup> = impl Id<Assoc = Inner<'b, 'bDup>>;
556
+ /// // hidden type is `&'cDup ()`
557
+ /// type Inner<'c, 'cDup> = impl Sized + 'cDup;
558
+ /// fn func<'a>(x: &'a () -> Outer<'static, 'a> { x }
559
+ /// ```
537
560
fn find_and_apply_rpit_args < ' tcx > (
538
561
tcx : TyCtxt < ' tcx > ,
539
562
mut hidden_ty : Ty < ' tcx > ,
0 commit comments