Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1e58d51

Browse files
authoredMar 17, 2025
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`
2 parents b15e663 + adf2bb7 commit 1e58d51

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed
 

‎compiler/rustc_ast_lowering/src/item.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
17201720

17211721
let bounds = self.lower_param_bounds(bounds, itctx);
17221722

1723-
let ident = self.lower_ident(ident);
17241723
let param_span = ident.span;
17251724

17261725
// Reconstruct the span of the entire predicate from the individual generic bounds.
@@ -1739,6 +1738,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17391738
let def_id = self.local_def_id(id).to_def_id();
17401739
let hir_id = self.next_id();
17411740
let res = Res::Def(DefKind::TyParam, def_id);
1741+
let ident = self.lower_ident(ident);
17421742
let ty_path = self.arena.alloc(hir::Path {
17431743
span: param_span,
17441744
res,
@@ -1757,7 +1757,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
17571757
})
17581758
}
17591759
GenericParamKind::Lifetime => {
1760-
let ident = self.lower_ident(ident);
17611760
let lt_id = self.next_node_id();
17621761
let lifetime = self.new_named_lifetime(id, lt_id, ident);
17631762
hir::WherePredicateKind::RegionPredicate(hir::WhereRegionPredicate {

‎compiler/rustc_ast_lowering/src/lib.rs

+8-20
Original file line numberDiff line numberDiff line change
@@ -1769,17 +1769,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17691769
}
17701770

17711771
fn lower_lifetime(&mut self, l: &Lifetime) -> &'hir hir::Lifetime {
1772-
let ident = self.lower_ident(l.ident);
1773-
self.new_named_lifetime(l.id, l.id, ident)
1772+
self.new_named_lifetime(l.id, l.id, l.ident)
17741773
}
17751774

17761775
#[instrument(level = "debug", skip(self))]
1777-
fn new_named_lifetime_with_res(
1776+
fn new_named_lifetime(
17781777
&mut self,
17791778
id: NodeId,
1779+
new_id: NodeId,
17801780
ident: Ident,
1781-
res: LifetimeRes,
17821781
) -> &'hir hir::Lifetime {
1782+
let res = self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error);
17831783
let res = match res {
17841784
LifetimeRes::Param { param, .. } => hir::LifetimeName::Param(param),
17851785
LifetimeRes::Fresh { param, .. } => {
@@ -1789,31 +1789,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17891789
LifetimeRes::Infer => hir::LifetimeName::Infer,
17901790
LifetimeRes::Static { .. } => hir::LifetimeName::Static,
17911791
LifetimeRes::Error => hir::LifetimeName::Error,
1792-
res => panic!(
1793-
"Unexpected lifetime resolution {:?} for {:?} at {:?}",
1794-
res, ident, ident.span
1795-
),
1792+
LifetimeRes::ElidedAnchor { .. } => {
1793+
panic!("Unexpected `ElidedAnchar` {:?} at {:?}", ident, ident.span);
1794+
}
17961795
};
17971796

17981797
debug!(?res);
17991798
self.arena.alloc(hir::Lifetime {
1800-
hir_id: self.lower_node_id(id),
1799+
hir_id: self.lower_node_id(new_id),
18011800
ident: self.lower_ident(ident),
18021801
res,
18031802
})
18041803
}
18051804

1806-
#[instrument(level = "debug", skip(self))]
1807-
fn new_named_lifetime(
1808-
&mut self,
1809-
id: NodeId,
1810-
new_id: NodeId,
1811-
ident: Ident,
1812-
) -> &'hir hir::Lifetime {
1813-
let res = self.resolver.get_lifetime_res(id).unwrap_or(LifetimeRes::Error);
1814-
self.new_named_lifetime_with_res(new_id, ident, res)
1815-
}
1816-
18171805
fn lower_generic_params_mut(
18181806
&mut self,
18191807
params: &[GenericParam],

0 commit comments

Comments
 (0)
Failed to load comments.