@@ -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 } ;
@@ -432,6 +432,36 @@ struct Checker<'a, 'tcx: 'a> {
432
432
}
433
433
434
434
impl < ' 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
+
435
465
pub fn check_stability ( self , def_id : DefId , id : NodeId , span : Span ) {
436
466
if self . sess . codemap ( ) . span_allows_unstable ( span) {
437
467
debug ! ( "stability: \
@@ -492,6 +522,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
492
522
self . stability . borrow_mut ( ) . used_features . insert ( feature. clone ( ) , level. clone ( ) ) ;
493
523
}
494
524
525
+ // Issue 38412: private items lack stability markers.
526
+ if self . skip_stability_check_due_to_privacy ( def_id) {
527
+ return
528
+ }
529
+
495
530
match stability {
496
531
Some ( & Stability { level : attr:: Unstable { ref reason, issue} , ref feature, .. } ) => {
497
532
if !self . stability . borrow ( ) . active_features . contains ( feature) {
0 commit comments