Fix cross-crate visibility of fictive variant constructors

This commit is contained in:
Vadim Petrochenkov 2019-04-13 12:56:07 +03:00
parent 464473ab3b
commit 3c3a140294
2 changed files with 19 additions and 1 deletions

View File

@ -831,7 +831,16 @@ impl<'a, 'tcx> CrateMetadata {
let ctor_def_id = self.get_ctor_def_id(child_index).unwrap_or(def_id);
let ctor_kind = self.get_ctor_kind(child_index);
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Variant, ctor_kind);
let vis = self.get_visibility(ctor_def_id.index);
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);
}
callback(def::Export { def: ctor_def, ident, vis, span });
}
_ => {}

View File

@ -0,0 +1,9 @@
// compile-pass
// aux-build:variants.rs
extern crate variants;
const S: u8 = 0;
use variants::NonExhaustiveVariants::Struct as S;
fn main() {}