Skip to content

Commit 8c06dc4

Browse files
committed
make import.vis is not mutable
1 parent 9bad7ba commit 8c06dc4

File tree

9 files changed

+129
-63
lines changed

9 files changed

+129
-63
lines changed

compiler/rustc_resolve/src/build_reduced_graph.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
283283
parent_scope,
284284
finalize.then(|| Finalize::new(id, path.span)),
285285
None,
286+
None,
286287
) {
287288
PathResult::Module(ModuleOrUniformRoot::Module(module)) => {
288289
let res = module.res().expect("visibility resolved to unnamed block");
@@ -372,7 +373,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
372373
has_attributes: !item.attrs.is_empty(),
373374
root_span,
374375
root_id,
375-
vis: Cell::new(Some(vis)),
376+
vis,
376377
used: Default::default(),
377378
});
378379

@@ -888,7 +889,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
888889
root_span: item.span,
889890
span: item.span,
890891
module_path: Vec::new(),
891-
vis: Cell::new(Some(vis)),
892+
vis,
892893
used: Cell::new(used.then_some(Used::Other)),
893894
});
894895
self.r.potentially_unused_imports.push(import);
@@ -1089,7 +1090,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
10891090
root_span: span,
10901091
span,
10911092
module_path: Vec::new(),
1092-
vis: Cell::new(Some(ty::Visibility::Restricted(CRATE_DEF_ID))),
1093+
vis: ty::Visibility::Restricted(CRATE_DEF_ID),
10931094
used: Default::default(),
10941095
})
10951096
};
@@ -1125,6 +1126,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
11251126
ident,
11261127
MacroNS,
11271128
&self.parent_scope,
1129+
None,
11281130
);
11291131
if let Ok(binding) = result {
11301132
let import = macro_use_import(self, ident.span, false);
@@ -1253,7 +1255,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
12531255
root_span: span,
12541256
span,
12551257
module_path: Vec::new(),
1256-
vis: Cell::new(Some(vis)),
1258+
vis,
12571259
used: Cell::new(Some(Used::Other)),
12581260
});
12591261
let import_binding = self.r.import(binding, import);

compiler/rustc_resolve/src/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl Resolver<'_, '_> {
382382
for import in self.potentially_unused_imports.iter() {
383383
match import.kind {
384384
_ if import.used.get().is_some()
385-
|| import.expect_vis().is_public()
385+
|| import.vis.is_public()
386386
|| import.span.is_dummy() =>
387387
{
388388
if let ImportKind::MacroUse { .. } = import.kind {

compiler/rustc_resolve/src/diagnostics.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
10521052
parent_scope,
10531053
false,
10541054
false,
1055+
None,
10551056
) {
10561057
suggestions.extend(
10571058
ext.helper_attrs
@@ -1506,6 +1507,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15061507
None,
15071508
false,
15081509
None,
1510+
None,
15091511
) {
15101512
let desc = match binding.res() {
15111513
Res::Def(DefKind::Macro(MacroKind::Bang), _) => {
@@ -1983,6 +1985,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
19831985
parent_scope: &ParentScope<'a>,
19841986
ribs: Option<&PerNS<Vec<Rib<'a>>>>,
19851987
ignore_binding: Option<NameBinding<'a>>,
1988+
ignore_import: Option<Import<'a>>,
19861989
module: Option<ModuleOrUniformRoot<'a>>,
19871990
failed_segment_idx: usize,
19881991
ident: Ident,
@@ -2066,11 +2069,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20662069
parent_scope,
20672070
None,
20682071
ignore_binding,
2072+
ignore_import,
20692073
)
20702074
.ok()
20712075
} else if let Some(ribs) = ribs
20722076
&& let Some(TypeNS | ValueNS) = opt_ns
20732077
{
2078+
assert!(ignore_import.is_none());
20742079
match self.resolve_ident_in_lexical_scope(
20752080
ident,
20762081
ns_to_try,
@@ -2091,6 +2096,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
20912096
None,
20922097
false,
20932098
ignore_binding,
2099+
ignore_import,
20942100
)
20952101
.ok()
20962102
};
@@ -2132,6 +2138,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
21322138
} else if ident.name.as_str().chars().next().is_some_and(|c| c.is_ascii_uppercase()) {
21332139
// Check whether the name refers to an item in the value namespace.
21342140
let binding = if let Some(ribs) = ribs {
2141+
assert!(ignore_import.is_none());
21352142
self.resolve_ident_in_lexical_scope(
21362143
ident,
21372144
ValueNS,
@@ -2206,6 +2213,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
22062213
None,
22072214
false,
22082215
ignore_binding,
2216+
ignore_import,
22092217
) {
22102218
let descr = binding.res().descr();
22112219
(format!("{descr} `{ident}` is not a crate or module"), suggestion)
@@ -2259,7 +2267,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
22592267
) -> Option<(Vec<Segment>, Option<String>)> {
22602268
// Replace first ident with `self` and check if that is valid.
22612269
path[0].ident.name = kw::SelfLower;
2262-
let result = self.maybe_resolve_path(&path, None, parent_scope);
2270+
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
22632271
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
22642272
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
22652273
}
@@ -2278,7 +2286,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
22782286
) -> Option<(Vec<Segment>, Option<String>)> {
22792287
// Replace first ident with `crate` and check if that is valid.
22802288
path[0].ident.name = kw::Crate;
2281-
let result = self.maybe_resolve_path(&path, None, parent_scope);
2289+
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
22822290
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
22832291
if let PathResult::Module(..) = result {
22842292
Some((
@@ -2309,7 +2317,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
23092317
) -> Option<(Vec<Segment>, Option<String>)> {
23102318
// Replace first ident with `crate` and check if that is valid.
23112319
path[0].ident.name = kw::Super;
2312-
let result = self.maybe_resolve_path(&path, None, parent_scope);
2320+
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
23132321
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
23142322
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
23152323
}
@@ -2343,7 +2351,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
23432351
for name in extern_crate_names.into_iter() {
23442352
// Replace first ident with a crate name and check if that is valid.
23452353
path[0].ident.name = name;
2346-
let result = self.maybe_resolve_path(&path, None, parent_scope);
2354+
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
23472355
debug!(
23482356
"make_external_crate_suggestion: name={:?} path={:?} result={:?}",
23492357
name, path, result
@@ -2509,12 +2517,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
25092517
}
25102518

25112519
/// Finds a cfg-ed out item inside `module` with the matching name.
2512-
pub(crate) fn find_cfg_stripped(
2513-
&mut self,
2514-
err: &mut Diag<'_>,
2515-
segment: &Symbol,
2516-
module: DefId,
2517-
) {
2520+
pub(crate) fn find_cfg_stripped(&self, err: &mut Diag<'_>, segment: &Symbol, module: DefId) {
25182521
let local_items;
25192522
let symbols = if module.is_local() {
25202523
local_items = self

0 commit comments

Comments
 (0)