Skip to content

Commit abbe625

Browse files
committed
Handle Attributes in arena.
1 parent 084e672 commit abbe625

File tree

13 files changed

+41
-42
lines changed

13 files changed

+41
-42
lines changed

src/librustc/arena.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ macro_rules! arena_types {
127127
[] attribute: syntax::ast::Attribute,
128128
[] global_asm: rustc::hir::GlobalAsm,
129129
[] impl_item_ref: rustc::hir::ImplItemRef,
130-
[] macro_def: rustc::hir::MacroDef,
130+
[] macro_def: rustc::hir::MacroDef<$tcx>,
131131
[] path: rustc::hir::Path,
132132
[] trait_item_ref: rustc::hir::TraitItemRef,
133133
[] ty: rustc::hir::Ty,

src/librustc/hir/check_attr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! conflicts between multiple such attributes attached to the same
55
//! item.
66
7-
use crate::hir::{self, HirId, HirVec, Attribute, Item, ItemKind, TraitItem, TraitItemKind};
7+
use crate::hir::{self, HirId, Attribute, Item, ItemKind, TraitItem, TraitItemKind};
88
use crate::hir::DUMMY_HIR_ID;
99
use crate::hir::def_id::DefId;
1010
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
@@ -158,7 +158,7 @@ impl CheckAttrVisitor<'tcx> {
158158
fn check_attributes(
159159
&self,
160160
hir_id: HirId,
161-
attrs: &HirVec<Attribute>,
161+
attrs: &'hir [Attribute],
162162
span: &Span,
163163
target: Target,
164164
item: Option<&Item<'_>>,
@@ -241,7 +241,7 @@ impl CheckAttrVisitor<'tcx> {
241241
fn check_track_caller(
242242
&self,
243243
attr_span: &Span,
244-
attrs: &HirVec<Attribute>,
244+
attrs: &'hir [Attribute],
245245
span: &Span,
246246
target: Target,
247247
) -> bool {
@@ -332,7 +332,7 @@ impl CheckAttrVisitor<'tcx> {
332332
/// Checks if the `#[repr]` attributes on `item` are valid.
333333
fn check_repr(
334334
&self,
335-
attrs: &HirVec<Attribute>,
335+
attrs: &'hir [Attribute],
336336
span: &Span,
337337
target: Target,
338338
item: Option<&Item<'_>>,
@@ -477,7 +477,7 @@ impl CheckAttrVisitor<'tcx> {
477477
}
478478
}
479479

480-
fn check_used(&self, attrs: &HirVec<Attribute>, target: Target) {
480+
fn check_used(&self, attrs: &'hir [Attribute], target: Target) {
481481
for attr in attrs {
482482
if attr.check_name(sym::used) && target != Target::Static {
483483
self.tcx.sess
@@ -494,7 +494,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
494494

495495
fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
496496
let target = Target::from_item(item);
497-
self.check_attributes(item.hir_id, &item.attrs, &item.span, target, Some(item));
497+
self.check_attributes(item.hir_id, item.attrs, &item.span, target, Some(item));
498498
intravisit::walk_item(self, item)
499499
}
500500

src/librustc/hir/intravisit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ pub trait Visitor<'v>: Sized {
367367
}
368368
fn visit_attribute(&mut self, _attr: &'v Attribute) {
369369
}
370-
fn visit_macro_def(&mut self, macro_def: &'v MacroDef) {
370+
fn visit_macro_def(&mut self, macro_def: &'v MacroDef<'v>) {
371371
walk_macro_def(self, macro_def)
372372
}
373373
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>) {
388388
walk_list!(visitor, visit_macro_def, krate.exported_macros);
389389
}
390390

391-
pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef) {
391+
pub fn walk_macro_def<'v, V: Visitor<'v>>(visitor: &mut V, macro_def: &'v MacroDef<'v>) {
392392
visitor.visit_id(macro_def.hir_id);
393393
visitor.visit_name(macro_def.span, macro_def.name);
394-
walk_list!(visitor, visit_attribute, &macro_def.attrs);
394+
walk_list!(visitor, visit_attribute, macro_def.attrs);
395395
}
396396

397397
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>) {
554554
walk_list!(visitor, visit_param_bound, bounds);
555555
}
556556
}
557-
walk_list!(visitor, visit_attribute, &item.attrs);
557+
walk_list!(visitor, visit_attribute, item.attrs);
558558
}
559559

560560
pub fn walk_use<'v, V: Visitor<'v>>(visitor: &mut V,

src/librustc/hir/lowering.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub struct LoweringContext<'a, 'hir: 'a> {
100100
trait_items: BTreeMap<hir::TraitItemId, hir::TraitItem>,
101101
impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem>,
102102
bodies: BTreeMap<hir::BodyId, hir::Body>,
103-
exported_macros: Vec<hir::MacroDef>,
103+
exported_macros: Vec<hir::MacroDef<'hir>>,
104104
non_exported_macro_attrs: Vec<ast::Attribute>,
105105

106106
trait_impls: BTreeMap<DefId, Vec<hir::HirId>>,
@@ -989,15 +989,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
989989
}
990990
}
991991

