privacy: no nominal visibility for assoc fns
When `staged_api` is enabled, effective visibilities are computed earlier and this can trigger an ICE in some cases. In particular, if a impl of a trait method has a visibility then an error will be reported for that, but when privacy invariants are being checked, the effective visibility will still be greater than the nominal visbility and that will trigger a `span_bug!`. However, this invariant - that effective visibilites are limited to nominal visibility - doesn't make sense for associated functions. Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
parent
aafd75a9c5
commit
e051a32311
7 changed files with 202 additions and 2 deletions
|
@ -178,7 +178,12 @@ impl EffectiveVisibilities {
|
|||
// All effective visibilities except `reachable_through_impl_trait` are limited to
|
||||
// nominal visibility. For some items nominal visibility doesn't make sense so we
|
||||
// don't check this condition for them.
|
||||
if !matches!(tcx.def_kind(def_id), DefKind::Impl { .. }) {
|
||||
let is_impl = matches!(tcx.def_kind(def_id), DefKind::Impl { .. });
|
||||
let is_associated_item_in_trait_impl = tcx
|
||||
.impl_of_method(def_id.to_def_id())
|
||||
.and_then(|impl_id| tcx.trait_id_of_impl(impl_id))
|
||||
.is_some();
|
||||
if !is_impl && !is_associated_item_in_trait_impl {
|
||||
let nominal_vis = tcx.visibility(def_id);
|
||||
if !nominal_vis.is_at_least(ev.reachable, tcx) {
|
||||
span_bug!(
|
||||
|
@ -186,7 +191,7 @@ impl EffectiveVisibilities {
|
|||
"{:?}: reachable {:?} > nominal {:?}",
|
||||
def_id,
|
||||
ev.reachable,
|
||||
nominal_vis
|
||||
nominal_vis,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue