Skip to content

Commit

Permalink
make import.vis is not mutable
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Aug 6, 2024
1 parent 93ea767 commit 533a279
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 50 deletions.
11 changes: 6 additions & 5 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
&segments,
None,
parent_scope,
None,
finalize.then(|| Finalize::new(id, path.span)),
None,
) {
Expand Down Expand Up @@ -372,7 +373,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
has_attributes: !item.attrs.is_empty(),
root_span,
root_id,
vis: Cell::new(Some(vis)),
vis: Some(vis),
used: Default::default(),
});

Expand Down Expand Up @@ -888,7 +889,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
root_span: item.span,
span: item.span,
module_path: Vec::new(),
vis: Cell::new(Some(vis)),
vis: Some(vis),
used: Cell::new(used.then_some(Used::Other)),
});
self.r.potentially_unused_imports.push(import);
Expand Down Expand Up @@ -1089,7 +1090,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
root_span: span,
span,
module_path: Vec::new(),
vis: Cell::new(Some(ty::Visibility::Restricted(CRATE_DEF_ID))),
vis: Some(ty::Visibility::Restricted(CRATE_DEF_ID)),
used: Default::default(),
})
};
Expand Down Expand Up @@ -1125,6 +1126,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
ident,
MacroNS,
&self.parent_scope,
None,
);
if let Ok(binding) = result {
let import = macro_use_import(self, ident.span, false);
Expand Down Expand Up @@ -1253,7 +1255,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
root_span: span,
span,
module_path: Vec::new(),
vis: Cell::new(Some(vis)),
vis: Some(vis),
used: Cell::new(Some(Used::Other)),
});
let import_binding = self.r.import(binding, import);
Expand Down Expand Up @@ -1369,7 +1371,6 @@ impl<'a, 'b, 'tcx> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b, 'tcx> {
self.parent_scope.module = orig_current_module;
self.parent_scope.macro_rules = orig_current_macro_rules_scope;
}

fn visit_assoc_item(&mut self, item: &'b AssocItem, ctxt: AssocCtxt) {
if let AssocItemKind::MacCall(_) = item.kind {
match ctxt {
Expand Down
18 changes: 13 additions & 5 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::{
errors as errs, path_names_to_string, AmbiguityError, AmbiguityErrorMisc, AmbiguityKind,
BindingError, BindingKey, Finalize, HasGenericParams, LexicalScopeBinding, MacroRulesScope,
Module, ModuleKind, ModuleOrUniformRoot, NameBinding, NameBindingKind, ParentScope, PathResult,
PrivacyError, ResolutionError, Resolver, Scope, ScopeSet, Segment, UseError, Used,
PrivacyError, ResolutionError, Resolver, Scope, ScopeSet, Segment, UseError, Used, UsedImport,
VisResolutionError,
};

Expand Down Expand Up @@ -1050,6 +1050,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
derive,
Some(MacroKind::Derive),
parent_scope,
None,
false,
false,
) {
Expand Down Expand Up @@ -1504,6 +1505,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
ScopeSet::All(ns),
parent_scope,
None,
None,
false,
None,
) {
Expand Down Expand Up @@ -1981,6 +1983,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
path: &[Segment],
opt_ns: Option<Namespace>, // `None` indicates a module path in import
parent_scope: &ParentScope<'a>,
used_import: UsedImport<'a>,
ribs: Option<&PerNS<Vec<Rib<'a>>>>,
ignore_binding: Option<NameBinding<'a>>,
module: Option<ModuleOrUniformRoot<'a>>,
Expand Down Expand Up @@ -2064,6 +2067,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
ident,
ns_to_try,
parent_scope,
used_import,
None,
ignore_binding,
)
Expand All @@ -2075,6 +2079,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
ident,
ns_to_try,
parent_scope,
used_import,
None,
&ribs[ns_to_try],
ignore_binding,
Expand All @@ -2088,6 +2093,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
ident,
ScopeSet::All(ns_to_try),
parent_scope,
used_import,
None,
false,
ignore_binding,
Expand Down Expand Up @@ -2136,6 +2142,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
ident,
ValueNS,
parent_scope,
used_import,
None,
&ribs[ValueNS],
ignore_binding,
Expand Down Expand Up @@ -2203,6 +2210,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
ident,
ScopeSet::All(ValueNS),
parent_scope,
used_import,
None,
false,
ignore_binding,
Expand Down Expand Up @@ -2259,7 +2267,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
) -> Option<(Vec<Segment>, Option<String>)> {
// Replace first ident with `self` and check if that is valid.
path[0].ident.name = kw::SelfLower;
let result = self.maybe_resolve_path(&path, None, parent_scope);
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
}
Expand All @@ -2278,7 +2286,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
) -> Option<(Vec<Segment>, Option<String>)> {
// Replace first ident with `crate` and check if that is valid.
path[0].ident.name = kw::Crate;
let result = self.maybe_resolve_path(&path, None, parent_scope);
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
if let PathResult::Module(..) = result {
Some((
Expand Down Expand Up @@ -2309,7 +2317,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
) -> Option<(Vec<Segment>, Option<String>)> {
// Replace first ident with `crate` and check if that is valid.
path[0].ident.name = kw::Super;
let result = self.maybe_resolve_path(&path, None, parent_scope);
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
}
Expand Down Expand Up @@ -2343,7 +2351,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
for name in extern_crate_names.into_iter() {
// Replace first ident with a crate name and check if that is valid.
path[0].ident.name = name;
let result = self.maybe_resolve_path(&path, None, parent_scope);
let result = self.maybe_resolve_path(&path, None, parent_scope, None);
debug!(
"make_external_crate_suggestion: name={:?} path={:?} result={:?}",
name, path, result
Expand Down
Loading

0 comments on commit 533a279

Please sign in to comment.