Skip to content

Commit bec2235

Browse files
committed
resolve: Change &mut Resolver to &Resolver when possible
1 parent 013591e commit bec2235

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
@@ -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 {
@@ -404,7 +404,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
404404
self.r.field_visibility_spans.insert(def_id, field_vis);
405405
}
406406

407-
fn block_needs_anonymous_module(&mut self, block: &Block) -> bool {
407+
fn block_needs_anonymous_module(&self, block: &Block) -> bool {
408408
// If any statements are items, we need to create an anonymous module
409409
block
410410
.stmts
@@ -1128,7 +1128,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
11281128
}
11291129

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

21482148
pub(crate) fn find_similarly_named_module_or_crate(
2149-
&mut self,
2149+
&self,
21502150
ident: Symbol,
21512151
current_module: Module<'ra>,
21522152
) -> Option<Symbol> {
@@ -2440,7 +2440,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24402440
}
24412441

24422442
fn undeclared_module_suggest_declare(
2443-
&mut self,
2443+
&self,
24442444
ident: Ident,
24452445
path: std::path::PathBuf,
24462446
) -> Option<(Vec<(Span, String)>, String, Applicability)> {
@@ -2455,7 +2455,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
24552455
))
24562456
}
24572457

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

24612461
let src = map.span_to_filename(ident.span).into_local_path()?;
@@ -2776,12 +2776,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
27762776
}
27772777

27782778
/// Finds a cfg-ed out item inside `module` with the matching name.
2779-
pub(crate) fn find_cfg_stripped(
2780-
&mut self,
2781-
err: &mut Diag<'_>,
2782-
segment: &Symbol,
2783-
module: DefId,
2784-
) {
2779+
pub(crate) fn find_cfg_stripped(&self, err: &mut Diag<'_>, segment: &Symbol, module: DefId) {
27852780
let local_items;
27862781
let symbols = if module.is_local() {
27872782
local_items = self
@@ -2807,7 +2802,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
28072802
}
28082803

28092804
fn comes_from_same_module_for_glob(
2810-
r: &mut Resolver<'_, '_>,
2805+
r: &Resolver<'_, '_>,
28112806
parent_module: DefId,
28122807
module: DefId,
28132808
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
@@ -923,7 +923,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
923923
return Ok(binding);
924924
}
925925

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

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
@@ -938,7 +938,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
938938
}
939939

940940
fn suggest_trait_and_bounds(
941-
&mut self,
941+
&self,
942942
err: &mut Diag<'_>,
943943
source: PathSource<'_, '_, '_>,
944944
res: Option<Res>,
@@ -1139,7 +1139,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11391139

11401140
/// Emit special messages for unresolved `Self` and `self`.
11411141
fn suggest_self_ty(
1142-
&mut self,
1142+
&self,
11431143
err: &mut Diag<'_>,
11441144
source: PathSource<'_, '_, '_>,
11451145
path: &[Segment],
@@ -1247,7 +1247,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
12471247
}
12481248

12491249
fn detect_missing_binding_available_from_pattern(
1250-
&mut self,
1250+
&self,
12511251
err: &mut Diag<'_>,
12521252
path: &[Segment],
12531253
following_seg: Option<&Segment>,
@@ -1293,11 +1293,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
12931293
}
12941294
}
12951295

1296-
fn suggest_at_operator_in_slice_pat_with_range(
1297-
&mut self,
1298-
err: &mut Diag<'_>,
1299-
path: &[Segment],
1300-
) {
1296+
fn suggest_at_operator_in_slice_pat_with_range(&self, err: &mut Diag<'_>, path: &[Segment]) {
13011297
let Some(pat) = self.diag_metadata.current_pat else { return };
13021298
let (bound, side, range) = match &pat.kind {
13031299
ast::PatKind::Range(Some(bound), None, range) => (bound, Side::Start, range),
@@ -1358,7 +1354,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
13581354
}
13591355

13601356
fn explain_functions_in_pattern(
1361-
&mut self,
1357+
&self,
13621358
err: &mut Diag<'_>,
13631359
res: Option<Res>,
13641360
source: PathSource<'_, '_, '_>,
@@ -1370,7 +1366,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
13701366
}
13711367

13721368
fn suggest_changing_type_to_const_param(
1373-
&mut self,
1369+
&self,
13741370
err: &mut Diag<'_>,
13751371
res: Option<Res>,
13761372
source: PathSource<'_, '_, '_>,
@@ -1420,7 +1416,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
14201416
}
14211417

14221418
fn suggest_pattern_match_with_let(
1423-
&mut self,
1419+
&self,
14241420
err: &mut Diag<'_>,
14251421
source: PathSource<'_, '_, '_>,
14261422
span: Span,
@@ -1475,7 +1471,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
14751471
}
14761472

14771473
/// Given `where <T as Bar>::Baz: String`, suggest `where T: Bar<Baz = String>`.
1478-
fn restrict_assoc_type_in_where_clause(&mut self, span: Span, err: &mut Diag<'_>) -> bool {
1474+
fn restrict_assoc_type_in_where_clause(&self, span: Span, err: &mut Diag<'_>) -> bool {
14791475
// Detect that we are actually in a `where` predicate.
14801476
let (bounded_ty, bounds, where_span) = if let Some(ast::WherePredicate {
14811477
kind:
@@ -1623,7 +1619,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
16231619
let ns = source.namespace();
16241620
let is_expected = &|res| source.is_expected(res);
16251621

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

16291625
let (lhs_span, rhs_span) = match &expr.kind {
@@ -2575,7 +2571,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
25752571

25762572
// try to give a suggestion for this pattern: `name = blah`, which is common in other languages
25772573
// suggest `let name = blah` to introduce a new binding
2578-
fn let_binding_suggestion(&mut self, err: &mut Diag<'_>, ident_span: Span) -> bool {
2574+
fn let_binding_suggestion(&self, err: &mut Diag<'_>, ident_span: Span) -> bool {
25792575
if ident_span.from_expansion() {
25802576
return false;
25812577
}

compiler/rustc_resolve/src/lib.rs

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

16081608
fn new_extern_module(
1609-
&mut self,
1609+
&self,
16101610
parent: Option<Module<'ra>>,
16111611
kind: ModuleKind,
16121612
expn_id: ExpnId,
@@ -1997,7 +1997,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19971997
}
19981998
}
19991999

2000-
fn resolve_crate_root(&mut self, ident: Ident) -> Module<'ra> {
2000+
fn resolve_crate_root(&self, ident: Ident) -> Module<'ra> {
20012001
debug!("resolve_crate_root({:?})", ident);
20022002
let mut ctxt = ident.span.ctxt();
20032003
let mark = if ident.name == kw::DollarCrate {
@@ -2070,7 +2070,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
20702070
module
20712071
}
20722072

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

compiler/rustc_resolve/src/macros.rs

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

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

829829
pub(crate) fn finalize_macro_resolutions(&mut self, krate: &Crate) {
830-
let check_consistency = |this: &mut Self,
830+
let check_consistency = |this: &Self,
831831
path: &[Segment],
832832
span,
833833
kind: MacroKind,
@@ -1147,7 +1147,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
11471147
///
11481148
/// Possibly replace its expander to a pre-defined one for built-in macros.
11491149
pub(crate) fn compile_macro(
1150-
&mut self,
1150+
&self,
11511151
macro_def: &ast::MacroDef,
11521152
ident: Ident,
11531153
attrs: &[rustc_hir::Attribute],

0 commit comments

Comments
 (0)