1
Fork 0

Remove local_def_id from captured_lifetimes

This commit is contained in:
Santiago Pastorino 2022-08-02 23:20:15 -03:00
parent 2d826e27c4
commit f0db1d68e6
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF

View file

@ -137,13 +137,10 @@ struct LoweringContext<'a, 'hir> {
#[derive(Debug)] #[derive(Debug)]
struct LifetimeCaptureContext { struct LifetimeCaptureContext {
/// Set of lifetimes to rebind. /// Set of lifetimes to rebind.
captures: FxHashMap< captures: Vec<(
LocalDefId, // original parameter id Lifetime, // Lifetime parameter
( LifetimeRes, // original resolution
Lifetime, // Lifetime parameter )>,
LifetimeRes, // original resolution
),
>,
} }
trait ResolverAstLoweringExt { trait ResolverAstLoweringExt {
@ -1324,7 +1321,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id); let opaque_ty_def_id = self.local_def_id(opaque_ty_node_id);
let mut collected_lifetimes = FxHashMap::default(); let mut collected_lifetimes = Vec::new();
let mut new_remapping = FxHashMap::default(); let mut new_remapping = FxHashMap::default();
self.with_hir_id_owner(opaque_ty_node_id, |lctx| { self.with_hir_id_owner(opaque_ty_node_id, |lctx| {
@ -1360,8 +1357,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}; };
debug!(?collected_lifetimes); debug!(?collected_lifetimes);
let lifetime_defs = lctx.arena.alloc_from_iter(collected_lifetimes.iter().map( let lifetime_defs =
|(_, &(lifetime, _))| { lctx.arena.alloc_from_iter(collected_lifetimes.iter().map(|&(lifetime, _)| {
let hir_id = lctx.lower_node_id(lifetime.id); let hir_id = lctx.lower_node_id(lifetime.id);
debug_assert_ne!(lctx.opt_local_def_id(lifetime.id), None); debug_assert_ne!(lctx.opt_local_def_id(lifetime.id), None);
@ -1379,8 +1376,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
kind: hir::GenericParamKind::Lifetime { kind }, kind: hir::GenericParamKind::Lifetime { kind },
colon_span: None, colon_span: None,
} }
}, }));
));
debug!("lower_opaque_impl_trait: lifetime_defs={:#?}", lifetime_defs); debug!("lower_opaque_impl_trait: lifetime_defs={:#?}", lifetime_defs);
@ -1400,8 +1396,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
lctx.generate_opaque_type(opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span) lctx.generate_opaque_type(opaque_ty_def_id, opaque_ty_item, span, opaque_ty_span)
}); });
let lifetimes = self.arena.alloc_from_iter(collected_lifetimes.into_iter().map( let lifetimes =
|(_, (lifetime, res))| { self.arena.alloc_from_iter(collected_lifetimes.into_iter().map(|(lifetime, res)| {
let id = self.next_node_id(); let id = self.next_node_id();
let span = lifetime.ident.span; let span = lifetime.ident.span;
@ -1413,8 +1409,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let l = self.new_named_lifetime_with_res(id, span, ident, res); let l = self.new_named_lifetime_with_res(id, span, ident, res);
hir::GenericArg::Lifetime(l) hir::GenericArg::Lifetime(l)
}, }));
));
debug!("lower_opaque_impl_trait: lifetimes={:#?}", lifetimes); debug!("lower_opaque_impl_trait: lifetimes={:#?}", lifetimes);
@ -1468,7 +1463,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
remapping.insert(old_def_id, new_def_id); remapping.insert(old_def_id, new_def_id);
let new_lifetime = Lifetime { id: node_id, ident: lifetime.ident }; let new_lifetime = Lifetime { id: node_id, ident: lifetime.ident };
captured_lifetimes.captures.insert(old_def_id, (new_lifetime, res)); captured_lifetimes.captures.push((new_lifetime, res));
} }
} }
@ -1486,7 +1481,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
remapping.insert(old_def_id, new_def_id); remapping.insert(old_def_id, new_def_id);
let new_lifetime = Lifetime { id: node_id, ident: lifetime.ident }; let new_lifetime = Lifetime { id: node_id, ident: lifetime.ident };
captured_lifetimes.captures.insert(old_def_id, (new_lifetime, res)); captured_lifetimes.captures.push((new_lifetime, res));
} }
} }
@ -1694,7 +1689,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// by the opaque type. This should include all in-scope // by the opaque type. This should include all in-scope
// lifetime parameters, including those defined in-band. // lifetime parameters, including those defined in-band.
let mut captures = FxHashMap::default(); let mut captures = Vec::new();
let mut new_remapping = FxHashMap::default(); let mut new_remapping = FxHashMap::default();
let extra_lifetime_params = self.resolver.take_extra_lifetime_params(opaque_ty_node_id); let extra_lifetime_params = self.resolver.take_extra_lifetime_params(opaque_ty_node_id);
@ -1730,7 +1725,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}; };
let new_lifetime = Lifetime { id: inner_node_id, ident }; let new_lifetime = Lifetime { id: inner_node_id, ident };
captures.insert(outer_def_id, (new_lifetime, inner_res)); captures.push((new_lifetime, inner_res));
} }
debug!(?captures); debug!(?captures);
@ -1768,7 +1763,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let future_bound = ret; let future_bound = ret;
let generic_params = let generic_params =
this.arena.alloc_from_iter(captures.iter().map(|(_, &(lifetime, _))| { this.arena.alloc_from_iter(captures.iter().map(|&(lifetime, _)| {
let hir_id = this.lower_node_id(lifetime.id); let hir_id = this.lower_node_id(lifetime.id);
debug_assert_ne!(this.opt_local_def_id(lifetime.id), None); debug_assert_ne!(this.opt_local_def_id(lifetime.id), None);
@ -1821,7 +1816,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// For the "output" lifetime parameters, we just want to // For the "output" lifetime parameters, we just want to
// generate `'_`. // generate `'_`.
let generic_args = let generic_args =
self.arena.alloc_from_iter(captures.into_iter().map(|(_, (lifetime, res))| { self.arena.alloc_from_iter(captures.into_iter().map(|(lifetime, res)| {
let id = self.next_node_id(); let id = self.next_node_id();
let span = lifetime.ident.span; let span = lifetime.ident.span;