Skip to content

Commit 30f7878

Browse files
committed
Explain RPITs in the way they actually work
1 parent 5b4549d commit 30f7878

File tree

1 file changed

+16
-10
lines changed
  • compiler/rustc_hir_analysis/src/check

1 file changed

+16
-10
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -545,17 +545,23 @@ fn sanity_check_found_hidden_type<'tcx>(
545545
/// }
546546
/// fn func<'a>(x: &'a ()) -> impl Id<Assoc = impl Sized + 'a> { x }
547547
/// // desugared to
548+
/// fn func<'a>(x: &'a () -> Outer<'a, Assoc = Inner<'a>> {
549+
/// // Note that in contrast to other nested items, RPIT type aliases can
550+
/// // access their parents' generics.
548551
///
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 }
552+
/// // hidden type is `&'aDupOuter ()`
553+
/// // During wfcheck the hidden type of `Inner<'aDupOuter>` is `&'a ()`, but
554+
/// // `typeof(Inner<'aDupOuter>) = &'aDupOuter ()`.
555+
/// // So we walk the signature of `func` to find the use of `Inner<'a>`
556+
/// // and then use that to replace the lifetimes in the hidden type, obtaining
557+
/// // `&'a ()`.
558+
/// type Outer<'aDupOuter> = impl Id<Assoc = Inner<'aDupOuter>>;
559+
///
560+
/// // hidden type is `&'aDupInner ()`
561+
/// type Inner<'aDupInner> = impl Sized + 'aDupInner;
562+
///
563+
/// x
564+
/// }
559565
/// ```
560566
fn find_and_apply_rpit_args<'tcx>(
561567
tcx: TyCtxt<'tcx>,

0 commit comments

Comments
 (0)