1
Fork 0

Rollup merge of #138588 - nnethercote:avoid-double-lower_ident, r=compiler-errors

Avoid double lowering of idents

It's easy to double lower idents and spans because they don't change type when lowered.

r? `@cjgillot`
This commit is contained in:
Matthias Krüger 2025-03-17 16:34:52 +01:00 committed by GitHub
commit 1e58d51290
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 35 deletions

View file

@ -1720,7 +1720,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
let bounds = self.lower_param_bounds(bounds, itctx); let bounds = self.lower_param_bounds(bounds, itctx);
let ident = self.lower_ident(ident);
let param_span = ident.span; let param_span = ident.span;
// Reconstruct the span of the entire predicate from the individual generic bounds. // Reconstruct the span of the entire predicate from the individual generic bounds.
@ -1739,6 +1738,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let def_id = self.local_def_id(id).to_def_id(); let def_id = self.local_def_id(id).to_def_id();
let hir_id = self.next_id(); let hir_id = self.next_id();
let res = Res::Def(DefKind::TyParam, def_id); let res = Res::Def(DefKind::TyParam, def_id);
let ident = self.lower_ident(ident);
let ty_path = self.arena.alloc(hir::Path { let ty_path = self.arena.alloc(hir::Path {
span: param_span, span: param_span,
res, res,
@ -1757,7 +1757,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
}) })
} }
GenericParamKind::Lifetime => { GenericParamKind::Lifetime => {
let ident = self.lower_ident(ident);
let lt_id = self.next_node_id(); let lt_id = self.next_node_id();
let lifetime = self.new_named_lifetime(id, lt_id, ident); let lifetime = self.new_named_lifetime(id, lt_id, ident);
hir::WherePredicateKind::RegionPredicate(hir::WhereRegionPredicate { hir::WherePredicateKind::RegionPredicate(hir::WhereRegionPredicate {

View file

@ -1769,38 +1769,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
} }
fn lower_lifetime(&mut self, l: &Lifetime) -> &'hir hir::Lifetime { fn lower_lifetime(&mut self, l: &Lifetime) -> &'hir hir::Lifetime {
let ident = self.lower_ident(l.ident); self.new_named_lifetime(l.id, l.id, l.ident)
self.new_named_lifetime(l.id, l.id, ident)
}
#[instrument(level = "debug", skip(self))]
fn new_named_lifetime_with_res(
&mut self,
id: NodeId,
ident: Ident,
res: LifetimeRes,
) -> &'hir hir::Lifetime {
let res = match res {
LifetimeRes::Param { param, .. } => hir::LifetimeName::Param(param),
LifetimeRes::Fresh { param, .. } => {
let param = self.local_def_id(param);
hir::LifetimeName::Param(param)
}
LifetimeRes::Infer => hir::LifetimeName::Infer,
LifetimeRes::Static { .. } => hir::LifetimeName::Static,
LifetimeRes::Error => hir::LifetimeName::Error,
res => panic!(
"Unexpected lifetime resolution {:?} for {:?} at {:?}",
res, ident, ident.span
),
};
debug!(?res);
self.arena.alloc(hir::Lifetime {
hir_id: self.lower_node_id(id),
ident: self.lower_ident(ident),
res,
})
} }
#[instrument(level = "debug", skip(self))] #[instrument(level = "debug", skip(self))]
@ -1811,7 +1780,26 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ident: Ident, ident: Ident,
) -> &'hir hir::Lifetime { ) -> &'hir hir::Lifetime {
let res = self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error); let res = self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error);
self.new_named_lifetime_with_res(new_id, ident, res) let res = match res {
LifetimeRes::Param { param, .. } => hir::LifetimeName::Param(param),
LifetimeRes::Fresh { param, .. } => {
let param = self.local_def_id(param);
hir::LifetimeName::Param(param)
}
LifetimeRes::Infer => hir::LifetimeName::Infer,
LifetimeRes::Static { .. } => hir::LifetimeName::Static,
LifetimeRes::Error => hir::LifetimeName::Error,
LifetimeRes::ElidedAnchor { .. } => {
panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
}
};
debug!(?res);
self.arena.alloc(hir::Lifetime {
hir_id: self.lower_node_id(new_id),
ident: self.lower_ident(ident),
res,
})
} }
fn lower_generic_params_mut( fn lower_generic_params_mut(