Skip to content

Commit 6849f81

Browse files
committed
resolve: Change &mut Resolver to &Resolver when possible
1 parent 8b8889d commit 6849f81

File tree

10 files changed

+35
-44
lines changed

10 files changed

+35
-44
lines changed

compiler/rustc_expand/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ pub trait ResolverExpand {
10621062
fn next_node_id(&mut self) -> NodeId;
10631063
fn invocation_parent(&self, id: LocalExpnId) -> LocalDefId;
10641064

1065-
fn resolve_dollar_crates(&mut self);
1065+
fn resolve_dollar_crates(&self);
10661066
fn visit_ast_fragment_with_placeholders(
10671067
&mut self,
10681068
expn_id: LocalExpnId,

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
8585
/// Reachable macros with block module parents exist due to `#[macro_export] macro_rules!`,
8686
/// but they cannot use def-site hygiene, so the assumption holds
8787
/// (<https://github.com/rust-lang/rust/pull/77984#issuecomment-712445508>).
88-
pub(crate) fn get_nearest_non_block_module(&mut self, mut def_id: DefId) -> Module<'ra> {
88+
pub(crate) fn get_nearest_non_block_module(&self, mut def_id: DefId) -> Module<'ra> {
8989
loop {
9090
match self.get_module(def_id) {
9191
Some(module) => return module,
@@ -94,14 +94,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
9494
}
9595
}
9696

97-
pub(crate) fn expect_module(&mut self, def_id: DefId) -> Module<'ra> {
97+
pub(crate) fn expect_module(&self, def_id: DefId) -> Module<'ra> {
9898
self.get_module(def_id).expect("argument `DefId` is not a module")
9999
}
100100

101101
/// If `def_id` refers to a module (in resolver's sense, i.e. a module item, crate root, enum,
102102
/// or trait), then this function returns that module's resolver representation, otherwise it
103103
/// returns `None`.
104-
pub(crate) fn get_module(&mut self, def_id: DefId) -> Option<Module<'ra>> {
104+
pub(crate) fn get_module(&self, def_id: DefId) -> Option<Module<'ra>> {
105105
match def_id.as_local() {
106106
Some(local_def_id) => self.local_module_map.get(&local_def_id).copied(),
107107
None => {
@@ -134,7 +134,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
134134
}
135135
}
136136

137-
pub(crate) fn expn_def_scope(&mut self, expn_id: ExpnId) -> Module<'ra> {
137+
pub(crate) fn expn_def_scope(&self, expn_id: ExpnId) -> Module<'ra> {
138138
match expn_id.expn_data().macro_def_id {
139139
Some(def_id) => self.macro_def_scope(def_id),
140140
None => expn_id
@@ -144,7 +144,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
144144
}
145145
}
146146

147-
pub(crate) fn macro_def_scope(&mut self, def_id: DefId) -> Module<'ra> {
147+
pub(crate) fn macro_def_scope(&self, def_id: DefId) -> Module<'ra> {
148148
if let Some(id) = def_id.as_local() {
149149
self.local_macro_def_scopes[&id]
150150
} else {
@@ -406,7 +406,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
406406
self.r.field_visibility_spans.insert(def_id, field_vis);
407407
}
408408

409-
fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
409+
fn block_needs_anonymous_module(&self, block: &Block) -> bool {
410410
// If any statements are items, we need to create an anonymous module
411411
block
412412
.stmts
@@ -1121,7 +1121,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
11211121
}
11221122

