Skip to content

Commit

Permalink
Dont check stability for items that are not pub to universe.
Browse files Browse the repository at this point in the history
Includes special case handling for trait methods.

Fix #38412.
  • Loading branch information
pnkfelix committed Jan 3, 2017
1 parent 17f1fba commit ae13a72
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/librustc/middle/stability.rs
Expand Up @@ -18,7 +18,7 @@ use hir::map as hir_map;
use lint;
use hir::def::Def;
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, DefIndex, LOCAL_CRATE};
use ty::TyCtxt;
use ty::{self, TyCtxt};
use middle::privacy::AccessLevels;
use syntax::symbol::Symbol;
use syntax_pos::{Span, DUMMY_SP};
Expand Down Expand Up @@ -432,6 +432,36 @@ struct Checker<'a, 'tcx: 'a> {
}

impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// (See issue #38412)
fn skip_stability_check_due_to_privacy(self, def_id: DefId) -> bool {
let visibility = {
// Check if `def_id` is a trait method.
match self.sess.cstore.associated_item(def_id) {
Some(ty::AssociatedItem { container: ty::TraitContainer(trait_def_id), .. }) => {
// Trait methods do not declare visibility (even
// for visibility info in cstore). Use containing
// trait instead, so methods of pub traits are
// themselves considered pub.
self.sess.cstore.visibility(trait_def_id)
}
_ => {
// Otherwise, cstore info works directly.
self.sess.cstore.visibility(def_id)
}
}
};

match visibility {
// must check stability for pub items.
ty::Visibility::Public => false,

// these are not visible outside crate; therefore
// stability markers are irrelevant, if even present.
ty::Visibility::Restricted(..) |
ty::Visibility::Invisible => true,
}
}

pub fn check_stability(self, def_id: DefId, id: NodeId, span: Span) {
if self.sess.codemap().span_allows_unstable(span) {
debug!("stability: \
Expand Down Expand Up @@ -492,6 +522,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.stability.borrow_mut().used_features.insert(feature.clone(), level.clone());
}

// Issue 38412: private items lack stability markers.
if self.skip_stability_check_due_to_privacy(def_id) {
return
}

match stability {
Some(&Stability { level: attr::Unstable {ref reason, issue}, ref feature, .. }) => {
if !self.stability.borrow().active_features.contains(feature) {
Expand Down

0 comments on commit ae13a72

Please sign in to comment.