Skip to content

Commit 7858509

Browse files
committed
Add comments about lifetime collect and create lifetime defs for RPITs
1 parent 40bcbed commit 7858509

File tree

1 file changed

+8
-0
lines changed
  • compiler/rustc_ast_lowering/src

1 file changed

+8
-0
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,10 +1345,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13451345

13461346
self.with_hir_id_owner(opaque_ty_node_id, |lctx| {
13471347
if origin != hir::OpaqueTyOrigin::TyAlias {
1348+
// When lowering `fn foo<'a>() -> impl Debug + 'a`, the `lifetime_collector` finds
1349+
// the set of lifetimes that appear in the bounds (in this case, 'a) and returns
1350+
// that set in the variable lifetimes_in_bounds.
13481351
let lifetimes_in_bounds =
13491352
lifetime_collector::lifetimes_in_bounds(&lctx.resolver, bounds);
13501353
debug!(?lifetimes_in_bounds);
13511354

1355+
// For each captured lifetime (e.g., 'a), we create a new lifetime parameter that
1356+
// is a generic defined on the TAIT, so we have type Foo<'a1> = ... and we
1357+
// establish a mapping from the original parameter 'a to the new parameter 'a1.
13521358
collected_lifetimes = lctx.create_lifetime_defs(
13531359
opaque_ty_def_id,
13541360
&lifetimes_in_bounds,
@@ -1359,6 +1365,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13591365
debug!(?collected_lifetimes);
13601366

13611367
lctx.with_remapping(new_remapping, |lctx| {
1368+
// Then when we lower the param bounds, references to 'a are remapped to 'a1, so we
1369+
// get back Debug + 'a1, which is suitable for use on the TAIT.
13621370
let hir_bounds = lctx.lower_param_bounds(bounds, itctx);
13631371

13641372
let lifetime_defs = lctx.arena.alloc_from_iter(collected_lifetimes.iter().map(

0 commit comments

Comments
 (0)