Skip to content

Commit e2c9dd7

Browse files
committed
Retire HirVec.
1 parent aa3678d commit e2c9dd7

File tree

6 files changed

+37
-56
lines changed

6 files changed

+37
-56
lines changed

src/librustc/hir/lowering.rs

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use crate::hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
3838
use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
3939
use crate::hir::map::{DefKey, DefPathData, Definitions};
4040
use crate::hir::ptr::P;
41-
use crate::hir::HirVec;
4241
use crate::hir::{self, ParamName};
4342
use crate::hir::{ConstArg, GenericArg};
4443
use crate::lint;
@@ -540,7 +539,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
540539
visit::walk_crate(&mut item::ItemLowerer { lctx: &mut self }, c);
541540

542541
let module = self.lower_mod(&c.module);
543-
let attrs = self.arena.alloc_from_iter(self.lower_attrs(&c.attrs).into_iter());
542+
let attrs = self.lower_attrs(&c.attrs);
544543
let body_ids = body_ids(&self.bodies);
545544

546545
self.resolver.definitions().init_node_id_to_hir_id_mapping(self.node_id_to_hir_id);
@@ -958,14 +957,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
958957
}
959958
}
960959

961-
fn lower_attrs_arena(&mut self, attrs: &[Attribute]) -> &'hir [Attribute] {
960+
fn lower_attrs(&mut self, attrs: &[Attribute]) -> &'hir [Attribute] {
962961
self.arena.alloc_from_iter(attrs.iter().map(|a| self.lower_attr(a)))
963962
}
964963

965-
fn lower_attrs(&mut self, attrs: &[Attribute]) -> hir::HirVec<Attribute> {
966-
attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into()
967-
}
968-
969964
fn lower_attr(&mut self, attr: &Attribute) -> Attribute {
970965
// Note that we explicitly do not walk the path. Since we don't really
971966
// lower attributes (we use the AST version) there is nowhere to keep
@@ -1225,25 +1220,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12251220
};
12261221
hir::TyKind::Rptr(lifetime, self.lower_mt(mt, itctx))
12271222
}
1228-
TyKind::BareFn(ref f) => {
1229-
self.with_in_scope_lifetime_defs(&f.generic_params, |this| {
1230-
this.with_anonymous_lifetime_mode(AnonymousLifetimeMode::PassThrough, |this| {
1231-
hir::TyKind::BareFn(this.arena.alloc(hir::BareFnTy {
1232-
generic_params: this.lower_generic_params(
1233-
&f.generic_params,
1234-
&NodeMap::default(),
1235-
ImplTraitContext::disallowed(),
1236-
),
1237-
unsafety: f.unsafety,
1238-
abi: this.lower_extern(f.ext),
1239-
decl: this.lower_fn_decl(&f.decl, None, false, None),
1240-
param_names: this.arena.alloc_from_iter(
1241-
this.lower_fn_params_to_names(&f.decl).into_iter(),
1242-
),
1243-
}))
1244-
})
1223+
TyKind::BareFn(ref f) => self.with_in_scope_lifetime_defs(&f.generic_params, |this| {
1224+
this.with_anonymous_lifetime_mode(AnonymousLifetimeMode::PassThrough, |this| {
1225+
hir::TyKind::BareFn(this.arena.alloc(hir::BareFnTy {
1226+
generic_params: this.lower_generic_params(
1227+
&f.generic_params,
1228+
&NodeMap::default(),
1229+
ImplTraitContext::disallowed(),
1230+
),
1231+
unsafety: f.unsafety,
1232+
abi: this.lower_extern(f.ext),
1233+
decl: this.lower_fn_decl(&f.decl, None, false, None),
1234+
param_names: this.lower_fn_params_to_names(&f.decl),
1235+
}))
12451236
})
1246-
}
1237+
}),
12471238
TyKind::Never => hir::TyKind::Never,
12481239
TyKind::Tup(ref tys) => {
12491240
hir::TyKind::Tup(self.arena.alloc_from_iter(
@@ -1412,7 +1403,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14121403
opaque_ty_def_index,
14131404
&hir_bounds,
14141405
);
1415-
let lifetime_defs = self.arena.alloc_from_iter(lifetime_defs.into_iter());
14161406

14171407
debug!("lower_opaque_impl_trait: lifetimes={:#?}", lifetimes,);
14181408

@@ -1473,7 +1463,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14731463
opaque_ty_id: NodeId,
14741464
parent_index: DefIndex,
14751465
bounds: hir::GenericBounds<'hir>,
1476-
) -> (&'hir [hir::GenericArg<'hir>], HirVec<hir::GenericParam<'hir>>) {
1466+
) -> (&'hir [hir::GenericArg<'hir>], &'hir [hir::GenericParam<'hir>]) {
14771467
debug!(
14781468
"lifetimes_from_impl_trait_bounds(opaque_ty_id={:?}, \
14791469
parent_index={:?}, \
@@ -1640,7 +1630,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16401630
let ImplTraitLifetimeCollector { output_lifetimes, output_lifetime_params, .. } =
16411631
lifetime_collector;
16421632

1643-
(self.arena.alloc_from_iter(output_lifetimes), output_lifetime_params.into())
1633+
(
1634+
self.arena.alloc_from_iter(output_lifetimes),
1635+
self.arena.alloc_from_iter(output_lifetime_params),
1636+
)
16441637
}
16451638

16461639
fn lower_qpath(
@@ -2075,21 +2068,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20752068
)
20762069
}
20772070

