Skip to content

Commit 3c3a140

Browse files
committed
Fix cross-crate visibility of fictive variant constructors
1 parent 464473a commit 3c3a140

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/librustc_metadata/decoder.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,16 @@ impl<'a, 'tcx> CrateMetadata {
831831
let ctor_def_id = self.get_ctor_def_id(child_index).unwrap_or(def_id);
832832
let ctor_kind = self.get_ctor_kind(child_index);
833833
let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Variant, ctor_kind);
834-
let vis = self.get_visibility(ctor_def_id.index);
834+
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);
843+
}
835844
callback(def::Export { def: ctor_def, ident, vis, span });
836845
}
837846
_ => {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile-pass
2+
// aux-build:variants.rs
3+
4+
extern crate variants;
5+
6+
const S: u8 = 0;
7+
use variants::NonExhaustiveVariants::Struct as S;
8+
9+
fn main() {}

0 commit comments

Comments
 (0)