11231123
/// Returns `true` if this attribute list contains `macro_use`.
1124-
fn contains_macro_use(&mut self, attrs: &[ast::Attribute]) -> bool {
1124+
fn contains_macro_use(&self, attrs: &[ast::Attribute]) -> bool {
11251125
for attr in attrs {
11261126
if attr.has_name(sym::macro_escape) {
11271127
let inner_attribute = matches!(attr.style, ast::AttrStyle::Inner);

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
21502150
}
21512151

21522152
pub(crate) fn find_similarly_named_module_or_crate(
2153-
&mut self,
2153+
&self,
21542154
ident: Symbol,
21552155
current_module: Module<'ra>,
21562156
) -> Option<Symbol> {
@@ -2444,7 +2444,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24442444
}
24452445

24462446
fn undeclared_module_suggest_declare(
2447-
&mut self,
2447+
&self,
24482448
ident: Ident,
24492449
path: std::path::PathBuf,
24502450
) -> Option<(Vec<(Span, String)>, String, Applicability)> {
@@ -2459,7 +2459,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24592459
))
24602460
}
24612461

2462-
fn undeclared_module_exists(&mut self, ident: Ident) -> Option<std::path::PathBuf> {
2462+
fn undeclared_module_exists(&self, ident: Ident) -> Option<std::path::PathBuf> {
24632463
let map = self.tcx.sess.source_map();
24642464

24652465
let src = map.span_to_filename(ident.span).into_local_path()?;
@@ -2780,12 +2780,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
27802780
}
27812781

27822782
/// Finds a cfg-ed out item inside `module` with the matching name.
2783-
pub(crate) fn find_cfg_stripped(
2784-
&mut self,
2785-
err: &mut Diag<'_>,
2786-
segment: &Symbol,
2787-
module: DefId,
2788-
) {
2783+
pub(crate) fn find_cfg_stripped(&self, err: &mut Diag<'_>, segment: &Symbol, module: DefId) {
27892784
let local_items;
27902785
let symbols = if module.is_local() {
27912786
local_items = self
@@ -2811,7 +2806,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
28112806
}
28122807

28132808
fn comes_from_same_module_for_glob(
2814-
r: &mut Resolver<'_, '_>,
2809+
r: &Resolver<'_, '_>,
28152810
parent_module: DefId,
28162811
module: DefId,
28172812
visited: &mut FxHashMap<DefId, bool>,

compiler/rustc_resolve/src/effective_visibilities.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ pub(crate) struct EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
3838
}
3939

4040
impl Resolver<'_, '_> {
41-
fn nearest_normal_mod(&mut self, def_id: LocalDefId) -> LocalDefId {
41+
fn nearest_normal_mod(&self, def_id: LocalDefId) -> LocalDefId {
4242
self.get_nearest_non_block_module(def_id.to_def_id()).nearest_parent_mod().expect_local()
4343
}
4444

45-
fn private_vis_import(&mut self, binding: NameBinding<'_>) -> Visibility {
45+
fn private_vis_import(&self, binding: NameBinding<'_>) -> Visibility {
4646
let NameBindingKind::Import { import, .. } = binding.kind else { unreachable!() };
4747
Visibility::Restricted(
4848
import
@@ -52,7 +52,7 @@ impl Resolver<'_, '_> {
5252
)
5353
}
5454

55-
fn private_vis_def(&mut self, def_id: LocalDefId) -> Visibility {
55+
fn private_vis_def(&self, def_id: LocalDefId) -> Visibility {
5656
// For mod items `nearest_normal_mod` returns its argument, but we actually need its parent.
5757
let normal_mod_id = self.nearest_normal_mod(def_id);
5858
if normal_mod_id == def_id {

compiler/rustc_resolve/src/ident.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
219219
}
220220

221221
fn hygienic_lexical_parent(
222-
&mut self,
222+
&self,
223223
module: Module<'ra>,
224224
ctxt: &mut SyntaxContext,
225225
derive_fallback_lint_id: Option<NodeId>,
@@ -885,7 +885,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
885885
);
886886
}
887887

888-
let check_usable = |this: &mut Self, binding: NameBinding<'ra>| {
888+
let check_usable = |this: &Self, binding: NameBinding<'ra>| {
889889
let usable = this.is_accessible_from(binding.vis, parent_scope.module);
890890
if usable { Ok(binding) } else { Err((Determined, Weak::No)) }
891891
};

compiler/rustc_resolve/src/imports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
456456
f: F,
457457
) -> T
458458
where
459-
F: FnOnce(&mut Resolver<'ra, 'tcx>, &mut NameResolution<'ra>) -> T,
459+
F: FnOnce(&Resolver<'ra, 'tcx>, &mut NameResolution<'ra>) -> T,
460460
{
461461
// Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
462462
// during which the resolution might end up getting re-defined via a glob cycle.

compiler/rustc_resolve/src/late.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2491,7 +2491,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
24912491

24922492
/// Searches the current set of local scopes for labels. Returns the `NodeId` of the resolved
24932493
/// label and reports an error if the label is not found or is unreachable.
2494-
fn resolve_label(&mut self, mut label: Ident) -> Result<(NodeId, Span), ResolutionError<'ra>> {
2494+
fn resolve_label(&self, mut label: Ident) -> Result<(NodeId, Span), ResolutionError<'ra>> {
24952495
let mut suggestion = None;
24962496

24972497
for i in (0..self.label_ribs.len()).rev() {

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
939939
}
940940

941941
fn suggest_trait_and_bounds(
942-
&mut self,
942+
&self,
943943
err: &mut Diag<'_>,
944944
source: PathSource<'_, '_, '_>,
945945
res: Option<Res>,
@@ -1140,7 +1140,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11401140

11411141
/// Emit special messages for unresolved `Self` and `self`.
11421142
fn suggest_self_ty(
1143-
&mut self,
1143+
&self,
11441144
err: &mut Diag<'_>,
11451145
source: PathSource<'_, '_, '_>,
11461146
path: &[Segment],
@@ -1256,7 +1256,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
12561256
}
12571257

12581258
fn detect_missing_binding_available_from_pattern(
1259-
&mut self,
1259+
&self,
12601260
err: &mut Diag<'_>,
12611261
path: &[Segment],
12621262
following_seg: Option<&Segment>,
@@ -1302,11 +1302,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
13021302
}
13031303
}
13041304

1305-
fn suggest_at_operator_in_slice_pat_with_range(
1306-
&mut self,
1307-
err: &mut Diag<'_>,
1308-
path: &[Segment],
1309-
) {
1305+
fn suggest_at_operator_in_slice_pat_with_range(&self, err: &mut Diag<'_>, path: &[Segment]) {
13101306
let Some(pat) = self.diag_metadata.current_pat else { return };
13111307
let (bound, side, range) = match &pat.kind {
13121308
ast::PatKind::Range(Some(bound), None, range) => (bound, Side::Start, range),
@@ -1367,7 +1363,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
13671363
}
13681364

13691365
fn explain_functions_in_pattern(
1370-
&mut self,
1366+
&self,
13711367
err: &mut Diag<'_>,
13721368
res: Option<Res>,
13731369
source: PathSource<'_, '_, '_>,
@@ -1379,7 +1375,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
13791375
}
13801376

13811377
fn suggest_changing_type_to_const_param(
1382-
&mut self,
1378+
&self,
13831379
err: &mut Diag<'_>,
13841380
res: Option<Res>,
13851381
source: PathSource<'_, '_, '_>,
@@ -1429,7 +1425,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
14291425
}
14301426

14311427
fn suggest_pattern_match_with_let(
1432-
&mut self,
1428+
&self,
14331429
err: &mut Diag<'_>,
14341430
source: PathSource<'_, '_, '_>,
14351431
span: Span,
@@ -1485,7 +1481,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
14851481
}
14861482

14871483
/// Given `where <T as Bar>::Baz: String`, suggest `where T: Bar<Baz = String>`.
1488-
fn restrict_assoc_type_in_where_clause(&mut self, span: Span, err: &mut Diag<'_>) -> bool {
1484+
fn restrict_assoc_type_in_where_clause(&self, span: Span, err: &mut Diag<'_>) -> bool {
14891485
// Detect that we are actually in a `where` predicate.
14901486
let (bounded_ty, bounds, where_span) = if let Some(ast::WherePredicate {
14911487
kind:
@@ -1633,7 +1629,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
16331629
let ns = source.namespace();
16341630
let is_expected = &|res| source.is_expected(res);
16351631

1636-
let path_sep = |this: &mut Self, err: &mut Diag<'_>, expr: &Expr, kind: DefKind| {
1632+
let path_sep = |this: &Self, err: &mut Diag<'_>, expr: &Expr, kind: DefKind| {
16371633
const MESSAGE: &str = "use the path separator to refer to an item";
16381634

16391635
let (lhs_span, rhs_span) = match &expr.kind {
@@ -2587,7 +2583,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
25872583

25882584
// try to give a suggestion for this pattern: `name = blah`, which is common in other languages
25892585
// suggest `let name = blah` to introduce a new binding
2590-
fn let_binding_suggestion(&mut self, err: &mut Diag<'_>, ident_span: Span) -> bool {
2586+
fn let_binding_suggestion(&self, err: &mut Diag<'_>, ident_span: Span) -> bool {
25912587
if ident_span.from_expansion() {
25922588
return false;
25932589
}

compiler/rustc_resolve/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,7 +1624,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16241624
}
16251625

16261626
fn new_extern_module(
1627-
&mut self,
1627+
&self,
16281628
parent: Option<Module<'ra>>,
16291629
kind: ModuleKind,
16301630
expn_id: ExpnId,
@@ -2021,7 +2021,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20212021
}
20222022
}
20232023

2024-
fn resolve_crate_root(&mut self, ident: Ident) -> Module<'ra> {
2024+
fn resolve_crate_root(&self, ident: Ident) -> Module<'ra> {
20252025
debug!("resolve_crate_root({:?})", ident);
20262026
let mut ctxt = ident.span.ctxt();
20272027
let mark = if ident.name == kw::DollarCrate {
@@ -2094,7 +2094,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20942094
module
20952095
}
20962096

2097-
fn resolve_self(&mut self, ctxt: &mut SyntaxContext, module: Module<'ra>) -> Module<'ra> {
2097+
fn resolve_self(&self, ctxt: &mut SyntaxContext, module: Module<'ra>) -> Module<'ra> {
20982098
let mut module = self.expect_module(module.nearest_parent_mod());
20992099
while module.span.ctxt().normalize_to_macros_2_0() != *ctxt {
21002100
let parent = module.parent.unwrap_or_else(|| self.expn_def_scope(ctxt.remove_mark()));

compiler/rustc_resolve/src/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
170170
self.invocation_parents[&id].parent_def
171171
}
172172

173-
fn resolve_dollar_crates(&mut self) {
173+
fn resolve_dollar_crates(&self) {
174174
hygiene::update_dollar_crate_names(|ctxt| {
175175
let ident = Ident::new(kw::DollarCrate, DUMMY_SP.with_ctxt(ctxt));
176176
match self.resolve_crate_root(ident).kind {
@@ -835,7 +835,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
835835
}
836836

837837
pub(crate) fn finalize_macro_resolutions(&mut self, krate: &Crate) {
838-
let check_consistency = |this: &mut Self,
838+
let check_consistency = |this: &Self,
839839
path: &[Segment],
840840
span,
841841
kind: MacroKind,

0 commit comments

Comments
 (0)