@@ -832,14 +832,16 @@ impl<'a, 'tcx> CrateMetadata {
832
832
let ctor_kind = self . get_ctor_kind ( child_index) ;
833
833
let ctor_def = Def :: Ctor ( ctor_def_id, CtorOf :: Variant , ctor_kind) ;
834
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) ;
835
+ if ctor_def_id == def_id && vis == ty:: Visibility :: Public {
836
+ // For non-exhaustive variants lower the constructor visibility to
837
+ // within the crate. We only need this for fictive constructors,
838
+ // for other constructors correct visibilities
839
+ // were already encoded in metadata.
840
+ let attrs = self . get_item_attrs ( def_id. index , sess) ;
841
+ if attr:: contains_name ( & attrs, "non_exhaustive" ) {
842
+ let crate_def_id = DefId { index : CRATE_DEF_INDEX , ..def_id } ;
843
+ vis = ty:: Visibility :: Restricted ( crate_def_id) ;
844
+ }
843
845
}
844
846
callback ( def:: Export { def : ctor_def, ident, vis, span } ) ;
845
847
}
0 commit comments