Skip to content

Commit dbc7042

Browse files
committed
Address review comments
1 parent 3c3a140 commit dbc7042

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/librustc_metadata/decoder.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -832,14 +832,16 @@ impl<'a, 'tcx> CrateMetadata {
832832
let ctor_kind = self.get_ctor_kind(child_index);
833833
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Variant, ctor_kind);
834834
let mut vis = self.get_visibility(ctor_def_id.index);
835-
// If the variant is marked as non_exhaustive then lower the visibility
836-
// to within the crate.
837-
let has_non_exhaustive = || { attr::contains_name(
838-
&self.get_item_attrs(def_id.index, sess), "non_exhaustive"
839-
)};
840-
if vis == ty::Visibility::Public && has_non_exhaustive() {
841-
let crate_def_id = DefId { index: CRATE_DEF_INDEX, ..def_id };
842-
vis = ty::Visibility::Restricted(crate_def_id);
835+
if ctor_def_id == def_id && vis == ty::Visibility::Public {
836+
// For non-exhaustive variants lower the constructor visibility to
837+
// within the crate. We only need this for fictive constructors,
838+
// for other constructors correct visibilities
839+
// were already encoded in metadata.
840+
let attrs = self.get_item_attrs(def_id.index, sess);
841+
if attr::contains_name(&attrs, "non_exhaustive") {
842+
let crate_def_id = DefId { index: CRATE_DEF_INDEX, ..def_id };
843+
vis = ty::Visibility::Restricted(crate_def_id);
844+
}
843845
}
844846
callback(def::Export { def: ctor_def, ident, vis, span });
845847
}

src/test/ui/rfc-2008-non-exhaustive/variants_fictive_visibility.rs

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
extern crate variants;
55

66
const S: u8 = 0;
7+
8+
// OK, `Struct` in value namespace is crate-private, so it's filtered away
9+
// and there's no conflict with the previously defined `const S`.
710
use variants::NonExhaustiveVariants::Struct as S;
811

912
fn main() {}

0 commit comments

Comments
 (0)