992-
fn lower_attrs_extendable(&mut self, attrs: &[Attribute]) -> Vec<Attribute> {
993-
attrs
994-
.iter()
995-
.map(|a| self.lower_attr(a))
996-
.collect()
992+
fn lower_attrs_arena(&mut self, attrs: &[Attribute]) -> &'hir [Attribute] {
993+
self.arena.alloc_from_iter(
994+
attrs.iter().map(|a| self.lower_attr(a))
995+
)
997996
}
998997

999998
fn lower_attrs(&mut self, attrs: &[Attribute]) -> hir::HirVec<Attribute> {
1000-
self.lower_attrs_extendable(attrs).into()
999+
attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into()
10011000
}
10021001

10031002
fn lower_attr(&mut self, attr: &Attribute) -> Attribute {

src/librustc/hir/lowering/item.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ impl LoweringContext<'_, 'hir> {
228228
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item<'hir>> {
229229
let mut ident = i.ident;
230230
let mut vis = self.lower_visibility(&i.vis, None);
231-
let attrs = self.lower_attrs(&i.attrs);
231+
let attrs = self.lower_attrs_arena(&i.attrs);
232232

233233
if let ItemKind::MacroDef(ref def) = i.kind {
234234
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {
@@ -244,12 +244,12 @@ impl LoweringContext<'_, 'hir> {
244244
legacy: def.legacy,
245245
});
246246
} else {
247-
self.non_exported_macro_attrs.extend(attrs.into_iter());
247+
self.non_exported_macro_attrs.extend(attrs.iter().cloned());
248248
}
249249
return None;
250250
}
251251

252-
let kind = self.lower_item_kind(i.span, i.id, &mut ident, &attrs, &mut vis, &i.kind);
252+
let kind = self.lower_item_kind(i.span, i.id, &mut ident, attrs, &mut vis, &i.kind);
253253

254254
Some(hir::Item {
255255
hir_id: self.lower_node_id(i.id),
@@ -266,7 +266,7 @@ impl LoweringContext<'_, 'hir> {
266266
span: Span,
267267
id: NodeId,
268268
ident: &mut Ident,
269-
attrs: &hir::HirVec<Attribute>,
269+
attrs: &'hir [Attribute],
270270
vis: &mut hir::Visibility,
271271
i: &ItemKind,
272272
) -> hir::ItemKind<'hir> {
@@ -487,7 +487,7 @@ impl LoweringContext<'_, 'hir> {
487487
id: NodeId,
488488
vis: &mut hir::Visibility,
489489
ident: &mut Ident,
490-
attrs: &hir::HirVec<Attribute>,
490+
attrs: &'hir [Attribute],
491491
) -> hir::ItemKind<'hir> {
492492
debug!("lower_use_tree(tree={:?})", tree);
493493
debug!("lower_use_tree: vis = {:?}", vis);
@@ -550,7 +550,7 @@ impl LoweringContext<'_, 'hir> {
550550
hir::Item {
551551
hir_id: new_id,
552552
ident,
553-
attrs: attrs.into_iter().cloned().collect(),
553+
attrs,
554554
kind,
555555
vis,
556556
span,
@@ -634,7 +634,7 @@ impl LoweringContext<'_, 'hir> {
634634
hir::Item {
635635
hir_id: new_hir_id,
636636
ident,
637-
attrs: attrs.into_iter().cloned().collect(),
637+
attrs,
638638
kind,
639639
vis,
640640
span: use_tree.span,

src/librustc/hir/map/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
530530
}
531531
}
532532

533-
fn visit_macro_def(&mut self, macro_def: &'hir MacroDef) {
533+
fn visit_macro_def(&mut self, macro_def: &'hir MacroDef<'hir>) {
534534
let node_id = self.hir_to_node_id[&macro_def.hir_id];
535535
let def_index = self.definitions.opt_def_index(node_id).unwrap();
536536

src/librustc/hir/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ pub struct Crate<'hir> {
746746
pub module: Mod,
747747
pub attrs: &'hir [Attribute],
748748
pub span: Span,
749-
pub exported_macros: &'hir [MacroDef],
749+
pub exported_macros: &'hir [MacroDef<'hir>],
750750
// Attributes from non-exported macros, kept only for collecting the library feature list.
751751
pub non_exported_macro_attrs: &'hir [Attribute],
752752

@@ -841,10 +841,10 @@ impl Crate<'_> {
841841
///
842842
/// Not parsed directly, but created on macro import or `macro_rules!` expansion.
843843
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
844-
pub struct MacroDef {
844+
pub struct MacroDef<'hir> {
845845
pub name: Name,
846846
pub vis: Visibility,
847-
pub attrs: HirVec<Attribute>,
847+
pub attrs: &'hir [Attribute],
848848
pub hir_id: HirId,
849849
pub span: Span,
850850
pub body: TokenStream,
@@ -2445,7 +2445,7 @@ pub struct ItemId {
24452445
pub struct Item<'hir> {
24462446
pub ident: Ident,
24472447
pub hir_id: HirId,
2448-
pub attrs: HirVec<Attribute>,
2448+
pub attrs: &'hir [Attribute],
24492449
pub kind: ItemKind<'hir>,
24502450
pub vis: Visibility,
24512451
pub span: Span,
@@ -2804,7 +2804,7 @@ pub enum Node<'hir> {
28042804
Arm(&'hir Arm),
28052805
Block(&'hir Block),
28062806
Local(&'hir Local),
2807-
MacroDef(&'hir MacroDef),
2807+
MacroDef(&'hir MacroDef<'hir>),
28082808

28092809
/// `Ctor` refers to the constructor of an enum variant or struct. Only tuple or unit variants
28102810
/// with synthesized constructors.

src/librustc/middle/stability.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
324324
});
325325
}
326326

327-
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) {
327+
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
328328
self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, |_| {});
329329
}
330330
}
@@ -397,7 +397,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
397397
intravisit::walk_foreign_item(self, i);
398398
}
399399

400-
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) {
400+
fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
401401
self.check_missing_stability(md.hir_id, md.span, "macro");
402402
}
403403
}

src/librustc_codegen_llvm/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl CodegenCx<'ll, 'tcx> {
232232
let llty = self.layout_of(ty).llvm_type(self);
233233
let (g, attrs) = match self.tcx.hir().get(id) {
234234
Node::Item(&hir::Item {
235-
ref attrs, span, kind: hir::ItemKind::Static(..), ..
235+
attrs, span, kind: hir::ItemKind::Static(..), ..
236236
}) => {
237237
let sym_str = sym.as_str();
238238
if let Some(g) = self.get_declared_value(&sym_str) {
@@ -256,7 +256,7 @@ impl CodegenCx<'ll, 'tcx> {
256256
ref attrs, span, kind: hir::ForeignItemKind::Static(..), ..
257257
}) => {
258258
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
259-
(check_and_apply_linkage(&self, &fn_attrs, ty, sym, span), attrs)
259+
(check_and_apply_linkage(&self, &fn_attrs, ty, sym, span), &**attrs)
260260
}
261261

262262
item => bug!("get_static: expected static, found {:?}", item)

src/librustc_metadata/rmeta/encoder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ impl EncodeContext<'tcx> {
11601160
record!(self.per_def.visibility[def_id] <-
11611161
ty::Visibility::from_hir(&item.vis, item.hir_id, tcx));
11621162
record!(self.per_def.span[def_id] <- item.span);
1163-
record!(self.per_def.attributes[def_id] <- &item.attrs);
1163+
record!(self.per_def.attributes[def_id] <- item.attrs);
11641164
// FIXME(eddyb) there should be a nicer way to do this.
11651165
match item.kind {
11661166
hir::ItemKind::ForeignMod(ref fm) => record!(self.per_def.children[def_id] <-
@@ -1271,7 +1271,7 @@ impl EncodeContext<'tcx> {
12711271
}
12721272

12731273
/// Serialize the text of exported macros
1274-
fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef) {
1274+
fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef<'_>) {
12751275
use syntax::print::pprust;
12761276
let def_id = self.tcx.hir().local_def_id(macro_def.hir_id);
12771277
record!(self.per_def.kind[def_id] <- EntryKind::MacroDef(self.lazy(MacroDef {
@@ -1280,7 +1280,7 @@ impl EncodeContext<'tcx> {
12801280
})));
12811281
record!(self.per_def.visibility[def_id] <- ty::Visibility::Public);
12821282
record!(self.per_def.span[def_id] <- macro_def.span);
1283-
record!(self.per_def.attributes[def_id] <- &macro_def.attrs);
1283+
record!(self.per_def.attributes[def_id] <- macro_def.attrs);
12841284
self.encode_stability(def_id);
12851285
self.encode_deprecation(def_id);
12861286
}
@@ -1599,7 +1599,7 @@ impl Visitor<'tcx> for EncodeContext<'tcx> {
15991599
intravisit::walk_generics(self, generics);
16001600
self.encode_info_for_generics(generics);
16011601
}
1602-
fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef) {
1602+
fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef<'tcx>) {
16031603
self.encode_info_for_macro_def(macro_def);
16041604
}
16051605
}

0 commit comments

Comments
 (0)