Handle Attributes in arena.
This commit is contained in:
parent
084e6722f9
commit
abbe6259e1
13 changed files with 41 additions and 42 deletions
|
@ -127,7 +127,7 @@ macro_rules! arena_types {
|
|||
[] attribute: syntax::ast::Attribute,
|
||||
[] global_asm: rustc::hir::GlobalAsm,
|
||||
[] impl_item_ref: rustc::hir::ImplItemRef,
|
||||
[] macro_def: rustc::hir::MacroDef,
|
||||
[] macro_def: rustc::hir::MacroDef<$tcx>,
|
||||
[] path: rustc::hir::Path,
|
||||
[] trait_item_ref: rustc::hir::TraitItemRef,
|
||||
[] ty: rustc::hir::Ty,
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
//! conflicts between multiple such attributes attached to the same
|
||||
//! item.
|
||||
|
||||
use crate::hir::{self, HirId, HirVec, Attribute, Item, ItemKind, TraitItem, TraitItemKind};
|
||||
use crate::hir::{self, HirId, Attribute, Item, ItemKind, TraitItem, TraitItemKind};
|
||||
use crate::hir::DUMMY_HIR_ID;
|
||||
use crate::hir::def_id::DefId;
|
||||
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
|
||||
|
@ -158,7 +158,7 @@ impl CheckAttrVisitor<'tcx> {
|
|||
fn check_attributes(
|
||||
&self,
|
||||
hir_id: HirId,
|
||||
attrs: &HirVec<Attribute>,
|
||||
attrs: &'hir [Attribute],
|
||||
span: &Span,
|
||||
target: Target,
|
||||
item: Option<&Item<'_>>,
|
||||
|
@ -241,7 +241,7 @@ impl CheckAttrVisitor<'tcx> {
|
|||
fn check_track_caller(
|
||||
&self,
|
||||
attr_span: &Span,
|
||||
attrs: &HirVec<Attribute>,
|
||||
attrs: &'hir [Attribute],
|
||||
span: &Span,
|
||||
target: Target,
|
||||
) -> bool {
|
||||
|
@ -332,7 +332,7 @@ impl CheckAttrVisitor<'tcx> {
|
|||
/// Checks if the `#[repr]` attributes on `item` are valid.
|
||||
fn check_repr(
|
||||
&self,
|
||||
attrs: &HirVec<Attribute>,
|
||||
attrs: &'hir [Attribute],
|
||||
span: &Span,
|
||||
target: Target,
|
||||
item: Option<&Item<'_>>,
|
||||
|
@ -477,7 +477,7 @@ impl CheckAttrVisitor<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_used(&self, attrs: &HirVec<Attribute>, target: Target) {
|
||||
fn check_used(&self, attrs: &'hir [Attribute], target: Target) {
|
||||
for attr in attrs {
|
||||
if attr.check_name(sym::used) && target != Target::Static {
|
||||
self.tcx.sess
|
||||
|
@ -494,7 +494,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||
|
||||
fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
|
||||
let target = Target::from_item(item);
|
||||
self.check_attributes(item.hir_id, &item.attrs, &item.span, target, Some(item));
|
||||
self.check_attributes(item.hir_id, item.attrs, &item.span, target, Some(item));
|
||||
intravisit::walk_item(self, item)
|
||||
}
|
||||
|
||||
|
|
|
@ -367,7 +367,7 @@ pub trait Visitor<'v>: Sized {
|
|||
}
|
||||
fn visit_attribute(&mut self, _attr: &'v Attribute) {
|
||||
}
|
||||
fn visit_macro_def(&mut self, macro_def: &'v MacroDef) {
|
||||
fn visit_macro_def(&mut self, macro_def: &'v MacroDef<'v>) {
|
||||
walk_macro_def(self, macro_def)
|
||||
}
|
||||
fn visit_vis(&mut self, vis: &'v Visibility) {
|
||||
|
@ -388,10 +388,10 @@ pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate<'v>) {
|
|||
walk_list!(visitor, visit_macro_def, krate.exported_macros);
|
||||
}
|
||||
|
||||
pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef) {
|
||||
pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef<'v>) {
|
||||
visitor.visit_id(macro_def.hir_id);
|
||||
visitor.visit_name(macro_def.span, macro_def.name);
|
||||
walk_list!(visitor, visit_attribute, ¯o_def.attrs);
|
||||
walk_list!(visitor, visit_attribute, macro_def.attrs);
|
||||
}
|
||||
|
||||
pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod, mod_hir_id: HirId) {
|
||||
|
@ -554,7 +554,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
|
|||
walk_list!(visitor, visit_param_bound, bounds);
|
||||
}
|
||||
}
|
||||
walk_list!(visitor, visit_attribute, &item.attrs);
|
||||
walk_list!(visitor, visit_attribute, item.attrs);
|
||||
}
|
||||
|
||||
pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||
|
|
|
@ -100,7 +100,7 @@ pub struct LoweringContext<'a, 'hir: 'a> {
|
|||
trait_items: BTreeMap<hir::TraitItemId, hir::TraitItem>,
|
||||
impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem>,
|
||||
bodies: BTreeMap<hir::BodyId, hir::Body>,
|
||||
exported_macros: Vec<hir::MacroDef>,
|
||||
exported_macros: Vec<hir::MacroDef<'hir>>,
|
||||
non_exported_macro_attrs: Vec<ast::Attribute>,
|
||||
|
||||
trait_impls: BTreeMap<DefId, Vec<hir::HirId>>,
|
||||
|
@ -989,15 +989,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
fn lower_attrs_extendable(&mut self, attrs: &[Attribute]) -> Vec<Attribute> {
|
||||
attrs
|
||||
.iter()
|
||||
.map(|a| self.lower_attr(a))
|
||||
.collect()
|
||||
fn lower_attrs_arena(&mut self, attrs: &[Attribute]) -> &'hir [Attribute] {
|
||||
self.arena.alloc_from_iter(
|
||||
attrs.iter().map(|a| self.lower_attr(a))
|
||||
)
|
||||
}
|
||||
|
||||
fn lower_attrs(&mut self, attrs: &[Attribute]) -> hir::HirVec<Attribute> {
|
||||
self.lower_attrs_extendable(attrs).into()
|
||||
attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into()
|
||||
}
|
||||
|
||||
fn lower_attr(&mut self, attr: &Attribute) -> Attribute {
|
||||
|
|
|
@ -228,7 +228,7 @@ impl LoweringContext<'_, 'hir> {
|
|||
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item<'hir>> {
|
||||
let mut ident = i.ident;
|
||||
let mut vis = self.lower_visibility(&i.vis, None);
|
||||
let attrs = self.lower_attrs(&i.attrs);
|
||||
let attrs = self.lower_attrs_arena(&i.attrs);
|
||||
|
||||
if let ItemKind::MacroDef(ref def) = i.kind {
|
||||
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {
|
||||
|
@ -244,12 +244,12 @@ impl LoweringContext<'_, 'hir> {
|
|||
legacy: def.legacy,
|
||||
});
|
||||
} else {
|
||||
self.non_exported_macro_attrs.extend(attrs.into_iter());
|
||||
self.non_exported_macro_attrs.extend(attrs.iter().cloned());
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
let kind = self.lower_item_kind(i.span, i.id, &mut ident, &attrs, &mut vis, &i.kind);
|
||||
let kind = self.lower_item_kind(i.span, i.id, &mut ident, attrs, &mut vis, &i.kind);
|
||||
|
||||
Some(hir::Item {
|
||||
hir_id: self.lower_node_id(i.id),
|
||||
|
@ -266,7 +266,7 @@ impl LoweringContext<'_, 'hir> {
|
|||
span: Span,
|
||||
id: NodeId,
|
||||
ident: &mut Ident,
|
||||
attrs: &hir::HirVec<Attribute>,
|
||||
attrs: &'hir [Attribute],
|
||||
vis: &mut hir::Visibility,
|
||||
i: &ItemKind,
|
||||
) -> hir::ItemKind<'hir> {
|
||||
|
@ -487,7 +487,7 @@ impl LoweringContext<'_, 'hir> {
|
|||
id: NodeId,
|
||||
vis: &mut hir::Visibility,
|
||||
ident: &mut Ident,
|
||||
attrs: &hir::HirVec<Attribute>,
|
||||
attrs: &'hir [Attribute],
|
||||
) -> hir::ItemKind<'hir> {
|
||||
debug!("lower_use_tree(tree={:?})", tree);
|
||||
debug!("lower_use_tree: vis = {:?}", vis);
|
||||
|
@ -550,7 +550,7 @@ impl LoweringContext<'_, 'hir> {
|
|||
hir::Item {
|
||||
hir_id: new_id,
|
||||
ident,
|
||||
attrs: attrs.into_iter().cloned().collect(),
|
||||
attrs,
|
||||
kind,
|
||||
vis,
|
||||
span,
|
||||
|
@ -634,7 +634,7 @@ impl LoweringContext<'_, 'hir> {
|
|||
hir::Item {
|
||||
hir_id: new_hir_id,
|
||||
ident,
|
||||
attrs: attrs.into_iter().cloned().collect(),
|
||||
attrs,
|
||||
kind,
|
||||
vis,
|
||||
span: use_tree.span,
|
||||
|
|
|
@ -530,7 +530,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||
}
|
||||
}
|
||||
|
||||
fn visit_macro_def(&mut self, macro_def: &'hir MacroDef) {
|
||||
fn visit_macro_def(&mut self, macro_def: &'hir MacroDef<'hir>) {
|
||||
let node_id = self.hir_to_node_id[¯o_def.hir_id];
|
||||
let def_index = self.definitions.opt_def_index(node_id).unwrap();
|
||||
|
||||
|
|
|
@ -746,7 +746,7 @@ pub struct Crate<'hir> {
|
|||
pub module: Mod,
|
||||
pub attrs: &'hir [Attribute],
|
||||
pub span: Span,
|
||||
pub exported_macros: &'hir [MacroDef],
|
||||
pub exported_macros: &'hir [MacroDef<'hir>],
|
||||
// Attributes from non-exported macros, kept only for collecting the library feature list.
|
||||
pub non_exported_macro_attrs: &'hir [Attribute],
|
||||
|
||||
|
@ -841,10 +841,10 @@ impl Crate<'_> {
|
|||
///
|
||||
/// Not parsed directly, but created on macro import or `macro_rules!` expansion.
|
||||
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
|
||||
pub struct MacroDef {
|
||||
pub struct MacroDef<'hir> {
|
||||
pub name: Name,
|
||||
pub vis: Visibility,
|
||||
pub attrs: HirVec<Attribute>,
|
||||
pub attrs: &'hir [Attribute],
|
||||
pub hir_id: HirId,
|
||||
pub span: Span,
|
||||
pub body: TokenStream,
|
||||
|
@ -2445,7 +2445,7 @@ pub struct ItemId {
|
|||
pub struct Item<'hir> {
|
||||
pub ident: Ident,
|
||||
pub hir_id: HirId,
|
||||
pub attrs: HirVec<Attribute>,
|
||||
pub attrs: &'hir [Attribute],
|
||||
pub kind: ItemKind<'hir>,
|
||||
pub vis: Visibility,
|
||||
pub span: Span,
|
||||
|
@ -2804,7 +2804,7 @@ pub enum Node<'hir> {
|
|||
Arm(&'hir Arm),
|
||||
Block(&'hir Block),
|
||||
Local(&'hir Local),
|
||||
MacroDef(&'hir MacroDef),
|
||||
MacroDef(&'hir MacroDef<'hir>),
|
||||
|
||||
/// `Ctor` refers to the constructor of an enum variant or struct. Only tuple or unit variants
|
||||
/// with synthesized constructors.
|
||||
|
|
|
@ -324,7 +324,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||
});
|
||||
}
|
||||
|
||||
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) {
|
||||
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
|
||||
self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, |_| {});
|
||||
}
|
||||
}
|
||||
|
@ -397,7 +397,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
|
|||
intravisit::walk_foreign_item(self, i);
|
||||
}
|
||||
|
||||
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) {
|
||||
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
|
||||
self.check_missing_stability(md.hir_id, md.span, "macro");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -232,7 +232,7 @@ impl CodegenCx<'ll, 'tcx> {
|
|||
let llty = self.layout_of(ty).llvm_type(self);
|
||||
let (g, attrs) = match self.tcx.hir().get(id) {
|
||||
Node::Item(&hir::Item {
|
||||
ref attrs, span, kind: hir::ItemKind::Static(..), ..
|
||||
attrs, span, kind: hir::ItemKind::Static(..), ..
|
||||
}) => {
|
||||
let sym_str = sym.as_str();
|
||||
if let Some(g) = self.get_declared_value(&sym_str) {
|
||||
|
@ -256,7 +256,7 @@ impl CodegenCx<'ll, 'tcx> {
|
|||
ref attrs, span, kind: hir::ForeignItemKind::Static(..), ..
|
||||
}) => {
|
||||
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
|
||||
(check_and_apply_linkage(&self, &fn_attrs, ty, sym, span), attrs)
|
||||
(check_and_apply_linkage(&self, &fn_attrs, ty, sym, span), &**attrs)
|
||||
}
|
||||
|
||||
item => bug!("get_static: expected static, found {:?}", item)
|
||||
|
|
|
@ -1160,7 +1160,7 @@ impl EncodeContext<'tcx> {
|
|||
record!(self.per_def.visibility[def_id] <-
|
||||
ty::Visibility::from_hir(&item.vis, item.hir_id, tcx));
|
||||
record!(self.per_def.span[def_id] <- item.span);
|
||||
record!(self.per_def.attributes[def_id] <- &item.attrs);
|
||||
record!(self.per_def.attributes[def_id] <- item.attrs);
|
||||
// FIXME(eddyb) there should be a nicer way to do this.
|
||||
match item.kind {
|
||||
hir::ItemKind::ForeignMod(ref fm) => record!(self.per_def.children[def_id] <-
|
||||
|
@ -1271,7 +1271,7 @@ impl EncodeContext<'tcx> {
|
|||
}
|
||||
|
||||
/// Serialize the text of exported macros
|
||||
fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef) {
|
||||
fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) {
|
||||
use syntax::print::pprust;
|
||||
let def_id = self.tcx.hir().local_def_id(macro_def.hir_id);
|
||||
record!(self.per_def.kind[def_id] <- EntryKind::MacroDef(self.lazy(MacroDef {
|
||||
|
@ -1280,7 +1280,7 @@ impl EncodeContext<'tcx> {
|
|||
})));
|
||||
record!(self.per_def.visibility[def_id] <- ty::Visibility::Public);
|
||||
record!(self.per_def.span[def_id] <- macro_def.span);
|
||||
record!(self.per_def.attributes[def_id] <- ¯o_def.attrs);
|
||||
record!(self.per_def.attributes[def_id] <- macro_def.attrs);
|
||||
self.encode_stability(def_id);
|
||||
self.encode_deprecation(def_id);
|
||||
}
|
||||
|
@ -1599,7 +1599,7 @@ impl Visitor<'tcx> for EncodeContext<'tcx> {
|
|||
intravisit::walk_generics(self, generics);
|
||||
self.encode_info_for_generics(generics);
|
||||
}
|
||||
fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef) {
|
||||
fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) {
|
||||
self.encode_info_for_macro_def(macro_def);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> {
|
|||
self.record("Attribute", Id::Attr(attr.id), attr);
|
||||
}
|
||||
|
||||
fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef) {
|
||||
fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef<'v>) {
|
||||
self.record("MacroDef", Id::Node(macro_def.hir_id), macro_def);
|
||||
hir_visit::walk_macro_def(self, macro_def)
|
||||
}
|
||||
|
|
|
@ -870,7 +870,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
|||
intravisit::walk_mod(self, m, id);
|
||||
}
|
||||
|
||||
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) {
|
||||
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
|
||||
if attr::find_transparency(&md.attrs, md.legacy).0 != Transparency::Opaque {
|
||||
self.update(md.hir_id, Some(AccessLevel::Public));
|
||||
return
|
||||
|
|
|
@ -1127,7 +1127,7 @@ impl hir::intravisit::Visitor<'tcx> for UsePlacementFinder<'tcx> {
|
|||
self.span = Some(item.span.shrink_to_lo());
|
||||
} else {
|
||||
// Find the first attribute on the item.
|
||||
for attr in &item.attrs {
|
||||
for attr in item.attrs {
|
||||
if self.span.map_or(true, |span| attr.span < span) {
|
||||
self.span = Some(attr.span.shrink_to_lo());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue