Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Apr 14, 2019
1 parent 3c3a140 commit dbc7042
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -832,14 +832,16 @@ impl<'a, 'tcx> CrateMetadata {
let ctor_kind = self.get_ctor_kind(child_index);
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Variant, ctor_kind);
let mut vis = self.get_visibility(ctor_def_id.index);
// If the variant is marked as non_exhaustive then lower the visibility
// to within the crate.
let has_non_exhaustive = || { attr::contains_name(
&self.get_item_attrs(def_id.index, sess), "non_exhaustive"
)};
if vis == ty::Visibility::Public && has_non_exhaustive() {
let crate_def_id = DefId { index: CRATE_DEF_INDEX, ..def_id };
vis = ty::Visibility::Restricted(crate_def_id);
if ctor_def_id == def_id && vis == ty::Visibility::Public {
// For non-exhaustive variants lower the constructor visibility to
// within the crate. We only need this for fictive constructors,
// for other constructors correct visibilities
// were already encoded in metadata.
let attrs = self.get_item_attrs(def_id.index, sess);
if attr::contains_name(&attrs, "non_exhaustive") {
let crate_def_id = DefId { index: CRATE_DEF_INDEX, ..def_id };
vis = ty::Visibility::Restricted(crate_def_id);
}
}
callback(def::Export { def: ctor_def, ident, vis, span });
}
Expand Down
Expand Up @@ -4,6 +4,9 @@
extern crate variants;

const S: u8 = 0;

// OK, `Struct` in value namespace is crate-private, so it's filtered away
// and there's no conflict with the previously defined `const S`.
use variants::NonExhaustiveVariants::Struct as S;

fn main() {}

0 comments on commit dbc7042

Please sign in to comment.