Skip to content

Commit 084e672

Browse files
committed
Use Arena inside hir::Item.
1 parent 4dc79f1 commit 084e672

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+208
-198
lines changed

src/librustc/arena.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,12 @@ macro_rules! arena_types {
125125
// HIR nodes arenas
126126
[few] hir_forest: rustc::hir::map::Forest<$tcx>,
127127
[] attribute: syntax::ast::Attribute,
128+
[] global_asm: rustc::hir::GlobalAsm,
129+
[] impl_item_ref: rustc::hir::ImplItemRef,
128130
[] macro_def: rustc::hir::MacroDef,
131+
[] path: rustc::hir::Path,
132+
[] trait_item_ref: rustc::hir::TraitItemRef,
133+
[] ty: rustc::hir::Ty,
129134
], $tcx);
130135
)
131136
}

src/librustc/hir/check_attr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Display for Target {
8686
}
8787

8888
impl Target {
89-
pub(crate) fn from_item(item: &Item) -> Target {
89+
pub(crate) fn from_item(item: &Item<'_>) -> Target {
9090
match item.kind {
9191
ItemKind::ExternCrate(..) => Target::ExternCrate,
9292
ItemKind::Use(..) => Target::Use,
@@ -161,7 +161,7 @@ impl CheckAttrVisitor<'tcx> {
161161
attrs: &HirVec<Attribute>,
162162
span: &Span,
163163
target: Target,
164-
item: Option<&Item>,
164+
item: Option<&Item<'_>>,
165165
) {
166166
let mut is_valid = true;
167167
for attr in attrs {
@@ -335,7 +335,7 @@ impl CheckAttrVisitor<'tcx> {
335335
attrs: &HirVec<Attribute>,
336336
span: &Span,
337337
target: Target,
338-
item: Option<&Item>,
338+
item: Option<&Item<'_>>,
339339
) {
340340
// Extract the names of all repr hints, e.g., [foo, bar, align] for:
341341
// ```
@@ -492,7 +492,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
492492
NestedVisitorMap::OnlyBodies(&self.tcx.hir())
493493
}
494494

495-
fn visit_item(&mut self, item: &'tcx Item) {
495+
fn visit_item(&mut self, item: &'tcx Item<'tcx>) {
496496
let target = Target::from_item(item);
497497
self.check_attributes(item.hir_id, &item.attrs, &item.span, target, Some(item));
498498
intravisit::walk_item(self, item)
@@ -527,7 +527,7 @@ impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
527527
}
528528
}
529529

530-
fn is_c_like_enum(item: &Item) -> bool {
530+
fn is_c_like_enum(item: &Item<'_>) -> bool {
531531
if let ItemKind::Enum(ref def, _) = item.kind {
532532
for variant in &def.variants {
533533
match variant.data {

src/librustc/hir/intravisit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ pub trait Visitor<'v>: Sized {
218218

219219
/// Visits the top-level item and (optionally) nested items / impl items. See
220220
/// `visit_nested_item` for details.
221-
fn visit_item(&mut self, i: &'v Item) {
221+
fn visit_item(&mut self, i: &'v Item<'v>) {
222222
walk_item(self, i)
223223
}
224224

@@ -462,7 +462,7 @@ pub fn walk_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Param) {
462462
walk_list!(visitor, visit_attribute, &param.attrs);
463463
}
464464

465-
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
465+
pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) {
466466
visitor.visit_vis(&item.vis);
467467
visitor.visit_ident(item.ident);
468468
match item.kind {
@@ -527,7 +527,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
527527
ref generics,
528528
ref opt_trait_reference,
529529
ref typ,
530-
ref impl_item_refs
530+
impl_item_refs
531531
) => {
532532
visitor.visit_id(item.hir_id);
533533
visitor.visit_generics(generics);
@@ -542,7 +542,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
542542
visitor.visit_variant_data(struct_definition, item.ident.name, generics, item.hir_id,
543543
item.span);
544544
}
545-
ItemKind::Trait(.., ref generics, ref bounds, ref trait_item_refs) => {
545+
ItemKind::Trait(.., ref generics, ref bounds, trait_item_refs) => {
546546
visitor.visit_id(item.hir_id);
547547
visitor.visit_generics(generics);
548548
walk_list!(visitor, visit_param_bound, bounds);

src/librustc/hir/itemlikevisit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use super::intravisit::Visitor;
4545
/// existing `fn visit_nested` methods to see where changes are
4646
/// needed.
4747
pub trait ItemLikeVisitor<'hir> {
48-
fn visit_item(&mut self, item: &'hir Item);
48+
fn visit_item(&mut self, item: &'hir Item<'hir>);
4949
fn visit_trait_item(&mut self, trait_item: &'hir TraitItem);
5050
fn visit_impl_item(&mut self, impl_item: &'hir ImplItem);
5151
}
@@ -65,7 +65,7 @@ impl<'v, 'hir, V> DeepVisitor<'v, V>
6565
impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V>
6666
where V: Visitor<'hir>
6767
{
68-
fn visit_item(&mut self, item: &'hir Item) {
68+
fn visit_item(&mut self, item: &'hir Item<'hir>) {
6969
self.visitor.visit_item(item);
7070
}
7171

@@ -80,7 +80,7 @@ impl<'v, 'hir, V> ItemLikeVisitor<'hir> for DeepVisitor<'v, V>
8080

8181
/// A parallel variant of `ItemLikeVisitor`.
8282
pub trait ParItemLikeVisitor<'hir> {
83-
fn visit_item(&self, item: &'hir Item);
83+
fn visit_item(&self, item: &'hir Item<'hir>);
8484
fn visit_trait_item(&self, trait_item: &'hir TraitItem);
8585
fn visit_impl_item(&self, impl_item: &'hir ImplItem);
8686
}
@@ -95,7 +95,7 @@ pub struct ParDeepVisitor<V>(pub V);
9595
impl<'hir, V> ParItemLikeVisitor<'hir> for ParDeepVisitor<V>
9696
where V: IntoVisitor<'hir>
9797
{
98-
fn visit_item(&self, item: &'hir Item) {
98+
fn visit_item(&self, item: &'hir Item<'hir>) {
9999
self.0.into_visitor().visit_item(item);
100100
}
101101

src/librustc/hir/lowering.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub struct LoweringContext<'a, 'hir: 'a> {
9595
arena: &'hir Arena<'hir>,
9696

9797
/// The items being lowered are collected here.
98-
items: BTreeMap<hir::HirId, hir::Item>,
98+
items: BTreeMap<hir::HirId, hir::Item<'hir>>,
9999

100100
trait_items: BTreeMap<hir::TraitItemId, hir::TraitItem>,
101101
impl_items: BTreeMap<hir::ImplItemId, hir::ImplItem>,
@@ -566,7 +566,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
566566
}
567567
}
568568

569-
fn insert_item(&mut self, item: hir::Item) {
569+
fn insert_item(&mut self, item: hir::Item<'hir>) {
570570
let id = item.hir_id;
571571
// FIXME: Use `debug_asset-rt`.
572572
assert_eq!(id.local_id, hir::ItemLocalId::from_u32(0));
@@ -873,7 +873,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
873873
// for them.
874874
fn with_in_scope_lifetime_defs<T, F>(&mut self, params: &[GenericParam], f: F) -> T
875875
where
876-
F: FnOnce(&mut LoweringContext<'_, '_>) -> T,
876+
F: FnOnce(&mut LoweringContext<'_, 'hir>) -> T,
877877
{
878878
let old_len = self.in_scope_lifetimes.len();
879879
let lt_def_names = params.iter().filter_map(|param| match param.kind {

src/librustc/hir/lowering/item.rs

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl<'a, 'lowering, 'hir> Visitor<'a> for ItemLowerer<'a, 'lowering, 'hir> {
107107
}
108108
}
109109

110-
impl LoweringContext<'_, '_> {
110+
impl LoweringContext<'_, 'hir> {
111111
// Same as the method above, but accepts `hir::GenericParam`s
112112
// instead of `ast::GenericParam`s.
113113
// This should only be used with generics that have already had their
@@ -225,7 +225,7 @@ impl LoweringContext<'_, '_> {
225225
}
226226
}
227227

228-
pub fn lower_item(&mut self, i: &Item) -> Option<hir::Item> {
228+
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);
231231
let attrs = self.lower_attrs(&i.attrs);
@@ -269,7 +269,7 @@ impl LoweringContext<'_, '_> {
269269
attrs: &hir::HirVec<Attribute>,
270270
vis: &mut hir::Visibility,
271271
i: &ItemKind,
272-
) -> hir::ItemKind {
272+
) -> hir::ItemKind<'hir> {
273273
match *i {
274274
ItemKind::ExternCrate(orig_name) => hir::ItemKind::ExternCrate(orig_name),
275275
ItemKind::Use(ref use_tree) => {
@@ -282,29 +282,31 @@ impl LoweringContext<'_, '_> {
282282
self.lower_use_tree(use_tree, &prefix, id, vis, ident, attrs)
283283
}
284284
ItemKind::Static(ref t, m, ref e) => {
285+
let ty = self.lower_ty(
286+
t,
287+
if self.sess.features_untracked().impl_trait_in_bindings {
288+
ImplTraitContext::OpaqueTy(None)
289+
} else {
290+
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
291+
}
292+
);
285293
hir::ItemKind::Static(
286-
self.lower_ty(
287-
t,
288-
if self.sess.features_untracked().impl_trait_in_bindings {
289-
ImplTraitContext::OpaqueTy(None)
290-
} else {
291-
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
292-
}
293-
),
294+
self.arena.alloc(ty.into_inner()),
294295
m,
295296
self.lower_const_body(span, Some(e)),
296297
)
297298
}
298299
ItemKind::Const(ref t, ref e) => {
300+
let ty = self.lower_ty(
301+
t,
302+
if self.sess.features_untracked().impl_trait_in_bindings {
303+
ImplTraitContext::OpaqueTy(None)
304+
} else {
305+
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
306+
}
307+
);
299308
hir::ItemKind::Const(
300-
self.lower_ty(
301-
t,
302-
if self.sess.features_untracked().impl_trait_in_bindings {
303-
ImplTraitContext::OpaqueTy(None)
304-
} else {
305-
ImplTraitContext::Disallowed(ImplTraitPosition::Binding)
306-
}
307-
),
309+
self.arena.alloc(ty.into_inner()),
308310
self.lower_const_body(span, Some(e))
309311
)
310312
}
@@ -346,7 +348,7 @@ impl LoweringContext<'_, '_> {
346348
None => {
347349
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
348350
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
349-
hir::ItemKind::TyAlias(ty, generics)
351+
hir::ItemKind::TyAlias(self.arena.alloc(ty.into_inner()), generics)
350352
},
351353
Some(bounds) => {
352354
let ty = hir::OpaqueTy {
@@ -434,10 +436,11 @@ impl LoweringContext<'_, '_> {
434436
let new_impl_items = self.with_in_scope_lifetime_defs(
435437
&ast_generics.params,
436438
|this| {
437-
impl_items
438-
.iter()
439-
.map(|item| this.lower_impl_item_ref(item))
440-
.collect()
439+
this.arena.alloc_from_iter(
440+
impl_items
441+
.iter()
442+
.map(|item| this.lower_impl_item_ref(item))
443+
)
441444
},
442445
);
443446

@@ -447,16 +450,16 @@ impl LoweringContext<'_, '_> {
447450
self.lower_defaultness(defaultness, true /* [1] */),
448451
generics,
449452
trait_ref,
450-
lowered_ty,
453+
self.arena.alloc(lowered_ty.into_inner()),
451454
new_impl_items,
452455
)
453456
}
454457
ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref items) => {
455458
let bounds = self.lower_param_bounds(bounds, ImplTraitContext::disallowed());
456-
let items = items
459+
let items = self.arena.alloc_from_iter(items
457460
.iter()
458461
.map(|item| self.lower_trait_item_ref(item))
459-
.collect();
462+
);
460463
hir::ItemKind::Trait(
461464
is_auto,
462465
unsafety,
@@ -485,7 +488,7 @@ impl LoweringContext<'_, '_> {
485488
vis: &mut hir::Visibility,
486489
ident: &mut Ident,
487490
attrs: &hir::HirVec<Attribute>,
488-
) -> hir::ItemKind {
491+
) -> hir::ItemKind<'hir> {
489492
debug!("lower_use_tree(tree={:?})", tree);
490493
debug!("lower_use_tree: vis = {:?}", vis);
491494

@@ -540,7 +543,7 @@ impl LoweringContext<'_, '_> {
540543
let res = this.lower_res(res);
541544
let path =
542545
this.lower_path_extra(res, &path, ParamMode::Explicit, None);
543-
let kind = hir::ItemKind::Use(P(path), hir::UseKind::Single);
546+
let kind = hir::ItemKind::Use(this.arena.alloc(path), hir::UseKind::Single);
544547
let vis = this.rebuild_vis(&vis);
545548

546549
this.insert_item(
@@ -556,11 +559,11 @@ impl LoweringContext<'_, '_> {
556559
});
557560
}
558561

559-
let path = P(self.lower_path_extra(ret_res, &path, ParamMode::Explicit, None));
562+
let path = self.arena.alloc(self.lower_path_extra(ret_res, &path, ParamMode::Explicit, None));
560563
hir::ItemKind::Use(path, hir::UseKind::Single)
561564
}
562565
UseTreeKind::Glob => {
563-
let path = P(self.lower_path(
566+
let path = self.arena.alloc(self.lower_path(
564567
id,
565568
&Path {
566569
segments,
@@ -663,7 +666,7 @@ impl LoweringContext<'_, '_> {
663666

664667
let res = self.expect_full_res_from_use(id).next().unwrap_or(Res::Err);
665668
let res = self.lower_res(res);
666-
let path = P(self.lower_path_extra(res, &prefix, ParamMode::Explicit, None));
669+
let path = self.arena.alloc(self.lower_path_extra(res, &prefix, ParamMode::Explicit, None));
667670
hir::ItemKind::Use(path, hir::UseKind::ListStem)
668671
}
669672
}
@@ -748,8 +751,8 @@ impl LoweringContext<'_, '_> {
748751
}
749752
}
750753

751-
fn lower_global_asm(&mut self, ga: &GlobalAsm) -> P<hir::GlobalAsm> {
752-
P(hir::GlobalAsm { asm: ga.asm })
754+
fn lower_global_asm(&mut self, ga: &GlobalAsm) -> &'hir hir::GlobalAsm {
755+
self.arena.alloc(hir::GlobalAsm { asm: ga.asm })
753756
}
754757

755758
fn lower_variant(&mut self, v: &Variant) -> hir::Variant {

src/librustc/hir/map/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct FnLikeNode<'a> { node: Node<'a> }
3535
/// corresponds to some FnLikeNode.
3636
trait MaybeFnLike { fn is_fn_like(&self) -> bool; }
3737

38-
impl MaybeFnLike for ast::Item {
38+
impl MaybeFnLike for ast::Item<'_> {
3939
fn is_fn_like(&self) -> bool {
4040
match self.kind {
4141
ast::ItemKind::Fn(..) => true,

src/librustc/hir/map/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
367367
});
368368
}
369369

370-
fn visit_item(&mut self, i: &'hir Item) {
370+
fn visit_item(&mut self, i: &'hir Item<'hir>) {
371371
debug!("visit_item: {:?}", i);
372372
debug_assert_eq!(i.hir_id.owner,
373373
self.definitions.opt_def_index(self.hir_to_node_id[&i.hir_id]).unwrap());

src/librustc/hir/map/hir_id_validator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'a, 'hir> OuterVisitor<'a, 'hir> {
5353
}
5454

5555
impl<'a, 'hir> ItemLikeVisitor<'hir> for OuterVisitor<'a, 'hir> {
56-
fn visit_item(&mut self, i: &'hir hir::Item) {
56+
fn visit_item(&mut self, i: &'hir hir::Item<'hir>) {
5757
let mut inner_visitor = self.new_inner_visitor(self.hir_map);
5858
inner_visitor.check(i.hir_id, |this| intravisit::walk_item(this, i));
5959
}

src/librustc/hir/map/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,7 @@ impl<'hir> Map<'hir> {
959959
bug!("expected foreign mod or inlined parent, found {}", self.node_to_string(parent))
960960
}
961961

962-
pub fn expect_item(&self, id: HirId) -> &'hir Item {
962+
pub fn expect_item(&self, id: HirId) -> &'hir Item<'hir> {
963963
match self.find(id) { // read recorded by `find`
964964
Some(Node::Item(item)) => item,
965965
_ => bug!("expected item, found {}", self.node_to_string(id))
@@ -1213,7 +1213,7 @@ impl<'a> NodesMatchingSuffix<'a> {
12131213
id = parent;
12141214
}
12151215

1216-
fn item_is_mod(item: &Item) -> bool {
1216+
fn item_is_mod(item: &Item<'_>) -> bool {
12171217
match item.kind {
12181218
ItemKind::Mod(_) => true,
12191219
_ => false,
@@ -1248,7 +1248,7 @@ trait Named {
12481248

12491249
impl<T:Named> Named for Spanned<T> { fn name(&self) -> Name { self.node.name() } }
12501250

1251-
impl Named for Item { fn name(&self) -> Name { self.ident.name } }
1251+
impl Named for Item<'_> { fn name(&self) -> Name { self.ident.name } }
12521252
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 } }

0 commit comments

Comments
 (0)