pub use self::StabilityLevel::*;
use lint;
+use hir::{self, Item, Generics, StructField, Variant, HirId};
use hir::def::Def;
use hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId, LOCAL_CRATE};
-use ty::{self, TyCtxt};
+use hir::intravisit::{self, Visitor, NestedVisitorMap};
use middle::privacy::AccessLevels;
use session::{DiagnosticMessageId, Session};
use syntax::symbol::Symbol;
use syntax::ast::{NodeId, Attribute};
use syntax::feature_gate::{GateIssue, emit_feature_err};
use syntax::attr::{self, Stability, Deprecation};
+use ty::{self, TyCtxt};
use util::nodemap::{FxHashSet, FxHashMap};
-use hir;
-use hir::{Item, Generics, StructField, Variant, HirId};
-use hir::intravisit::{self, Visitor, NestedVisitorMap};
-
use std::mem::replace;
use std::cmp::Ordering;
if self.tcx.features().staged_api {
// This crate explicitly wants staged API.
debug!("annotate(id = {:?}, attrs = {:?})", id, attrs);
- if let Some(..) = attr::find_deprecation(self.tcx.sess.diagnostic(), attrs, item_sp) {
+ if let Some(..) = attr::find_deprecation(&self.tcx.sess.parse_sess, attrs, item_sp) {
self.tcx.sess.span_err(item_sp, "`#[deprecated]` cannot be used in staged api, \
use `#[rustc_deprecated]` instead");
}
- if let Some(mut stab) = attr::find_stability(self.tcx.sess.diagnostic(),
+ if let Some(mut stab) = attr::find_stability(&self.tcx.sess.parse_sess,
attrs, item_sp) {
// Error if prohibited, or can't inherit anything from a container
if kind == AnnotationKind::Prohibited ||
}
}
- let hir_id = self.tcx.hir.node_to_hir_id(id);
+ let hir_id = self.tcx.hir().node_to_hir_id(id);
self.index.stab_map.insert(hir_id, stab);
let orig_parent_stab = replace(&mut self.parent_stab, Some(stab));
debug!("annotate: not found, parent = {:?}", self.parent_stab);
if let Some(stab) = self.parent_stab {
if stab.level.is_unstable() {
- let hir_id = self.tcx.hir.node_to_hir_id(id);
+ let hir_id = self.tcx.hir().node_to_hir_id(id);
self.index.stab_map.insert(hir_id, stab);
}
}
// -Zforce-unstable-if-unmarked is set.
if let Some(stab) = self.parent_stab {
if stab.level.is_unstable() {
- let hir_id = self.tcx.hir.node_to_hir_id(id);
+ let hir_id = self.tcx.hir().node_to_hir_id(id);
self.index.stab_map.insert(hir_id, stab);
}
}
- if let Some(depr) = attr::find_deprecation(self.tcx.sess.diagnostic(), attrs, item_sp) {
+ if let Some(depr) = attr::find_deprecation(&self.tcx.sess.parse_sess, attrs, item_sp) {
if kind == AnnotationKind::Prohibited {
self.tcx.sess.span_err(item_sp, "This deprecation annotation is useless");
}
// `Deprecation` is just two pointers, no need to intern it
- let hir_id = self.tcx.hir.node_to_hir_id(id);
+ let hir_id = self.tcx.hir().node_to_hir_id(id);
let depr_entry = DeprecationEntry::local(depr, hir_id);
self.index.depr_map.insert(hir_id, depr_entry.clone());
visit_children(self);
self.parent_depr = orig_parent_depr;
} else if let Some(parent_depr) = self.parent_depr.clone() {
- let hir_id = self.tcx.hir.node_to_hir_id(id);
+ let hir_id = self.tcx.hir().node_to_hir_id(id);
self.index.depr_map.insert(hir_id, parent_depr);
visit_children(self);
} else {
/// nested items in the context of the outer item, so enable
/// deep-walking.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::All(&self.tcx.hir)
+ NestedVisitorMap::All(&self.tcx.hir())
}
fn visit_item(&mut self, i: &'tcx Item) {
impl<'a, 'tcx: 'a> MissingStabilityAnnotations<'a, 'tcx> {
fn check_missing_stability(&self, id: NodeId, span: Span) {
- let hir_id = self.tcx.hir.node_to_hir_id(id);
+ let hir_id = self.tcx.hir().node_to_hir_id(id);
let stab = self.tcx.stability().local_stability(hir_id);
let is_error = !self.tcx.sess.opts.test &&
stab.is_none() &&
impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.tcx.hir)
+ NestedVisitorMap::OnlyBodies(&self.tcx.hir())
}
fn visit_item(&mut self, i: &'tcx Item) {
}
fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) {
- let impl_def_id = self.tcx.hir.local_def_id(self.tcx.hir.get_parent(ii.id));
+ let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent(ii.id));
if self.tcx.impl_trait_ref(impl_def_id).is_none() {
self.check_missing_stability(ii.id, ii.span);
}
let is_staged_api =
tcx.sess.opts.debugging_opts.force_unstable_if_unmarked ||
tcx.features().staged_api;
- let mut staged_api = FxHashMap();
+ let mut staged_api = FxHashMap::default();
staged_api.insert(LOCAL_CRATE, is_staged_api);
let mut index = Index {
staged_api,
- stab_map: FxHashMap(),
- depr_map: FxHashMap(),
- active_features: FxHashSet(),
+ stab_map: Default::default(),
+ depr_map: Default::default(),
+ active_features: Default::default(),
};
let ref active_lib_features = tcx.features().declared_lib_features;
index.active_features = active_lib_features.iter().map(|&(ref s, _)| s.clone()).collect();
{
- let krate = tcx.hir.krate();
+ let krate = tcx.hir().krate();
let mut annotator = Annotator {
tcx,
index: &mut index,
/// features and possibly prints errors.
pub fn check_unstable_api_usage<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
let mut checker = Checker { tcx };
- tcx.hir.krate().visit_all_item_likes(&mut checker.as_deep_visitor());
+ tcx.hir().krate().visit_all_item_likes(&mut checker.as_deep_visitor());
}
/// Check whether an item marked with `deprecated(since="X")` is currently
-/// deprecated (i.e. whether X is not greater than the current rustc version).
+/// deprecated (i.e., whether X is not greater than the current rustc version).
pub fn deprecation_in_effect(since: &str) -> bool {
fn parse_version(ver: &str) -> Vec<u32> {
- // We ignore non-integer components of the version (e.g. "nightly").
+ // We ignore non-integer components of the version (e.g., "nightly").
ver.split(|c| c == '.' || c == '-').flat_map(|s| s.parse()).collect()
}
}
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
- // (See issue #38412)
+ // See issue #38412.
fn skip_stability_check_due_to_privacy(self, mut def_id: DefId) -> bool {
// Check if `def_id` is a trait method.
match self.describe_def(def_id) {
if let ty::TraitContainer(trait_def_id) = self.associated_item(def_id).container {
// 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.
+ // trait instead, so methods of `pub` traits are
+ // themselves considered `pub`.
def_id = trait_def_id;
}
}
let visibility = self.visibility(def_id);
match visibility {
- // must check stability for pub items.
+ // Must check stability for `pub` items.
ty::Visibility::Public => false,
- // these are not visible outside crate; therefore
+ // These are not visible outside crate; therefore
// stability markers are irrelevant, if even present.
ty::Visibility::Restricted(..) |
ty::Visibility::Invisible => true,
false
};
- let parent_def_id = self.hir.local_def_id(self.hir.get_parent(id));
+ let parent_def_id = self.hir().local_def_id(self.hir().get_parent(id));
let skip = deprecated_in_future_version ||
self.lookup_deprecation_entry(parent_def_id)
.map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry));
return EvalResult::Allow;
}
- // Issue 38412: private items lack stability markers.
+ // Issue #38412: private items lack stability markers.
if self.skip_stability_check_due_to_privacy(def_id) {
return EvalResult::Allow;
}
// crates also pulled in from crates.io. We want to ideally be
// able to compile everything without requiring upstream
// modifications, so in the case that this looks like a
- // rustc_private crate (e.g. a compiler crate) and we also have
+ // `rustc_private` crate (e.g., a compiler crate) and we also have
// the `-Z force-unstable-if-unmarked` flag present (we're
// compiling a compiler crate), then let this missing feature
// annotation slide.
/// nested items in the context of the outer item, so enable
/// deep-walking.
fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
- NestedVisitorMap::OnlyBodies(&self.tcx.hir)
+ NestedVisitorMap::OnlyBodies(&self.tcx.hir())
}
fn visit_item(&mut self, item: &'tcx hir::Item) {
// compiler-generated `extern crate` items have a dummy span.
if item.span.is_dummy() { return }
- let def_id = self.tcx.hir.local_def_id(item.id);
+ let def_id = self.tcx.hir().local_def_id(item.id);
let cnum = match self.tcx.extern_mod_stmt_cnum(def_id) {
Some(cnum) => cnum,
None => return,
hir::ItemKind::Impl(.., Some(ref t), _, ref impl_item_refs) => {
if let Def::Trait(trait_did) = t.path.def {
for impl_item_ref in impl_item_refs {
- let impl_item = self.tcx.hir.impl_item(impl_item_ref.id);
+ let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
let trait_item_def_id = self.tcx.associated_items(trait_did)
.find(|item| item.ident.name == impl_item.ident.name)
.map(|item| item.def_id);
// There's no good place to insert stability check for non-Copy unions,
// so semi-randomly perform it here in stability.rs
hir::ItemKind::Union(..) if !self.tcx.features().untagged_unions => {
- let def_id = self.tcx.hir.local_def_id(item.id);
+ let def_id = self.tcx.hir().local_def_id(item.id);
let adt_def = self.tcx.adt_def(def_id);
let ty = self.tcx.type_of(def_id);
}
fn visit_path(&mut self, path: &'tcx hir::Path, id: hir::HirId) {
- let id = self.tcx.hir.hir_to_node_id(id);
- match path.def {
- Def::Local(..) | Def::Upvar(..) | Def::SelfCtor(..) |
- Def::PrimTy(..) | Def::SelfTy(..) | Def::Err => {}
- _ => self.tcx.check_stability(path.def.def_id(), Some(id), path.span)
+ let id = self.tcx.hir().hir_to_node_id(id);
+ if let Some(def_id) = path.def.opt_def_id() {
+ self.tcx.check_stability(def_id, Some(id), path.span)
}
intravisit::walk_path(self, path)
}
}
}
-/// Given the list of enabled features that were not language features (i.e. that
+/// Given the list of enabled features that were not language features (i.e., that
/// were expected to be library features), and the list of features used from
/// libraries, identify activated features that don't exist and error about them.
pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
if tcx.stability().staged_api[&LOCAL_CRATE] {
- let krate = tcx.hir.krate();
+ let krate = tcx.hir().krate();
let mut missing = MissingStabilityAnnotations {
tcx,
access_levels,
}
let declared_lang_features = &tcx.features().declared_lang_features;
- let mut lang_features = FxHashSet();
+ let mut lang_features = FxHashSet::default();
for &(feature, span, since) in declared_lang_features {
if let Some(since) = since {
// Warn if the user has enabled an already-stable lang feature.
}
let declared_lib_features = &tcx.features().declared_lib_features;
- let mut remaining_lib_features = FxHashMap();
+ let mut remaining_lib_features = FxHashMap::default();
for (feature, span) in declared_lib_features {
if remaining_lib_features.contains_key(&feature) {
// Warn if the user enables a lib feature multiple times.