change depr_map to use DeprecationEntry
This commit is contained in:
parent
75e2624a51
commit
b4c6a39ccf
@ -19,7 +19,7 @@ use session::Session;
|
|||||||
use lint;
|
use lint;
|
||||||
use middle::cstore::LOCAL_CRATE;
|
use middle::cstore::LOCAL_CRATE;
|
||||||
use hir::def::Def;
|
use hir::def::Def;
|
||||||
use hir::def_id::{CRATE_DEF_INDEX, DefId};
|
use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndex};
|
||||||
use ty::{self, TyCtxt};
|
use ty::{self, TyCtxt};
|
||||||
use middle::privacy::AccessLevels;
|
use middle::privacy::AccessLevels;
|
||||||
use syntax::parse::token::InternedString;
|
use syntax::parse::token::InternedString;
|
||||||
@ -61,12 +61,46 @@ enum AnnotationKind {
|
|||||||
Container,
|
Container,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An entry in the `depr_map`.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct DeprecationEntry {
|
||||||
|
/// The metadata of the attribute associated with this entry.
|
||||||
|
pub attr: Deprecation,
|
||||||
|
/// The def id where the attr was originally attached. `None` for non-local
|
||||||
|
/// `DefId`'s.
|
||||||
|
origin: Option<DefIndex>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DeprecationEntry {
|
||||||
|
fn local(attr: Deprecation, id: DefId) -> DeprecationEntry {
|
||||||
|
assert!(id.is_local());
|
||||||
|
DeprecationEntry {
|
||||||
|
attr: attr,
|
||||||
|
origin: Some(id.index),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn external(attr: Deprecation) -> DeprecationEntry {
|
||||||
|
DeprecationEntry {
|
||||||
|
attr: attr,
|
||||||
|
origin: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn same_origin(&self, other: &DeprecationEntry) -> bool {
|
||||||
|
match (self.origin, other.origin) {
|
||||||
|
(Some(o1), Some(o2)) => o1 == o2,
|
||||||
|
_ => false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A stability index, giving the stability level for items and methods.
|
/// A stability index, giving the stability level for items and methods.
|
||||||
pub struct Index<'tcx> {
|
pub struct Index<'tcx> {
|
||||||
/// This is mostly a cache, except the stabilities of local items
|
/// This is mostly a cache, except the stabilities of local items
|
||||||
/// are filled by the annotator.
|
/// are filled by the annotator.
|
||||||
stab_map: DefIdMap<Option<&'tcx Stability>>,
|
stab_map: DefIdMap<Option<&'tcx Stability>>,
|
||||||
depr_map: DefIdMap<Option<Deprecation>>,
|
depr_map: DefIdMap<Option<DeprecationEntry>>,
|
||||||
|
|
||||||
/// Maps for each crate whether it is part of the staged API.
|
/// Maps for each crate whether it is part of the staged API.
|
||||||
staged_api: FnvHashMap<ast::CrateNum, bool>
|
staged_api: FnvHashMap<ast::CrateNum, bool>
|
||||||
@ -77,7 +111,7 @@ struct Annotator<'a, 'tcx: 'a> {
|
|||||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
index: &'a mut Index<'tcx>,
|
index: &'a mut Index<'tcx>,
|
||||||
parent_stab: Option<&'tcx Stability>,
|
parent_stab: Option<&'tcx Stability>,
|
||||||
parent_depr: Option<Deprecation>,
|
parent_depr: Option<DeprecationEntry>,
|
||||||
access_levels: &'a AccessLevels,
|
access_levels: &'a AccessLevels,
|
||||||
in_trait_impl: bool,
|
in_trait_impl: bool,
|
||||||
}
|
}
|
||||||
@ -184,14 +218,15 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> {
|
|||||||
|
|
||||||
// `Deprecation` is just two pointers, no need to intern it
|
// `Deprecation` is just two pointers, no need to intern it
|
||||||
let def_id = self.tcx.map.local_def_id(id);
|
let def_id = self.tcx.map.local_def_id(id);
|
||||||
self.index.depr_map.insert(def_id, Some(depr.clone()));
|
let depr_entry = Some(DeprecationEntry::local(depr, def_id));
|
||||||
|
self.index.depr_map.insert(def_id, depr_entry.clone());
|
||||||
|
|
||||||
let orig_parent_depr = replace(&mut self.parent_depr, Some(depr));
|
let orig_parent_depr = replace(&mut self.parent_depr, depr_entry);
|
||||||
visit_children(self);
|
visit_children(self);
|
||||||
self.parent_depr = orig_parent_depr;
|
self.parent_depr = orig_parent_depr;
|
||||||
} else if let Some(depr) = self.parent_depr.clone() {
|
} else if let parent_depr @ Some(_) = self.parent_depr.clone() {
|
||||||
let def_id = self.tcx.map.local_def_id(id);
|
let def_id = self.tcx.map.local_def_id(id);
|
||||||
self.index.depr_map.insert(def_id, Some(depr));
|
self.index.depr_map.insert(def_id, parent_depr);
|
||||||
visit_children(self);
|
visit_children(self);
|
||||||
} else {
|
} else {
|
||||||
visit_children(self);
|
visit_children(self);
|
||||||
@ -685,6 +720,10 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn lookup_deprecation(self, id: DefId) -> Option<Deprecation> {
|
pub fn lookup_deprecation(self, id: DefId) -> Option<Deprecation> {
|
||||||
|
self.lookup_deprecation_entry(id).map(|depr| depr.attr)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn lookup_deprecation_entry(self, id: DefId) -> Option<DeprecationEntry> {
|
||||||
if let Some(depr) = self.stability.borrow().depr_map.get(&id) {
|
if let Some(depr) = self.stability.borrow().depr_map.get(&id) {
|
||||||
return depr.clone();
|
return depr.clone();
|
||||||
}
|
}
|
||||||
@ -703,12 +742,12 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lookup_deprecation_uncached(self, id: DefId) -> Option<Deprecation> {
|
fn lookup_deprecation_uncached(self, id: DefId) -> Option<DeprecationEntry> {
|
||||||
debug!("lookup(id={:?})", id);
|
debug!("lookup(id={:?})", id);
|
||||||
if id.is_local() {
|
if id.is_local() {
|
||||||
None // The stability cache is filled partially lazily
|
None // The stability cache is filled partially lazily
|
||||||
} else {
|
} else {
|
||||||
self.sess.cstore.deprecation(id)
|
self.sess.cstore.deprecation(id).map(DeprecationEntry::external)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user