@@ -18,7 +18,7 @@ use hir::map as hir_map;
18
18
use lint;
19
19
use hir:: def:: Def ;
20
20
use hir:: def_id:: { CrateNum , CRATE_DEF_INDEX , DefId , DefIndex , LOCAL_CRATE } ;
21
- use ty:: TyCtxt ;
21
+ use ty:: { self , TyCtxt } ;
22
22
use middle:: privacy:: AccessLevels ;
23
23
use syntax:: symbol:: Symbol ;
24
24
use syntax_pos:: { Span , DUMMY_SP } ;
@@ -436,6 +436,36 @@ struct Checker<'a, 'tcx: 'a> {
436
436
}
437
437
438
438
impl < ' 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
+
439
469
pub fn check_stability ( self , def_id : DefId , id : NodeId , span : Span ) {
440
470
if self . sess . codemap ( ) . span_allows_unstable ( span) {
441
471
debug ! ( "stability: \
@@ -496,6 +526,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
496
526
self . stability . borrow_mut ( ) . used_features . insert ( feature. clone ( ) , level. clone ( ) ) ;
497
527
}
498
528
529
+ // Issue 38412: private items lack stability markers.
530
+ if self . skip_stability_check_due_to_privacy ( def_id) {
531
+ return
532
+ }
533
+
499
534
match stability {
500
535
Some ( & Stability { level : attr:: Unstable { ref reason, issue} , ref feature, .. } ) => {
501
536
if !self . stability . borrow ( ) . active_features . contains ( feature) {
0 commit comments