Leave the responsibility to create Fresh
lifetimes to lowering.
This commit is contained in:
parent
dc614b90ca
commit
bc6a2c11ee
4 changed files with 34 additions and 30 deletions
|
@ -1386,16 +1386,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||
|
||||
let mut params: SmallVec<[hir::GenericParam<'hir>; 4]> =
|
||||
self.lower_generic_params_mut(&generics.params).collect();
|
||||
|
||||
// Introduce extra lifetimes if late resolution tells us to.
|
||||
let extra_lifetimes = self.resolver.take_extra_lifetime_params(parent_node_id);
|
||||
params.extend(extra_lifetimes.into_iter().filter_map(|(ident, node_id, res)| {
|
||||
self.lifetime_res_to_generic_param(ident, node_id, res)
|
||||
}));
|
||||
|
||||
let has_where_clause_predicates = !generics.where_clause.predicates.is_empty();
|
||||
let where_clause_span = self.lower_span(generics.where_clause.span);
|
||||
let span = self.lower_span(generics.span);
|
||||
let res = f(self);
|
||||
|
||||
let extra_lifetimes = self.resolver.take_extra_lifetime_params(parent_node_id);
|
||||
let impl_trait_defs = std::mem::take(&mut self.impl_trait_defs);
|
||||
params.extend(extra_lifetimes.into_iter().filter_map(|(ident, node_id, res)| {
|
||||
self.lifetime_res_to_generic_param(ident, node_id, res)
|
||||
}));
|
||||
params.extend(impl_trait_defs.into_iter());
|
||||
|
||||
let impl_trait_bounds = std::mem::take(&mut self.impl_trait_bounds);
|
||||
|
|
|
@ -731,7 +731,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
LifetimeRes::Param { .. } => {
|
||||
(hir::ParamName::Plain(ident), hir::LifetimeParamKind::Explicit)
|
||||
}
|
||||
LifetimeRes::Fresh { .. } => (hir::ParamName::Fresh, hir::LifetimeParamKind::Elided),
|
||||
LifetimeRes::Fresh { param, .. } => {
|
||||
// Late resolution delegates to us the creation of the `LocalDefId`.
|
||||
let _def_id = self.create_def(
|
||||
self.current_hir_id_owner,
|
||||
param,
|
||||
DefPathData::LifetimeNs(kw::UnderscoreLifetime),
|
||||
);
|
||||
debug!(?_def_id);
|
||||
|
||||
(hir::ParamName::Fresh, hir::LifetimeParamKind::Elided)
|
||||
}
|
||||
LifetimeRes::Static | LifetimeRes::Error => return None,
|
||||
res => panic!(
|
||||
"Unexpected lifetime resolution {:?} for {:?} at {:?}",
|
||||
|
@ -1814,8 +1824,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
}
|
||||
hir::LifetimeName::Param(param, p_name)
|
||||
}
|
||||
LifetimeRes::Fresh { mut param, binder } => {
|
||||
LifetimeRes::Fresh { param, binder } => {
|
||||
debug_assert_eq!(ident.name, kw::UnderscoreLifetime);
|
||||
let mut param = self.local_def_id(param);
|
||||
if let Some(mut captured_lifetimes) = self.captured_lifetimes.take() {
|
||||
if !captured_lifetimes.binders_to_ignore.contains(&binder) {
|
||||
match captured_lifetimes.captures.entry(param) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue