mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-23 11:58:04 +03:00
Address review comments
This commit is contained in:
@@ -832,14 +832,16 @@ pub fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F, sess: &Sessio
|
||||
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 });
|
||||
}
|
||||
|
||||
@@ -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() {}
|
||||
|
||||
Reference in New Issue
Block a user