about summary refs log tree commit diff
path: root/src/librustc
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2019-12-01 17:21:00 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2019-12-30 11:29:30 +0100
commite2c9dd7a1030ef25f6efc2831d50a0d7720b6844 (patch)
tree0b40f6f09228e9ec5b203244e66790a53c3dc860 /src/librustc
parentaa3678d4f4c9aa8bd50e8d08e387dc9d8d326154 (diff)
downloadrust-e2c9dd7a1030ef25f6efc2831d50a0d7720b6844.tar.gz
rust-e2c9dd7a1030ef25f6efc2831d50a0d7720b6844.zip
Retire HirVec.
Diffstat (limited to 'src/librustc')
-rw-r--r--src/librustc/hir/lowering.rs64
-rw-r--r--src/librustc/hir/lowering/expr.rs2
-rw-r--r--src/librustc/hir/lowering/item.rs16
-rw-r--r--src/librustc/hir/mod.rs7
4 files changed, 35 insertions, 54 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs
index 196f1044f59..e4836ef4eef 100644
--- a/src/librustc/hir/lowering.rs
+++ b/src/librustc/hir/lowering.rs
@@ -38,7 +38,6 @@ use crate::hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
 use crate::hir::def_id::{DefId, DefIndex, CRATE_DEF_INDEX};
 use crate::hir::map::{DefKey, DefPathData, Definitions};
 use crate::hir::ptr::P;
-use crate::hir::HirVec;
 use crate::hir::{self, ParamName};
 use crate::hir::{ConstArg, GenericArg};
 use crate::lint;
@@ -540,7 +539,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
         visit::walk_crate(&mut item::ItemLowerer { lctx: &mut self }, c);
 
         let module = self.lower_mod(&c.module);
-        let attrs = self.arena.alloc_from_iter(self.lower_attrs(&c.attrs).into_iter());
+        let attrs = self.lower_attrs(&c.attrs);
         let body_ids = body_ids(&self.bodies);
 
         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> {
         }
     }
 
-    fn lower_attrs_arena(&mut self, attrs: &[Attribute]) -> &'hir [Attribute] {
+    fn lower_attrs(&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> {
-        attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into()
-    }
-
     fn lower_attr(&mut self, attr: &Attribute) -> Attribute {
         // Note that we explicitly do not walk the path. Since we don't really
         // lower attributes (we use the AST version) there is nowhere to keep
@@ -1225,25 +1220,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                 };
                 hir::TyKind::Rptr(lifetime, self.lower_mt(mt, itctx))
             }
