Navigation Menu

Skip to content

Commit

Permalink
Fix cross-crate visibility of fictive variant constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Apr 14, 2019
1 parent 464473a commit 3c3a140
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/librustc_metadata/decoder.rs
Expand Up @@ -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 });
}
_ => {}
Expand Down
@@ -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() {}

0 comments on commit 3c3a140

Please sign in to comment.