2078-
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
2071+
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
20792072
// Skip the `...` (`CVarArgs`) trailing arguments from the AST,
20802073
// as they are not explicit in HIR/Ty function signatures.
20812074
// (instead, the `c_variadic` flag is set to `true`)
20822075
let mut inputs = &decl.inputs[..];
20832076
if decl.c_variadic() {
20842077
inputs = &inputs[..inputs.len() - 1];
20852078
}
2086-
inputs
2087-
.iter()
2088-
.map(|param| match param.pat.kind {
2089-
PatKind::Ident(_, ident, _) => ident,
2090-
_ => Ident::new(kw::Invalid, param.pat.span),
2091-
})
2092-
.collect()
2079+
self.arena.alloc_from_iter(inputs.iter().map(|param| match param.pat.kind {
2080+
PatKind::Ident(_, ident, _) => ident,
2081+
_ => Ident::new(kw::Invalid, param.pat.span),
2082+
}))
20932083
}
20942084

20952085
// Lowers a function declaration.
@@ -2571,7 +2561,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
25712561
name,
25722562
span: param.ident.span,
25732563
pure_wrt_drop: attr::contains_name(&param.attrs, sym::may_dangle),
2574-
attrs: self.lower_attrs_arena(&param.attrs),
2564+
attrs: self.lower_attrs(&param.attrs),
25752565
bounds: self.arena.alloc_from_iter(bounds),
25762566
kind,
25772567
}

