Skip to content

Commit dc1bd28

Browse files
petrochenkovLorrensP-2158466
authored andcommitted
resolve: Change &mut Resolver to &Resolver when possible
1 parent 3438b39 commit dc1bd28

File tree

10 files changed

+34
-43
lines changed

10 files changed

+34
-43
lines changed

compiler/rustc_expand/src/base.rs

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

1045-
fn resolve_dollar_crates(&mut self);
1045+
fn resolve_dollar_crates(&self);
10461046
fn visit_ast_fragment_with_placeholders(
10471047
&mut self,
10481048
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
@@ -1130,7 +1130,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
11301130
}
11311131

11321132
/// Returns `true` if this attribute list contains `macro_use`.
1133-
fn contains_macro_use(&mut self, attrs: &[ast::Attribute]) -> bool {
1133+
fn contains_macro_use(&self, attrs: &[ast::Attribute]) -> bool {
11341134
for attr in attrs {
11351135
if attr.has_name(sym::macro_escape) {
11361136
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
@@ -2151,7 +2151,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
21512151
}
21522152

21532153
pub(crate) fn find_similarly_named_module_or_crate(
2154-
&mut self,
2154+
&self,
21552155
ident: Symbol,
21562156
current_module: Module<'ra>,
21572157
) -> Option<Symbol> {
@@ -2445,7 +2445,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24452445
}
24462446

24472447
fn undeclared_module_suggest_declare(
2448-
&mut self,
2448+
&self,
24492449
ident: Ident,
24502450
path: std::path::PathBuf,
24512451
) -> Option<(Vec<(Span, String)>, String, Applicability)> {
@@ -2460,7 +2460,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24602460
))
24612461
}
24622462

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

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

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

28142809
fn comes_from_same_module_for_glob(
2815-
r: &mut Resolver<'_, '_>,
2810+
r: &Resolver<'_, '_>,
28162811
parent_module: DefId,
28172812
module: DefId,
28182813
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
@@ -443,7 +443,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
443443
f: F,
444444
) -> T
445445
where
446-
F: FnOnce(&mut Resolver<'ra, 'tcx>, &mut NameResolution<'ra>) -> T,
446+
F: FnOnce(&Resolver<'ra, 'tcx>, &mut NameResolution<'ra>) -> T,
447447
{
448448
// Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
449449
// 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
@@ -937,7 +937,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
937937
}
938938

939939
fn suggest_trait_and_bounds(
940-
&mut self,
940+
&self,
941941
err: &mut Diag<'_>,
942942
source: PathSource<'_, '_, '_>,
943943
res: Option<Res>,
@@ -1138,7 +1138,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11381138

11391139
/// Emit special messages for unresolved `Self` and `self`.
11401140
fn suggest_self_ty(
1141-
&mut self,
1141+
&self,
11421142
err: &mut Diag<'_>,
11431143
source: PathSource<'_, '_, '_>,
11441144
path: &[Segment],
@@ -1254,7 +1254,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
12541254
}
12551255

12561256
fn detect_missing_binding_available_from_pattern(
1257-
&mut self,
1257+
&self,
12581258
err: &mut Diag<'_>,
12591259
path: &[Segment],
12601260
following_seg: Option<&Segment>,
@@ -1300,11 +1300,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
13001300
}
13011301
}
13021302

1303-
fn suggest_at_operator_in_slice_pat_with_range(
1304-
&mut self,
1305-
err: &mut Diag<'_>,
1306-
path: &[Segment],
1307-
) {
1303+
fn suggest_at_operator_in_slice_pat_with_range(&self, err: &mut Diag<'_>, path: &[Segment]) {
13081304
let Some(pat) = self.diag_metadata.current_pat else { return };
13091305
let (bound, side, range) = match &pat.kind {
13101306
ast::PatKind::Range(Some(bound), None, range) => (bound, Side::Start, range),
@@ -1365,7 +1361,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
13651361
}
13661362

13671363
fn explain_functions_in_pattern(
1368-
&mut self,
1364+
&self,
13691365
err: &mut Diag<'_>,
13701366
res: Option<Res>,
13711367
source: PathSource<'_, '_, '_>,
@@ -1377,7 +1373,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
13771373
}
13781374

13791375
fn suggest_changing_type_to_const_param(
1380-
&mut self,
1376+
&self,
13811377
err: &mut Diag<'_>,
13821378
res: Option<Res>,
13831379
source: PathSource<'_, '_, '_>,
@@ -1427,7 +1423,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
14271423
}
14281424

14291425
fn suggest_pattern_match_with_let(
1430-
&mut self,
1426+
&self,
14311427
err: &mut Diag<'_>,
14321428
source: PathSource<'_, '_, '_>,
14331429
span: Span,
@@ -1482,7 +1478,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
14821478
}
14831479

14841480
/// Given `where <T as Bar>::Baz: String`, suggest `where T: Bar<Baz = String>`.
1485-
fn restrict_assoc_type_in_where_clause(&mut self, span: Span, err: &mut Diag<'_>) -> bool {
1481+
fn restrict_assoc_type_in_where_clause(&self, span: Span, err: &mut Diag<'_>) -> bool {
14861482
// Detect that we are actually in a `where` predicate.
14871483
let (bounded_ty, bounds, where_span) = if let Some(ast::WherePredicate {
14881484
kind:
@@ -1630,7 +1626,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
16301626
let ns = source.namespace();
16311627
let is_expected = &|res| source.is_expected(res);
16321628

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

16361632
let (lhs_span, rhs_span) = match &expr.kind {
@@ -2582,7 +2578,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
25822578

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

compiler/rustc_resolve/src/lib.rs

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

16161616
fn new_extern_module(
1617-
&mut self,
1617+
&self,
16181618
parent: Option<Module<'ra>>,
16191619
kind: ModuleKind,
16201620
expn_id: ExpnId,
@@ -2011,7 +2011,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20112011
}
20122012
}
20132013

2014-
fn resolve_crate_root(&mut self, ident: Ident) -> Module<'ra> {
2014+
fn resolve_crate_root(&self, ident: Ident) -> Module<'ra> {
20152015
debug!("resolve_crate_root({:?})", ident);
20162016
let mut ctxt = ident.span.ctxt();
20172017
let mark = if ident.name == kw::DollarCrate {
@@ -2084,7 +2084,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20842084
module
20852085
}
20862086

2087-
fn resolve_self(&mut self, ctxt: &mut SyntaxContext, module: Module<'ra>) -> Module<'ra> {
2087+
fn resolve_self(&self, ctxt: &mut SyntaxContext, module: Module<'ra>) -> Module<'ra> {
20882088
let mut module = self.expect_module(module.nearest_parent_mod());
20892089
while module.span.ctxt().normalize_to_macros_2_0() != *ctxt {
20902090
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
@@ -171,7 +171,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
171171
self.invocation_parents[&id].parent_def
172172
}
173173

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

828828
pub(crate) fn finalize_macro_resolutions(&mut self, krate: &Crate) {
829-
let check_consistency = |this: &mut Self,
829+
let check_consistency = |this: &Self,
830830
path: &[Segment],
831831
span,
832832
kind: MacroKind,

0 commit comments

Comments
 (0)