@@ -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 } ;
@@ -432,6 +432,36 @@ struct Checker<'a, 'tcx: 'a> {
432432}
433433
434434impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
435+ // (See issue #38412)
436+ fn skip_stability_check_due_to_privacy ( self , def_id : DefId ) -> bool {
437+ let visibility = {
438+ // Check if `def_id` is a trait method.
439+ match self . sess . cstore . associated_item ( def_id) {
440+ Some ( ty:: AssociatedItem { container : ty:: TraitContainer ( trait_def_id) , .. } ) => {
441+ // Trait methods do not declare visibility (even
442+ // for visibility info in cstore). Use containing
443+ // trait instead, so methods of pub traits are
444+ // themselves considered pub.
445+ self . sess . cstore . visibility ( trait_def_id)
446+ }
447+ _ => {
448+ // Otherwise, cstore info works directly.
449+ self . sess . cstore . visibility ( def_id)
450+ }
451+ }
452+ } ;
453+
454+ match visibility {
455+ // must check stability for pub items.
456+ ty:: Visibility :: Public => false ,
457+
458+ // these are not visible outside crate; therefore
459+ // stability markers are irrelevant, if even present.
460+ ty:: Visibility :: Restricted ( ..) |
461+ ty:: Visibility :: Invisible => true ,
462+ }
463+ }
464+
435465 pub fn check_stability ( self , def_id : DefId , id : NodeId , span : Span ) {
436466 if self . sess . codemap ( ) . span_allows_unstable ( span) {
437467 debug ! ( "stability: \
@@ -492,6 +522,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
492522 self . stability . borrow_mut ( ) . used_features . insert ( feature. clone ( ) , level. clone ( ) ) ;
493523 }
494524
525+ // Issue 38412: private items lack stability markers.
526+ if self . skip_stability_check_due_to_privacy ( def_id) {
527+ return
528+ }
529+
495530 match stability {
496531 Some ( & Stability { level : attr:: Unstable { ref reason, issue} , ref feature, .. } ) => {
497532 if !self . stability . borrow ( ) . active_features . contains ( feature) {
0 commit comments