Skip to content

Commit c06b2b9

Browse files
committed
Auto merge of #113847 - SparrowLii:path_clone, r=cjgillot
avoid clone path prefix when lowering to hir Found this while trying to parallelize `lower_to_hir`. When lowering to hir, `Nested` paths in `ast` will be split and the prefix segments will be cloned. This could be omited, since the only consequence is that the prefix segments in `Path`s in hir will have the same `HirId`s, and it seems harmless. This simplifies the process of lowering to hir and avoids re-modification of `ResolverAstLowering`. r? `@Aaron1011` cc #99292
2 parents 6b29036 + 0377945 commit c06b2b9

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

compiler/rustc_ast_lowering/src/item.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -551,17 +551,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
551551
for &(ref use_tree, id) in trees {
552552
let new_hir_id = self.local_def_id(id);
553553

554-
let mut prefix = prefix.clone();
555-
556-
// Give the segments new node-ids since they are being cloned.
557-
for seg in &mut prefix.segments {
558-
// Give the cloned segment the same resolution information
559-
// as the old one (this is needed for stability checking).
560-
let new_id = self.next_node_id();
561-
self.resolver.clone_res(seg.id, new_id);
562-
seg.id = new_id;
563-
}
564-
565554
// Each `use` import is an item and thus are owners of the
566555
// names in the path. Up to this point the nested import is
567556
// the current owner, since we want each desugared import to
@@ -570,6 +559,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
570559
self.with_hir_id_owner(id, |this| {
571560
let mut ident = *ident;
572561

562+
// `prefix` is lowered multiple times, but in different HIR owners.
563+
// So each segment gets renewed `HirId` with the same
564+
// `ItemLocalId` and the new owner. (See `lower_node_id`)
573565
let kind =
574566
this.lower_use_tree(use_tree, &prefix, id, vis_span, &mut ident, attrs);
575567
if let Some(attrs) = attrs {

compiler/rustc_ast_lowering/src/lib.rs

-10
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ trait ResolverAstLoweringExt {
148148
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>>;
149149
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes>;
150150
fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res<NodeId>>>;
151-
// Clones the resolution (if any) on 'source' and applies it
152-
// to 'target'. Used when desugaring a `UseTreeKind::Nested` to
153-
// multiple `UseTreeKind::Simple`s
154-
fn clone_res(&mut self, source: NodeId, target: NodeId);
155151
fn get_label_res(&self, id: NodeId) -> Option<NodeId>;
156152
fn get_lifetime_res(&self, id: NodeId) -> Option<LifetimeRes>;
157153
fn take_extra_lifetime_params(&mut self, id: NodeId) -> Vec<(Ident, NodeId, LifetimeRes)>;
@@ -184,12 +180,6 @@ impl ResolverAstLoweringExt for ResolverAstLowering {
184180
None
185181
}
186182

187-
fn clone_res(&mut self, source: NodeId, target: NodeId) {
188-
if let Some(res) = self.partial_res_map.get(&source) {
189-
self.partial_res_map.insert(target, *res);
190-
}
191-
}
192-
193183
/// Obtains resolution for a `NodeId` with a single resolution.
194184
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes> {
195185
self.partial_res_map.get(&id).copied()

0 commit comments

Comments
 (0)