@@ -18,7 +18,7 @@ use hir::map as hir_map;
1818use lint;
1919use hir:: def:: Def ;
2020use hir:: def_id:: { CrateNum , CRATE_DEF_INDEX , DefId , DefIndex , LOCAL_CRATE } ;
21- use ty:: TyCtxt ;
21+ use ty:: { self , TyCtxt } ;
2222use middle:: privacy:: AccessLevels ;
2323use syntax:: symbol:: Symbol ;
2424use syntax_pos:: { Span , DUMMY_SP } ;
@@ -436,6 +436,36 @@ struct Checker<'a, 'tcx: 'a> {
436436}
437437
438438impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
439+ // (See issue #38412)
440+ fn skip_stability_check_due_to_privacy ( self , def_id : DefId ) -> bool {
441+ let visibility = {
442+ // Check if `def_id` is a trait method.
443+ match self . sess . cstore . associated_item ( def_id) {
444+ Some ( ty:: AssociatedItem { container : ty:: TraitContainer ( trait_def_id) , .. } ) => {
445+ // Trait methods do not declare visibility (even
446+ // for visibility info in cstore). Use containing
447+ // trait instead, so methods of pub traits are
448+ // themselves considered pub.
449+ self . sess . cstore . visibility ( trait_def_id)
450+ }
451+ _ => {
452+ // Otherwise, cstore info works directly.
453+ self . sess . cstore . visibility ( def_id)
454+ }
455+ }
456+ } ;
457+
458+ match visibility {
459+ // must check stability for pub items.
460+ ty:: Visibility :: Public => false ,
461+
462+ // these are not visible outside crate; therefore
463+ // stability markers are irrelevant, if even present.
464+ ty:: Visibility :: Restricted ( ..) |
465+ ty:: Visibility :: Invisible => true ,
466+ }
467+ }
468+
439469 pub fn check_stability ( self , def_id : DefId , id : NodeId , span : Span ) {
440470 if self . sess . codemap ( ) . span_allows_unstable ( span) {
441471 debug ! ( "stability: \
@@ -496,6 +526,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
496526 self . stability . borrow_mut ( ) . used_features . insert ( feature. clone ( ) , level. clone ( ) ) ;
497527 }
498528
529+ // Issue 38412: private items lack stability markers.
530+ if self . skip_stability_check_due_to_privacy ( def_id) {
531+ return
532+ }
533+
499534 match stability {
500535 Some ( & Stability { level : attr:: Unstable { ref reason, issue} , ref feature, .. } ) => {
501536 if !self . stability . borrow ( ) . active_features . contains ( feature) {
0 commit comments