src/librustc/hir/lowering/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
464464
fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
465465
hir::Arm {
466466
hir_id: self.next_id(),
467-
attrs: self.lower_attrs_arena(&arm.attrs),
467+
attrs: self.lower_attrs(&arm.attrs),
468468
pat: self.lower_pat(&arm.pat),
469469
guard: match arm.guard {
470470
Some(ref x) => Some(hir::Guard::If(self.lower_expr(x))),

src/librustc/hir/lowering/item.rs

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

231231
if let ItemKind::MacroDef(ref def) = i.kind {
232232
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {
@@ -660,7 +660,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
660660
hir::ForeignItem {
661661
hir_id: self.lower_node_id(i.id),
662662
ident: i.ident,
663-
attrs: self.lower_attrs_arena(&i.attrs),
663+
attrs: self.lower_attrs(&i.attrs),
664664
kind: match i.kind {
665665
ForeignItemKind::Fn(ref fdec, ref generics) => {
666666
let (generics, (fn_dec, fn_args)) = self.add_in_band_defs(
@@ -675,7 +675,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
675675
)
676676
},
677677
);
678-
let fn_args = self.arena.alloc_from_iter(fn_args.into_iter());
679678

680679
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
681680
}
@@ -704,7 +703,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
704703

705704
fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
706705
hir::Variant {
707-
attrs: self.lower_attrs_arena(&v.attrs),
706+
attrs: self.lower_attrs(&v.attrs),
708707
data: self.lower_variant_data(&v.data),
709708
disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
710709
id: self.lower_node_id(v.id),
@@ -752,7 +751,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
752751
},
753752
vis: self.lower_visibility(&f.vis, None),
754753
ty,
755-
attrs: self.lower_attrs_arena(&f.attrs),
754+
attrs: self.lower_attrs(&f.attrs),
756755
}
757756
}
758757

@@ -773,7 +772,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
773772
}
774773
AssocItemKind::Fn(ref sig, None) => {
775774
let names = self.lower_fn_params_to_names(&sig.decl);
776-
let names: &[Ident] = self.arena.alloc_from_iter(names.into_iter());
777775
let (generics, sig) =
778776
self.lower_method_sig(&i.generics, sig, trait_item_def_id, false, None);
779777
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
@@ -800,7 +798,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
800798
hir::TraitItem {
801799
hir_id: self.lower_node_id(i.id),
802800
ident: i.ident,
803-
attrs: self.lower_attrs_arena(&i.attrs),
801+
attrs: self.lower_attrs(&i.attrs),
804802
generics,
805803
kind,
806804
span: i.span,
@@ -887,7 +885,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
887885
hir::ImplItem {
888886
hir_id: self.lower_node_id(i.id),
889887
ident: i.ident,
890-
attrs: self.lower_attrs_arena(&i.attrs),
888+
attrs: self.lower_attrs(&i.attrs),
891889
generics,
892890
vis: self.lower_visibility(&i.vis, None),
893891
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
@@ -994,7 +992,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
994992

995993
fn lower_param(&mut self, param: &Param) -> hir::Param<'hir> {
996994
hir::Param {
997-
attrs: self.lower_attrs_arena(&param.attrs),
995+
attrs: self.lower_attrs(&param.attrs),
998996
hir_id: self.lower_node_id(param.id),
999997
pat: self.lower_pat(&param.pat),
1000998
span: param.span,

src/librustc/hir/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub use self::UnsafeSource::*;
1010

1111
use crate::hir::def::{DefKind, Res};
1212
use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
13-
use crate::hir::ptr::P;
1413
use crate::mir::mono::Linkage;
1514
use crate::ty::query::Providers;
1615
use crate::ty::AdtKind;
@@ -35,12 +34,6 @@ use syntax_pos::source_map::{SourceMap, Spanned};
3534
use syntax_pos::symbol::{kw, sym, Symbol};
3635
use syntax_pos::{MultiSpan, Span, DUMMY_SP};
3736

38-
/// HIR doesn't commit to a concrete storage type and has its own alias for a vector.
39-
/// It can be `Vec`, `P<[T]>` or potentially `Box<[T]>`, or some other container with similar
40-
/// behavior. Unlike AST, HIR is mostly a static structure, so we can use an owned slice instead
41-
/// of `Vec` to avoid keeping extra capacity.
42-
pub type HirVec<T> = P<[T]>;
43-
4437
pub mod check_attr;
4538
pub mod def;
4639
pub mod def_id;

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ fn build_macro(cx: &DocContext<'_>, did: DefId, name: ast::Name) -> clean::ItemE
474474
let imported_from = cx.tcx.original_crate_name(did.krate);
475475
match cx.enter_resolver(|r| r.cstore().load_macro_untracked(did, cx.sess())) {
476476
LoadedMacro::MacroDef(def, _) => {
477-
let matchers: hir::HirVec<Span> = if let ast::ItemKind::MacroDef(ref def) = def.kind {
477+
let matchers: Vec<Span> = if let ast::ItemKind::MacroDef(ref def) = def.kind {
478478
let tts: Vec<_> = def.body.inner_tokens().into_trees().collect();
479479
tts.chunks(4).map(|arm| arm[0].span()).collect()
480480
} else {

src/librustdoc/doctree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ pub struct Macro<'hir> {
230230
pub def_id: hir::def_id::DefId,
231231
pub attrs: &'hir [ast::Attribute],
232232
pub whence: Span,
233-
pub matchers: hir::HirVec<Span>,
233+
pub matchers: Vec<Span>,
234234
pub imported_from: Option<Name>,
235235
}
236236

0 commit comments

Comments
 (0)