Skip to content

Commit 6713fe9

Browse files
committed
Remove mutability in ResolverAstLowering.
1 parent f8abed9 commit 6713fe9

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ struct LoweringContext<'a, 'hir: 'a> {
162162
}
163163

164164
pub trait ResolverAstLowering {
165-
fn def_key(&mut self, id: DefId) -> DefKey;
165+
fn def_key(&self, id: DefId) -> DefKey;
166166

167167
fn def_span(&self, id: LocalDefId) -> Span;
168168

@@ -174,17 +174,17 @@ pub trait ResolverAstLowering {
174174
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes>;
175175

176176
/// Obtains per-namespace resolutions for `use` statement with the given `NodeId`.
177-
fn get_import_res(&mut self, id: NodeId) -> PerNS<Option<Res<NodeId>>>;
177+
fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res<NodeId>>>;
178178

179179
/// Obtains resolution for a label with the given `NodeId`.
180-
fn get_label_res(&mut self, id: NodeId) -> Option<NodeId>;
181-
182-
/// We must keep the set of definitions up to date as we add nodes that weren't in the AST.
183-
/// This should only return `None` during testing.
184-
fn definitions(&mut self) -> &mut Definitions;
180+
fn get_label_res(&self, id: NodeId) -> Option<NodeId>;
185181

186182
fn create_stable_hashing_context(&self) -> StableHashingContext<'_>;
187183

184+
fn definitions(&self) -> &Definitions;
185+
186+
fn init_def_id_to_hir_id_mapping(&mut self, mapping: IndexVec<LocalDefId, Option<hir::HirId>>);
187+
188188
fn lint_buffer(&mut self) -> &mut LintBuffer;
189189

190190
fn next_node_id(&mut self) -> NodeId;
@@ -412,7 +412,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
412412
}
413413
}
414414

415-
self.resolver.definitions().init_def_id_to_hir_id_mapping(def_id_to_hir_id);
415+
self.resolver.init_def_id_to_hir_id_mapping(def_id_to_hir_id);
416416

417417
let krate = hir::Crate { owners: self.owners, hir_hash };
418418
self.arena.alloc(krate)

compiler/rustc_resolve/src/lib.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,9 +1134,9 @@ impl<'a, 'b> DefIdTree for &'a Resolver<'b> {
11341134
/// This interface is used through the AST→HIR step, to embed full paths into the HIR. After that
11351135
/// the resolver is no longer needed as all the relevant information is inline.
11361136
impl ResolverAstLowering for Resolver<'_> {
1137-
fn def_key(&mut self, id: DefId) -> DefKey {
1137+
fn def_key(&self, id: DefId) -> DefKey {
11381138
if let Some(id) = id.as_local() {
1139-
self.definitions().def_key(id)
1139+
self.definitions.def_key(id)
11401140
} else {
11411141
self.cstore().def_key(id)
11421142
}
@@ -1163,22 +1163,29 @@ impl ResolverAstLowering for Resolver<'_> {
11631163
self.partial_res_map.get(&id).cloned()
11641164
}
11651165

1166-
fn get_import_res(&mut self, id: NodeId) -> PerNS<Option<Res>> {
1166+
fn get_import_res(&self, id: NodeId) -> PerNS<Option<Res>> {
11671167
self.import_res_map.get(&id).cloned().unwrap_or_default()
11681168
}
11691169

1170-
fn get_label_res(&mut self, id: NodeId) -> Option<NodeId> {
1170+
fn get_label_res(&self, id: NodeId) -> Option<NodeId> {
11711171
self.label_res_map.get(&id).cloned()
11721172
}
11731173

1174-
fn definitions(&mut self) -> &mut Definitions {
1175-
&mut self.definitions
1176-
}
1177-
11781174
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
11791175
StableHashingContext::new(self.session, &self.definitions, self.crate_loader.cstore())
11801176
}
11811177

1178+
fn definitions(&self) -> &Definitions {
1179+
&self.definitions
1180+
}
1181+
1182+
fn init_def_id_to_hir_id_mapping(
1183+
&mut self,
1184+
mapping: IndexVec<LocalDefId, Option<rustc_hir::HirId>>,
1185+
) {
1186+
self.definitions.init_def_id_to_hir_id_mapping(mapping)
1187+
}
1188+
11821189
fn lint_buffer(&mut self) -> &mut LintBuffer {
11831190
&mut self.lint_buffer
11841191
}

0 commit comments

Comments
 (0)