@@ -1345,10 +1345,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1345
1345
1346
1346
self . with_hir_id_owner ( opaque_ty_node_id, |lctx| {
1347
1347
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.
1348
1351
let lifetimes_in_bounds =
1349
1352
lifetime_collector:: lifetimes_in_bounds ( & lctx. resolver , bounds) ;
1350
1353
debug ! ( ?lifetimes_in_bounds) ;
1351
1354
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.
1352
1358
collected_lifetimes = lctx. create_lifetime_defs (
1353
1359
opaque_ty_def_id,
1354
1360
& lifetimes_in_bounds,
@@ -1359,6 +1365,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1359
1365
debug ! ( ?collected_lifetimes) ;
1360
1366
1361
1367
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.
1362
1370
let hir_bounds = lctx. lower_param_bounds ( bounds, itctx) ;
1363
1371
1364
1372
let lifetime_defs = lctx. arena . alloc_from_iter ( collected_lifetimes. iter ( ) . map (
0 commit comments