about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src
diff options
context:
space:
mode:
authorSantiago Pastorino <spastorino@gmail.com>2022-08-03 17:06:30 -0300
committerSantiago Pastorino <spastorino@gmail.com>2022-08-04 11:26:58 -0300
commit78585098b5914a978b1c11d770e13541b97bd11f (patch)
treea18b5abe3ad32050c5210861a1c844dfd659ecc2 /compiler/rustc_ast_lowering/src
parent40bcbed3c7809fe779734d6a5c93e4b5e5d4b420 (diff)
downloadrust-78585098b5914a978b1c11d770e13541b97bd11f.tar.gz
rust-78585098b5914a978b1c11d770e13541b97bd11f.zip
Add comments about lifetime collect and create lifetime defs for RPITs
Diffstat (limited to 'compiler/rustc_ast_lowering/src')
-rw-r--r--compiler/rustc_ast_lowering/src/lib.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index 69398918f89..e7a20651107 100644
--- a/compiler/rustc_ast_lowering/src/lib.rs
+++ b/compiler/rustc_ast_lowering/src/lib.rs
@@ -1345,10 +1345,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
 
         self.with_hir_id_owner(opaque_ty_node_id, |lctx| {
             if origin != hir::OpaqueTyOrigin::TyAlias {
+                // When lowering `fn foo<'a>() -> impl Debug + 'a`, the `lifetime_collector` finds
+                // the set of lifetimes that appear in the bounds (in this case, 'a) and returns
+                // that set in the variable lifetimes_in_bounds.
                 let lifetimes_in_bounds =
                     lifetime_collector::lifetimes_in_bounds(&lctx.resolver, bounds);
                 debug!(?lifetimes_in_bounds);
 
+                // For each captured lifetime (e.g., 'a), we create a new lifetime parameter that
+                // is a generic defined on the TAIT, so we have type Foo<'a1> = ... and we
+                // establish a mapping from the original parameter 'a to the new parameter 'a1.
                 collected_lifetimes = lctx.create_lifetime_defs(
                     opaque_ty_def_id,
                     &lifetimes_in_bounds,
@@ -1359,6 +1365,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
             debug!(?collected_lifetimes);
 
             lctx.with_remapping(new_remapping, |lctx| {
+                // Then when we lower the param bounds, references to 'a are remapped to 'a1, so we
+                // get back Debug + 'a1, which is suitable for use on the TAIT.
                 let hir_bounds = lctx.lower_param_bounds(bounds, itctx);
 
                 let lifetime_defs = lctx.arena.alloc_from_iter(collected_lifetimes.iter().map(