diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-07-24 15:34:36 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2023-07-24 15:34:36 +0000 |
| commit | 30f787800a62077ebb211391320de4aad432b4a6 (patch) | |
| tree | 58309c64a01165559d7b5a00e5ed77dd7dbb4645 | |
| parent | 5b4549dd13778c6546ccb9d89c32a8fe9eb3b7b7 (diff) | |
| download | rust-30f787800a62077ebb211391320de4aad432b4a6.tar.gz rust-30f787800a62077ebb211391320de4aad432b4a6.zip | |
Explain RPITs in the way they actually work
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/check.rs | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 4379d7b77b1..96eb83f3768 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -545,17 +545,23 @@ fn sanity_check_found_hidden_type<'tcx>( /// } /// fn func<'a>(x: &'a ()) -> impl Id<Assoc = impl Sized + 'a> { x } /// // desugared to +/// fn func<'a>(x: &'a () -> Outer<'a, Assoc = Inner<'a>> { +/// // Note that in contrast to other nested items, RPIT type aliases can +/// // access their parents' generics. /// -/// // hidden type is `&'bDup ()` -/// // During wfcheck the hidden type of `Inner` is `&'a ()`, but -/// // `typeof(Inner<'b, 'bDup>) = &'bDup ()`. -/// // So we walk the signature of `func` to find the use of `Inner<'static, 'a>` -/// // and then use that to replace the lifetimes in the hidden type, obtaining -/// // `&'a ()`. -/// type Outer<'b, 'bDup> = impl Id<Assoc = Inner<'b, 'bDup>>; -/// // hidden type is `&'cDup ()` -/// type Inner<'c, 'cDup> = impl Sized + 'cDup; -/// fn func<'a>(x: &'a () -> Outer<'static, 'a> { x } +/// // hidden type is `&'aDupOuter ()` +/// // During wfcheck the hidden type of `Inner<'aDupOuter>` is `&'a ()`, but +/// // `typeof(Inner<'aDupOuter>) = &'aDupOuter ()`. +/// // So we walk the signature of `func` to find the use of `Inner<'a>` +/// // and then use that to replace the lifetimes in the hidden type, obtaining +/// // `&'a ()`. +/// type Outer<'aDupOuter> = impl Id<Assoc = Inner<'aDupOuter>>; +/// +/// // hidden type is `&'aDupInner ()` +/// type Inner<'aDupInner> = impl Sized + 'aDupInner; +/// +/// x +/// } /// ``` fn find_and_apply_rpit_args<'tcx>( tcx: TyCtxt<'tcx>, |