-            TyKind::BareFn(ref f) => {
-                self.with_in_scope_lifetime_defs(&f.generic_params, |this| {
-                    this.with_anonymous_lifetime_mode(AnonymousLifetimeMode::PassThrough, |this| {
-                        hir::TyKind::BareFn(this.arena.alloc(hir::BareFnTy {
-                            generic_params: this.lower_generic_params(
-                                &f.generic_params,
-                                &NodeMap::default(),
-                                ImplTraitContext::disallowed(),
-                            ),
-                            unsafety: f.unsafety,
-                            abi: this.lower_extern(f.ext),
-                            decl: this.lower_fn_decl(&f.decl, None, false, None),
-                            param_names: this.arena.alloc_from_iter(
-                                this.lower_fn_params_to_names(&f.decl).into_iter(),
-                            ),
-                        }))
-                    })
+            TyKind::BareFn(ref f) => self.with_in_scope_lifetime_defs(&f.generic_params, |this| {
+                this.with_anonymous_lifetime_mode(AnonymousLifetimeMode::PassThrough, |this| {
+                    hir::TyKind::BareFn(this.arena.alloc(hir::BareFnTy {
+                        generic_params: this.lower_generic_params(
+                            &f.generic_params,
+                            &NodeMap::default(),
+                            ImplTraitContext::disallowed(),
+                        ),
+                        unsafety: f.unsafety,
+                        abi: this.lower_extern(f.ext),
+                        decl: this.lower_fn_decl(&f.decl, None, false, None),
+                        param_names: this.lower_fn_params_to_names(&f.decl),
+                    }))
                 })
-            }
+            }),
             TyKind::Never => hir::TyKind::Never,
             TyKind::Tup(ref tys) => {
                 hir::TyKind::Tup(self.arena.alloc_from_iter(
@@ -1412,7 +1403,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
             opaque_ty_def_index,
             &hir_bounds,
         );
-        let lifetime_defs = self.arena.alloc_from_iter(lifetime_defs.into_iter());
 
         debug!("lower_opaque_impl_trait: lifetimes={:#?}", lifetimes,);
 
@@ -1473,7 +1463,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
         opaque_ty_id: NodeId,
         parent_index: DefIndex,
         bounds: hir::GenericBounds<'hir>,
-    ) -> (&'hir [hir::GenericArg<'hir>], HirVec<hir::GenericParam<'hir>>) {
+    ) -> (&'hir [hir::GenericArg<'hir>], &'hir [hir::GenericParam<'hir>]) {
         debug!(
             "lifetimes_from_impl_trait_bounds(opaque_ty_id={:?}, \
              parent_index={:?}, \
@@ -1640,7 +1630,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
         let ImplTraitLifetimeCollector { output_lifetimes, output_lifetime_params, .. } =
             lifetime_collector;
 
-        (self.arena.alloc_from_iter(output_lifetimes), output_lifetime_params.into())
+        (
+            self.arena.alloc_from_iter(output_lifetimes),
+            self.arena.alloc_from_iter(output_lifetime_params),
+        )
     }
 
     fn lower_qpath(
@@ -2075,7 +2068,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
         )
     }
 
-    fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
+    fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Ident] {
         // Skip the `...` (`CVarArgs`) trailing arguments from the AST,
         // as they are not explicit in HIR/Ty function signatures.
         // (instead, the `c_variadic` flag is set to `true`)
@@ -2083,13 +2076,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
         if decl.c_variadic() {
             inputs = &inputs[..inputs.len() - 1];
         }
-        inputs
-            .iter()
-            .map(|param| match param.pat.kind {
-                PatKind::Ident(_, ident, _) => ident,
-                _ => Ident::new(kw::Invalid, param.pat.span),
-            })
-            .collect()
+        self.arena.alloc_from_iter(inputs.iter().map(|param| match param.pat.kind {
+            PatKind::Ident(_, ident, _) => ident,
+            _ => Ident::new(kw::Invalid, param.pat.span),
+        }))
     }
 
     // Lowers a function declaration.
@@ -2571,7 +2561,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
             name,
             span: param.ident.span,
             pure_wrt_drop: attr::contains_name(&param.attrs, sym::may_dangle),
-            attrs: self.lower_attrs_arena(&param.attrs),
+            attrs: self.lower_attrs(&param.attrs),
             bounds: self.arena.alloc_from_iter(bounds),
             kind,
         }
