@@ -1568,7 +1568,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1568
1568
1569
1569
// This creates HIR lifetime arguments as `hir::GenericArg`, in the given example `type
1570
1570
// TestReturn<'a, T, 'x> = impl Debug + 'x`, it creates a collection containing `&['x]`.
1571
- let lifetime_mapping : Vec<_> = collected_lifetimes
1571
+ let collected_lifetime_mapping : Vec<_> = collected_lifetimes
1572
1572
.iter()
1573
1573
.map(|(node_id, lifetime)| {
1574
1574
let id = self.next_node_id();
@@ -1577,7 +1577,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1577
1577
(lifetime, def_id)
1578
1578
})
1579
1579
.collect();
1580
- debug!(?lifetime_mapping );
1580
+ debug!(?collected_lifetime_mapping );
1581
1581
1582
1582
self.with_hir_id_owner(opaque_ty_node_id, |lctx| {
1583
1583
// Install the remapping from old to new (if any):
@@ -1618,6 +1618,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1618
1618
let hir_bounds = lctx.lower_param_bounds(bounds, itctx);
1619
1619
debug!(?hir_bounds);
1620
1620
1621
+ let lifetime_mapping = if in_trait {
1622
+ self.arena.alloc_from_iter(
1623
+ collected_lifetime_mapping
1624
+ .iter()
1625
+ .map(|(lifetime, def_id)| (**lifetime, *def_id)),
1626
+ )
1627
+ } else {
1628
+ &mut []
1629
+ };
1630
+
1621
1631
let opaque_ty_item = hir::OpaqueTy {
1622
1632
generics: self.arena.alloc(hir::Generics {
1623
1633
params: lifetime_defs,
@@ -1628,9 +1638,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1628
1638
}),
1629
1639
bounds: hir_bounds,
1630
1640
origin,
1631
- lifetime_mapping: self.arena.alloc_from_iter(
1632
- lifetime_mapping.iter().map(|(lifetime, def_id)| (**lifetime, *def_id)),
1633
- ),
1641
+ lifetime_mapping,
1634
1642
in_trait,
1635
1643
};
1636
1644
debug!(?opaque_ty_item);
@@ -1643,7 +1651,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1643
1651
hir::TyKind::OpaqueDef(
1644
1652
hir::ItemId { owner_id: hir::OwnerId { def_id: opaque_ty_def_id } },
1645
1653
self.arena.alloc_from_iter(
1646
- lifetime_mapping.iter().map(|(lifetime, _)| hir::GenericArg::Lifetime(*lifetime)),
1654
+ collected_lifetime_mapping
1655
+ .iter()
1656
+ .map(|(lifetime, _)| hir::GenericArg::Lifetime(*lifetime)),
1647
1657
),
1648
1658
in_trait,
1649
1659
)
@@ -2010,7 +2020,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2010
2020
// TestReturn<'a, T, 'x> = impl Debug + 'x`, it creates a collection containing the
2011
2021
// new lifetime of the RPIT 'x and the def_id of the lifetime 'x corresponding to
2012
2022
// `TestReturn`.
2013
- let lifetime_mapping : Vec<_> = collected_lifetimes
2023
+ let collected_lifetime_mapping : Vec<_> = collected_lifetimes
2014
2024
.iter()
2015
2025
.map(|(node_id, lifetime, res)| {
2016
2026
let id = self.next_node_id();
@@ -2022,7 +2032,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2022
2032
(lifetime, def_id)
2023
2033
})
2024
2034
.collect();
2025
- debug!(?lifetime_mapping );
2035
+ debug!(?collected_lifetime_mapping );
2026
2036
2027
2037
self.with_hir_id_owner(opaque_ty_node_id, |this| {
2028
2038
// Install the remapping from old to new (if any):
@@ -2079,6 +2089,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2079
2089
));
2080
2090
debug!("lower_async_fn_ret_ty: generic_params={:#?}", generic_params);
2081
2091
2092
+ let lifetime_mapping = if in_trait {
2093
+ self.arena.alloc_from_iter(
2094
+ collected_lifetime_mapping
2095
+ .iter()
2096
+ .map(|(lifetime, def_id)| (**lifetime, *def_id)),
2097
+ )
2098
+ } else {
2099
+ &mut []
2100
+ };
2101
+
2082
2102
let opaque_ty_item = hir::OpaqueTy {
2083
2103
generics: this.arena.alloc(hir::Generics {
2084
2104
params: generic_params,
@@ -2089,9 +2109,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2089
2109
}),
2090
2110
bounds: arena_vec![this; future_bound],
2091
2111
origin: hir::OpaqueTyOrigin::AsyncFn(fn_def_id),
2092
- lifetime_mapping: self.arena.alloc_from_iter(
2093
- lifetime_mapping.iter().map(|(lifetime, def_id)| (**lifetime, *def_id)),
2094
- ),
2112
+ lifetime_mapping,
2095
2113
in_trait,
2096
2114
};
2097
2115
@@ -2116,7 +2134,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2116
2134
// For the "output" lifetime parameters, we just want to
2117
2135
// generate `'_`.
2118
2136
let generic_args = self.arena.alloc_from_iter(
2119
- lifetime_mapping.iter().map(|(lifetime, _)| hir::GenericArg::Lifetime(*lifetime)),
2137
+ collected_lifetime_mapping
2138
+ .iter()
2139
+ .map(|(lifetime, _)| hir::GenericArg::Lifetime(*lifetime)),
2120
2140
);
2121
2141
2122
2142
// Create the `Foo<...>` reference itself. Note that the `type
0 commit comments