Skip to content

Commit acf33f2

Browse files
committed
Use Arena inside hir::ForeignItem.
1 parent abbe625 commit acf33f2

File tree

26 files changed

+72
-63
lines changed

26 files changed

+72
-63
lines changed

src/librustc/arena.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ macro_rules! arena_types {
126126
[few] hir_forest: rustc::hir::map::Forest<$tcx>,
127127
[] attribute: syntax::ast::Attribute,
128128
[] global_asm: rustc::hir::GlobalAsm,
129+
[] fn_decl: rustc::hir::FnDecl,
130+
[] foreign_item: rustc::hir::ForeignItem<$tcx>,
129131
[] impl_item_ref: rustc::hir::ImplItemRef,
130132
[] macro_def: rustc::hir::MacroDef<$tcx>,
131133
[] path: rustc::hir::Path,

src/librustc/hir/check_attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl Target {
120120
}
121121
}
122122

123-
fn from_foreign_item(foreign_item: &hir::ForeignItem) -> Target {
123+
fn from_foreign_item(foreign_item: &hir::ForeignItem<'_>) -> Target {
124124
match foreign_item.kind {
125125
hir::ForeignItemKind::Fn(..) => Target::ForeignFn,
126126
hir::ForeignItemKind::Static(..) => Target::ForeignStatic,
@@ -504,7 +504,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
504504
intravisit::walk_trait_item(self, trait_item)
505505
}
506506

507-
fn visit_foreign_item(&mut self, f_item: &'tcx hir::ForeignItem) {
507+
fn visit_foreign_item(&mut self, f_item: &'tcx hir::ForeignItem<'tcx>) {
508508
let target = Target::from_foreign_item(f_item);
509509
self.check_attributes(f_item.hir_id, &f_item.attrs, &f_item.span, target, None);
510510
intravisit::walk_foreign_item(self, f_item)

src/librustc/hir/intravisit.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pub trait Visitor<'v>: Sized {
250250
fn visit_mod(&mut self, m: &'v Mod, _s: Span, n: HirId) {
251251
walk_mod(self, m, n)
252252
}
253-
fn visit_foreign_item(&mut self, i: &'v ForeignItem) {
253+
fn visit_foreign_item(&mut self, i: &'v ForeignItem<'v>) {
254254
walk_foreign_item(self, i)
255255
}
256256
fn visit_local(&mut self, l: &'v Local) {
@@ -498,7 +498,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
498498
}
499499
ItemKind::ForeignMod(ref foreign_module) => {
500500
visitor.visit_id(item.hir_id);
501-
walk_list!(visitor, visit_foreign_item, &foreign_module.items);
501+
walk_list!(visitor, visit_foreign_item, foreign_module.items);
502502
}
503503
ItemKind::GlobalAsm(_) => {
504504
visitor.visit_id(item.hir_id);
@@ -735,13 +735,13 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) {
735735
}
736736
}
737737

738-
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem) {
738+
pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v ForeignItem<'v>) {
739739
visitor.visit_id(foreign_item.hir_id);
740740
visitor.visit_vis(&foreign_item.vis);
741741
visitor.visit_ident(foreign_item.ident);
742742

743743
match foreign_item.kind {
744-
ForeignItemKind::Fn(ref function_declaration, ref param_names, ref generics) => {
744+
ForeignItemKind::Fn(ref function_declaration, param_names, ref generics) => {
745745
visitor.visit_generics(generics);
746746
visitor.visit_fn_decl(function_declaration);
747747
for &param_name in param_names {
@@ -752,7 +752,7 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v
752752
ForeignItemKind::Type => (),
753753
}
754754

755-
walk_list!(visitor, visit_attribute, &foreign_item.attrs);
755+
walk_list!(visitor, visit_attribute, foreign_item.attrs);
756756
}
757757

758758
pub fn walk_param_bound<'v, V: Visitor<'v>>(visitor: &mut V, bound: &'v GenericBound) {

src/librustc/hir/lowering/item.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -706,12 +706,12 @@ impl LoweringContext<'_, 'hir> {
706706
respan(vis.span, vis_kind)
707707
}
708708

709-
fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem {
709+
fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'hir> {
710710
let def_id = self.resolver.definitions().local_def_id(i.id);
711711
hir::ForeignItem {
712712
hir_id: self.lower_node_id(i.id),
713713
ident: i.ident,
714-
attrs: self.lower_attrs(&i.attrs),
714+
attrs: self.lower_attrs_arena(&i.attrs),
715715
kind: match i.kind {
716716
ForeignItemKind::Fn(ref fdec, ref generics) => {
717717
let (generics, (fn_dec, fn_args)) = self.add_in_band_defs(
@@ -726,12 +726,14 @@ impl LoweringContext<'_, 'hir> {
726726
)
727727
},
728728
);
729+
let fn_dec = self.arena.alloc(fn_dec.into_inner());
730+
let fn_args = self.arena.alloc_from_iter(fn_args.into_iter());
729731

730732
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
731733
}
732734
ForeignItemKind::Static(ref t, m) => {
733735
hir::ForeignItemKind::Static(
734-
self.lower_ty(t, ImplTraitContext::disallowed()), m)
736+
self.arena.alloc(self.lower_ty(t, ImplTraitContext::disallowed()).into_inner()), m)
735737
}
736738
ForeignItemKind::Ty => hir::ForeignItemKind::Type,
737739
ForeignItemKind::Macro(_) => panic!("macro shouldn't exist here"),
@@ -741,13 +743,12 @@ impl LoweringContext<'_, 'hir> {
741743
}
742744
}
743745

744-
fn lower_foreign_mod(&mut self, fm: &ForeignMod) -> hir::ForeignMod {
746+
fn lower_foreign_mod(&mut self, fm: &ForeignMod) -> hir::ForeignMod<'hir> {
745747
hir::ForeignMod {
746748
abi: fm.abi.map_or(abi::Abi::C, |abi| self.lower_abi(abi)),
747-
items: fm.items
749+
items: self.arena.alloc_from_iter(fm.items
748750
.iter()
749-
.map(|x| self.lower_foreign_item(x))
750-
.collect(),
751+
.map(|x| self.lower_foreign_item(x))),
751752
}
752753
}
753754

src/librustc/hir/map/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
385385
});
386386
}
387387

388-
fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem) {
388+
fn visit_foreign_item(&mut self, foreign_item: &'hir ForeignItem<'hir>) {
389389
self.insert(foreign_item.span, foreign_item.hir_id, Node::ForeignItem(foreign_item));
390390

391391
self.with_parent(foreign_item.hir_id, |this| {

src/librustc/hir/map/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ impl<'hir> Map<'hir> {
10021002
}
10031003
}
10041004

1005-
pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem {
1005+
pub fn expect_foreign_item(&self, id: HirId) -> &'hir ForeignItem<'hir> {
10061006
match self.find(id) {
10071007
Some(Node::ForeignItem(item)) => item,
10081008
_ => bug!("expected foreign item, found {}", self.node_to_string(id))
@@ -1249,7 +1249,7 @@ trait Named {
12491249
impl<T:Named> Named for Spanned<T> { fn name(&self) -> Name { self.node.name() } }
12501250

12511251
impl Named for Item<'_> { fn name(&self) -> Name { self.ident.name } }
1252-
impl Named for ForeignItem { fn name(&self) -> Name { self.ident.name } }
1252+
impl Named for ForeignItem<'_> { fn name(&self) -> Name { self.ident.name } }
12531253
impl Named for Variant { fn name(&self) -> Name { self.ident.name } }
12541254
impl Named for StructField { fn name(&self) -> Name { self.ident.name } }
12551255
impl Named for TraitItem { fn name(&self) -> Name { self.ident.name } }

src/librustc/hir/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,9 +2252,9 @@ pub struct Mod {
22522252
}
22532253

22542254
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
2255-
pub struct ForeignMod {
2255+
pub struct ForeignMod<'hir> {
22562256
pub abi: Abi,
2257-
pub items: HirVec<ForeignItem>,
2257+
pub items: &'hir [ForeignItem<'hir>],
22582258
}
22592259

22602260
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
@@ -2491,7 +2491,7 @@ pub enum ItemKind<'hir> {
24912491
/// A module.
24922492
Mod(Mod),
24932493
/// An external module, e.g. `extern { .. }`.
2494-
ForeignMod(ForeignMod),
2494+
ForeignMod(ForeignMod<'hir>),
24952495
/// Module-level inline assembly (from `global_asm!`).
24962496
GlobalAsm(&'hir GlobalAsm),
24972497
/// A type alias, e.g., `type Foo = Bar<u8>`.
@@ -2607,28 +2607,28 @@ pub enum AssocItemKind {
26072607
}
26082608

26092609
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
2610-
pub struct ForeignItem {
2610+
pub struct ForeignItem<'hir> {
26112611
#[stable_hasher(project(name))]
26122612
pub ident: Ident,
2613-
pub attrs: HirVec<Attribute>,
2614-
pub kind: ForeignItemKind,
2613+
pub attrs: &'hir [Attribute],
2614+
pub kind: ForeignItemKind<'hir>,
26152615
pub hir_id: HirId,
26162616
pub span: Span,
26172617
pub vis: Visibility,
26182618
}
26192619

26202620
/// An item within an `extern` block.
26212621
#[derive(RustcEncodable, RustcDecodable, Debug, HashStable)]
2622-
pub enum ForeignItemKind {
2622+
pub enum ForeignItemKind<'hir> {
26232623
/// A foreign function.
2624-
Fn(P<FnDecl>, HirVec<Ident>, Generics),
2624+
Fn(&'hir FnDecl, &'hir [Ident], Generics),
26252625
/// A foreign static item (`static ext: u8`).
2626-
Static(P<Ty>, Mutability),
2626+
Static(&'hir Ty, Mutability),
26272627
/// A foreign type.
26282628
Type,
26292629
}
26302630

2631-
impl ForeignItemKind {
2631+
impl ForeignItemKind<'hir> {
26322632
pub fn descriptive_variant(&self) -> &str {
26332633
match *self {
26342634
ForeignItemKind::Fn(..) => "foreign function",
@@ -2788,7 +2788,7 @@ impl CodegenFnAttrs {
27882788
pub enum Node<'hir> {
27892789
Param(&'hir Param),
27902790
Item(&'hir Item<'hir>),
2791-
ForeignItem(&'hir ForeignItem),
2791+
ForeignItem(&'hir ForeignItem<'hir>),
27922792
TraitItem(&'hir TraitItem),
27932793
ImplItem(&'hir ImplItem),
27942794
Variant(&'hir Variant),

src/librustc/hir/print.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ impl<'a> State<'a> {
267267
}
268268

269269
pub fn print_foreign_mod(&mut self,
270-
nmod: &hir::ForeignMod,
270+
nmod: &hir::ForeignMod<'_>,
271271
attrs: &[ast::Attribute])
272272
{
273273
self.print_inner_attributes(attrs);
274-
for item in &nmod.items {
274+
for item in nmod.items {
275275
self.print_foreign_item(item);
276276
}
277277
}
@@ -361,7 +361,7 @@ impl<'a> State<'a> {
361361
self.end()
362362
}
363363

364-
pub fn print_foreign_item(&mut self, item: &hir::ForeignItem) {
364+
pub fn print_foreign_item(&mut self, item: &hir::ForeignItem<'_>) {
365365
self.hardbreak_if_not_bol();
366366
self.maybe_print_comment(item.span.lo());
367367
self.print_outer_attributes(&item.attrs);

src/librustc/lint/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ for LateContextAndPass<'a, 'tcx, T> {
943943
self.context.generics = generics;
944944
}
945945

946-
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem) {
946+
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
947947
self.with_lint_attrs(it.hir_id, &it.attrs, |cx| {
948948
cx.with_param_env(it.hir_id, |cx| {
949949
lint_callback!(cx, check_foreign_item, it);

src/librustc/lint/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ macro_rules! late_lint_methods {
9494
fn check_crate_post(a: &$hir hir::Crate<$hir>);
9595
fn check_mod(a: &$hir hir::Mod, b: Span, c: hir::HirId);
9696
fn check_mod_post(a: &$hir hir::Mod, b: Span, c: hir::HirId);
97-
fn check_foreign_item(a: &$hir hir::ForeignItem);
98-
fn check_foreign_item_post(a: &$hir hir::ForeignItem);
97+
fn check_foreign_item(a: &$hir hir::ForeignItem<$hir>);
98+
fn check_foreign_item_post(a: &$hir hir::ForeignItem<$hir>);
9999
fn check_item(a: &$hir hir::Item<$hir>);
100100
fn check_item_post(a: &$hir hir::Item<$hir>);
101101
fn check_local(a: &$hir hir::Local);
@@ -610,7 +610,7 @@ impl intravisit::Visitor<'tcx> for LintLevelMapBuilder<'_, 'tcx> {
610610
});
611611
}
612612

613-
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem) {
613+
fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem<'tcx>) {
614614
self.with_lint_attrs(it.hir_id, &it.attrs, |builder| {
615615
intravisit::walk_foreign_item(builder, it);
616616
})

0 commit comments

Comments
 (0)