Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
) {
let decl = self.arenas.alloc_decl(DeclData {
kind: DeclKind::Def(res),
ambiguity,
ambiguity: CmCell::new(ambiguity),
// External ambiguities always report the `AMBIGUOUS_GLOB_IMPORTS` lint at the moment.
warn_ambiguity: true,
vis,
warn_ambiguity: CmCell::new(true),
vis: CmCell::new(vis),
span,
expansion,
});
Expand Down Expand Up @@ -1158,18 +1158,18 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> {
self.r.potentially_unused_imports.push(import);
module.for_each_child_mut(self, |this, ident, ns, binding| {
if ns == MacroNS {
let import = if this.r.is_accessible_from(binding.vis, this.parent_scope.module)
{
import
} else {
// FIXME: This branch is used for reporting the `private_macro_use` lint
// and should eventually be removed.
if this.r.macro_use_prelude.contains_key(&ident.name) {
// Do not override already existing entries with compatibility entries.
return;
}
macro_use_import(this, span, true)
};
let import =
if this.r.is_accessible_from(binding.vis(), this.parent_scope.module) {
import
} else {
// FIXME: This branch is used for reporting the `private_macro_use` lint
// and should eventually be removed.
if this.r.macro_use_prelude.contains_key(&ident.name) {
// Do not override already existing entries with compatibility entries.
return;
}
macro_use_import(this, span, true)
};
let import_decl = this.r.new_import_decl(binding, import);
this.add_macro_use_decl(ident.name, import_decl, span, allow_shadowing);
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
}

let child_accessible =
accessible && this.is_accessible_from(name_binding.vis, parent_scope.module);
accessible && this.is_accessible_from(name_binding.vis(), parent_scope.module);

// do not venture inside inaccessible items of other crates
if in_module_is_extern && !child_accessible {
Expand All @@ -1358,8 +1358,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

// #90113: Do not count an inaccessible reexported item as a candidate.
if let DeclKind::Import { source_decl, .. } = name_binding.kind
&& this.is_accessible_from(source_decl.vis, parent_scope.module)
&& !this.is_accessible_from(name_binding.vis, parent_scope.module)
&& this.is_accessible_from(source_decl.vis(), parent_scope.module)
&& !this.is_accessible_from(name_binding.vis(), parent_scope.module)
{
return;
}
Expand Down Expand Up @@ -2243,7 +2243,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let first = binding == first_binding;
let def_span = self.tcx.sess.source_map().guess_head_span(binding.span);
let mut note_span = MultiSpan::from_span(def_span);
if !first && binding.vis.is_public() {
if !first && binding.vis().is_public() {
let desc = match binding.kind {
DeclKind::Import { .. } => "re-export",
_ => "directly",
Expand Down
15 changes: 9 additions & 6 deletions compiler/rustc_resolve/src/effective_visibilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
if let Some(node_id) = import.id() {
r.effective_visibilities.update_eff_vis(r.local_def_id(node_id), eff_vis, r.tcx)
}
} else if decl.ambiguity.is_some() && eff_vis.is_public_at_level(Level::Reexported) {
} else if decl.ambiguity.get().is_some()
&& eff_vis.is_public_at_level(Level::Reexported)
{
exported_ambiguities.insert(*decl);
}
}
Expand All @@ -125,9 +127,10 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
// If the binding is ambiguous, put the root ambiguity binding and all reexports
// leading to it into the table. They are used by the `ambiguous_glob_reexports`
// lint. For all bindings added to the table this way `is_ambiguity` returns true.
let is_ambiguity = |decl: Decl<'ra>, warn: bool| decl.ambiguity.is_some() && !warn;
let is_ambiguity =
|decl: Decl<'ra>, warn: bool| decl.ambiguity.get().is_some() && !warn;
let mut parent_id = ParentId::Def(module_id);
let mut warn_ambiguity = decl.warn_ambiguity;
let mut warn_ambiguity = decl.warn_ambiguity.get();
while let DeclKind::Import { source_decl, .. } = decl.kind {
self.update_import(decl, parent_id);

Expand All @@ -140,12 +143,12 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {

parent_id = ParentId::Import(decl);
decl = source_decl;
warn_ambiguity |= source_decl.warn_ambiguity;
warn_ambiguity |= source_decl.warn_ambiguity.get();
}
if !is_ambiguity(decl, warn_ambiguity)
&& let Some(def_id) = decl.res().opt_def_id().and_then(|id| id.as_local())
{
self.update_def(def_id, decl.vis.expect_local(), parent_id);
self.update_def(def_id, decl.vis().expect_local(), parent_id);
}
}
}
Expand Down Expand Up @@ -188,7 +191,7 @@ impl<'a, 'ra, 'tcx> EffectiveVisibilitiesVisitor<'a, 'ra, 'tcx> {
}

fn update_import(&mut self, decl: Decl<'ra>, parent_id: ParentId<'ra>) {
let nominal_vis = decl.vis.expect_local();
let nominal_vis = decl.vis().expect_local();
let Some(cheap_private_vis) = self.may_update(nominal_vis, parent_id) else { return };
let inherited_eff_vis = self.effective_vis_or_private(parent_id);
let tcx = self.r.tcx;
Expand Down
11 changes: 6 additions & 5 deletions compiler/rustc_resolve/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

// Items and single imports are not shadowable, if we have one, then it's determined.
if let Some(binding) = binding {
let accessible = self.is_accessible_from(binding.vis, parent_scope.module);
let accessible = self.is_accessible_from(binding.vis(), parent_scope.module);
return if accessible { Ok(binding) } else { Err(ControlFlow::Break(Determined)) };
}

Expand Down Expand Up @@ -1103,7 +1103,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// shadowing is enabled, see `macro_expanded_macro_export_errors`).
if let Some(binding) = binding {
return if binding.determined() || ns == MacroNS || shadowing == Shadowing::Restricted {
let accessible = self.is_accessible_from(binding.vis, parent_scope.module);
let accessible = self.is_accessible_from(binding.vis(), parent_scope.module);
if accessible { Ok(binding) } else { Err(ControlFlow::Break(Determined)) }
} else {
Err(ControlFlow::Break(Undetermined))
Expand Down Expand Up @@ -1160,7 +1160,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
match result {
Err(Determined) => continue,
Ok(binding)
if !self.is_accessible_from(binding.vis, glob_import.parent_scope.module) =>
if !self.is_accessible_from(binding.vis(), glob_import.parent_scope.module) =>
{
continue;
}
Expand All @@ -1187,7 +1187,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
return Err(ControlFlow::Continue(Determined));
};

if !self.is_accessible_from(binding.vis, parent_scope.module) {
if !self.is_accessible_from(binding.vis(), parent_scope.module) {
if report_private {
self.privacy_errors.push(PrivacyError {
ident,
Expand Down Expand Up @@ -1304,7 +1304,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
) {
Err(Determined) => continue,
Ok(binding)
if !self.is_accessible_from(binding.vis, single_import.parent_scope.module) =>
if !self
.is_accessible_from(binding.vis(), single_import.parent_scope.module) =>
{
continue;
}
Expand Down
Loading
Loading