diff --git a/src/librustc/hir/lowering/expr.rs b/src/librustc/hir/lowering/expr.rs
index 067a076d829..1e441f97059 100644
--- a/src/librustc/hir/lowering/expr.rs
+++ b/src/librustc/hir/lowering/expr.rs
@@ -464,7 +464,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
     fn lower_arm(&mut self, arm: &Arm) -> hir::Arm<'hir> {
         hir::Arm {
             hir_id: self.next_id(),
-            attrs: self.lower_attrs_arena(&arm.attrs),
+            attrs: self.lower_attrs(&arm.attrs),
             pat: self.lower_pat(&arm.pat),
             guard: match arm.guard {
                 Some(ref x) => Some(hir::Guard::If(self.lower_expr(x))),
diff --git a/src/librustc/hir/lowering/item.rs b/src/librustc/hir/lowering/item.rs
index c9dd0a23a7d..7174addb155 100644
--- a/src/librustc/hir/lowering/item.rs
+++ b/src/librustc/hir/lowering/item.rs
@@ -226,7 +226,7 @@ impl<'hir> 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_arena(&i.attrs);
+        let attrs = self.lower_attrs(&i.attrs);
 
         if let ItemKind::MacroDef(ref def) = i.kind {
             if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {
@@ -660,7 +660,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
         hir::ForeignItem {
             hir_id: self.lower_node_id(i.id),
             ident: i.ident,
-            attrs: self.lower_attrs_arena(&i.attrs),
+            attrs: self.lower_attrs(&i.attrs),
             kind: match i.kind {
                 ForeignItemKind::Fn(ref fdec, ref generics) => {
                     let (generics, (fn_dec, fn_args)) = self.add_in_band_defs(
@@ -675,7 +675,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
                             )
                         },
                     );
-                    let fn_args = self.arena.alloc_from_iter(fn_args.into_iter());
 
                     hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
                 }
@@ -704,7 +703,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
 
     fn lower_variant(&mut self, v: &Variant) -> hir::Variant<'hir> {
         hir::Variant {
-            attrs: self.lower_attrs_arena(&v.attrs),
+            attrs: self.lower_attrs(&v.attrs),
             data: self.lower_variant_data(&v.data),
             disr_expr: v.disr_expr.as_ref().map(|e| self.lower_anon_const(e)),
             id: self.lower_node_id(v.id),
@@ -752,7 +751,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
             },
             vis: self.lower_visibility(&f.vis, None),
             ty,
-            attrs: self.lower_attrs_arena(&f.attrs),
+            attrs: self.lower_attrs(&f.attrs),
         }
     }
 
@@ -773,7 +772,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
             }
             AssocItemKind::Fn(ref sig, None) => {
                 let names = self.lower_fn_params_to_names(&sig.decl);
-                let names: &[Ident] = self.arena.alloc_from_iter(names.into_iter());
                 let (generics, sig) =
                     self.lower_method_sig(&i.generics, sig, trait_item_def_id, false, None);
                 (generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
@@ -800,7 +798,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
         hir::TraitItem {
             hir_id: self.lower_node_id(i.id),
             ident: i.ident,
-            attrs: self.lower_attrs_arena(&i.attrs),
+            attrs: self.lower_attrs(&i.attrs),
             generics,
             kind,
             span: i.span,
@@ -887,7 +885,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
         hir::ImplItem {
             hir_id: self.lower_node_id(i.id),
             ident: i.ident,
-            attrs: self.lower_attrs_arena(&i.attrs),
+            attrs: self.lower_attrs(&i.attrs),
             generics,
             vis: self.lower_visibility(&i.vis, None),
             defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
@@ -994,7 +992,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
 
     fn lower_param(&mut self, param: &Param) -> hir::Param<'hir> {
         hir::Param {
-            attrs: self.lower_attrs_arena(&param.attrs),
+            attrs: self.lower_attrs(&param.attrs),
             hir_id: self.lower_node_id(param.id),
             pat: self.lower_pat(&param.pat),
             span: param.span,
diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs
index a66863ed77c..cf31c44ed68 100644
--- a/src/librustc/hir/mod.rs
+++ b/src/librustc/hir/mod.rs
@@ -10,7 +10,6 @@ pub use self::UnsafeSource::*;
 
 use crate::hir::def::{DefKind, Res};
 use crate::hir::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX};
-use crate::hir::ptr::P;
 use crate::mir::mono::Linkage;
 use crate::ty::query::Providers;
 use crate::ty::AdtKind;
@@ -35,12 +34,6 @@ use syntax_pos::source_map::{SourceMap, Spanned};
 use syntax_pos::symbol::{kw, sym, Symbol};
 use syntax_pos::{MultiSpan, Span, DUMMY_SP};
 
-/// HIR doesn't commit to a concrete storage type and has its own alias for a vector.
-/// It can be `Vec`, `P<[T]>` or potentially `Box<[T]>`, or some other container with similar
-/// behavior. Unlike AST, HIR is mostly a static structure, so we can use an owned slice instead
-/// of `Vec` to avoid keeping extra capacity.
-pub type HirVec<T> = P<[T]>;
-
 pub mod check_attr;
 pub mod def;
 pub mod def_id;