mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
rustc_metadata: Make attribute decoding slightly faster and stricter
Rename `CStore::item_attrs` -> `CStore::item_attrs_untracked` top follow conventions
This commit is contained in:
parent
636fd495c8
commit
4c6120c386
@ -1309,24 +1309,26 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
|
||||
fn get_item_attrs(
|
||||
&'a self,
|
||||
node_id: DefIndex,
|
||||
id: DefIndex,
|
||||
sess: &'a Session,
|
||||
) -> impl Iterator<Item = ast::Attribute> + 'a {
|
||||
// The attributes for a tuple struct/variant are attached to the definition, not the ctor;
|
||||
// we assume that someone passing in a tuple struct ctor is actually wanting to
|
||||
// look at the definition
|
||||
let def_key = self.def_key(node_id);
|
||||
let item_id = if def_key.disambiguated_data.data == DefPathData::Ctor {
|
||||
def_key.parent.unwrap()
|
||||
} else {
|
||||
node_id
|
||||
};
|
||||
|
||||
self.root
|
||||
.tables
|
||||
.attributes
|
||||
.get(self, item_id)
|
||||
.unwrap_or_else(Lazy::empty)
|
||||
.get(self, id)
|
||||
.unwrap_or_else(|| {
|
||||
// Structure and variant constructors don't have any attributes encoded for them,
|
||||
// but we assume that someone passing a constructor ID actually wants to look at
|
||||
// the attributes on the corresponding struct or variant.
|
||||
let def_key = self.def_key(id);
|
||||
assert_eq!(def_key.disambiguated_data.data, DefPathData::Ctor);
|
||||
let parent_id = def_key.parent.expect("no parent for a constructor");
|
||||
self.root
|
||||
.tables
|
||||
.attributes
|
||||
.get(self, parent_id)
|
||||
.expect("no encoded attributes for a structure or variant")
|
||||
})
|
||||
.decode((self, sess))
|
||||
}
|
||||
|
||||
|
@ -145,9 +145,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
||||
lookup_deprecation_entry => {
|
||||
cdata.get_deprecation(def_id.index).map(DeprecationEntry::external)
|
||||
}
|
||||
item_attrs => { tcx.arena.alloc_from_iter(
|
||||
cdata.get_item_attrs(def_id.index, tcx.sess)
|
||||
) }
|
||||
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
|
||||
fn_arg_names => { cdata.get_fn_param_names(tcx, def_id.index) }
|
||||
rendered_const => { cdata.get_rendered_const(def_id.index) }
|
||||
impl_parent => { cdata.get_parent_impl(def_id.index) }
|
||||
@ -470,7 +468,7 @@ impl CStore {
|
||||
self.get_crate_data(cnum).num_def_ids()
|
||||
}
|
||||
|
||||
pub fn item_attrs(&self, def_id: DefId, sess: &Session) -> Vec<ast::Attribute> {
|
||||
pub fn item_attrs_untracked(&self, def_id: DefId, sess: &Session) -> Vec<ast::Attribute> {
|
||||
self.get_crate_data(def_id.krate).get_item_attrs(def_id.index, sess).collect()
|
||||
}
|
||||
|
||||
|
@ -895,8 +895,11 @@ impl<'a> Resolver<'a> {
|
||||
// a note about editions
|
||||
let note = if let Some(did) = did {
|
||||
let requires_note = !did.is_local()
|
||||
&& this.cstore().item_attrs(did, this.session).iter().any(
|
||||
|attr| {
|
||||
&& this
|
||||
.cstore()
|
||||
.item_attrs_untracked(did, this.session)
|
||||
.iter()
|
||||
.any(|attr| {
|
||||
if attr.has_name(sym::rustc_diagnostic_item) {
|
||||
[sym::TryInto, sym::TryFrom, sym::FromIterator]
|
||||
.map(|x| Some(x))
|
||||
@ -904,8 +907,7 @@ impl<'a> Resolver<'a> {
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
requires_note.then(|| {
|
||||
format!(
|
||||
|
@ -3420,7 +3420,7 @@ impl<'a> Resolver<'a> {
|
||||
|
||||
let attr = self
|
||||
.cstore()
|
||||
.item_attrs(def_id, self.session)
|
||||
.item_attrs_untracked(def_id, self.session)
|
||||
.into_iter()
|
||||
.find(|a| a.has_name(sym::rustc_legacy_const_generics))?;
|
||||
let mut ret = Vec::new();
|
||||
|
Loading…
Reference in New Issue
Block a user