Skip to content

privacy: Relax some asserts on effective visibilities #104546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 1 addition & 8 deletions compiler/rustc_middle/src/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use crate::ty::{DefIdTree, TyCtxt, Visibility};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::def::DefKind;
use rustc_macros::HashStable;
use rustc_query_system::ich::StableHashingContext;
use rustc_span::def_id::LocalDefId;
Expand Down Expand Up @@ -167,7 +166,7 @@ impl EffectiveVisibilities {
// and all effective visibilities are larger or equal than private visibility.
let private_vis = Visibility::Restricted(tcx.parent_module_from_def_id(def_id));
let span = tcx.def_span(def_id.to_def_id());
if !ev.direct.is_at_least(private_vis, tcx) {
if !ev.direct.is_at_least(private_vis, tcx) && tcx.sess.has_errors().is_none() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to delay span bug here and the assert you removed below?

span_bug!(span, "private {:?} > direct {:?}", private_vis, ev.direct);
}
if !ev.reexported.is_at_least(ev.direct, tcx) {
Expand All @@ -185,7 +184,6 @@ impl EffectiveVisibilities {
);
}
let nominal_vis = tcx.visibility(def_id);
let def_kind = tcx.opt_def_kind(def_id);
// FIXME: `rustc_privacy` is not yet updated for the new logic and can set
// effective visibilities that are larger than the nominal one.
if !nominal_vis.is_at_least(ev.reachable_through_impl_trait, tcx) && early {
Expand All @@ -197,11 +195,6 @@ impl EffectiveVisibilities {
nominal_vis
);
}
// Fully private items are never put into the table, this is important for performance.
// FIXME: Fully private `mod` items are currently put into the table.
if ev.reachable_through_impl_trait == private_vis && def_kind != Some(DefKind::Mod) {
span_bug!(span, "fully private item in the table {:?}: {:?}", def_id, ev.direct);
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/privacy/effective_visibilities_invariants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Invariant checking doesn't ICE in some cases with errors (issue #104249).

#![feature(staged_api)] //~ ERROR module has missing stability attribute

pub mod m {} //~ ERROR module has missing stability attribute

pub mod m { //~ ERROR the name `m` is defined multiple times
mod inner {}
type Inner = u8;
}

fn main() {}
32 changes: 32 additions & 0 deletions src/test/ui/privacy/effective_visibilities_invariants.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error[E0428]: the name `m` is defined multiple times
--> $DIR/effective_visibilities_invariants.rs:7:1
|
LL | pub mod m {}
| --------- previous definition of the module `m` here
LL |
LL | pub mod m {
| ^^^^^^^^^ `m` redefined here
|
= note: `m` must be defined only once in the type namespace of this module

error: module has missing stability attribute
--> $DIR/effective_visibilities_invariants.rs:3:1
|
LL | / #![feature(staged_api)]
LL | |
LL | | pub mod m {}
LL | |
... |
LL | |
LL | | fn main() {}
| |____________^

error: module has missing stability attribute
--> $DIR/effective_visibilities_invariants.rs:5:1
|
LL | pub mod m {}
| ^^^^^^^^^^^^

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0428`.