]> git.lizzy.rs Git - rust.git/commitdiff
Retire HirVec.
authorCamille GILLOT <gillot.camille@gmail.com>
Sun, 1 Dec 2019 16:21:00 +0000 (17:21 +0100)
committerCamille GILLOT <gillot.camille@gmail.com>
Mon, 30 Dec 2019 10:29:30 +0000 (11:29 +0100)
src/librustc/hir/lowering.rs
src/librustc/hir/lowering/expr.rs
src/librustc/hir/lowering/item.rs
src/librustc/hir/mod.rs
src/librustdoc/clean/inline.rs
src/librustdoc/doctree.rs

index 196f1044f59427b8264e613daf360a8fa310c716..e4836ef4eef8928ea75f65f833f461b5f270c63a 100644 (file)
@@ -38,7 +38,6 @@
 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 @@ fn visit_ty(&mut self, t: &'tcx Ty) {
         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 @@ fn def_key(&mut self, id: DefId) -> DefKey {
         }
     }
 
-    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 @@ fn lower_ty_direct(&mut self, t: &Ty, mut itctx: ImplTraitContext<'_, '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 @@ fn lower_opaque_impl_trait(
             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 @@ fn lifetimes_from_impl_trait_bounds(
         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 @@ fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) {
         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 @@ fn lower_parenthesized_parameter_data(
         )
     }
 
-    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 @@ fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> hir::HirVec<Ident> {
         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 @@ fn lower_generic_param(
             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,
         }
index 067a076d8298a1ca4e79ba3c09bb3e38efaba3c8..1e441f97059cc26ac95b52153ca6a55e5ad6cf88 100644 (file)
@@ -464,7 +464,7 @@ fn wrap_in_try_constructor(
     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))),
index c9dd0a23a7d1ebe0ac38c3f67d25c335198df6b5..7174addb15501df0768d4d36ccffcdbeb8d6644b 100644 (file)
@@ -226,7 +226,7 @@ fn lower_item_id_use_tree(
     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 @@ fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'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 @@ fn lower_foreign_item(&mut self, i: &ForeignItem) -> hir::ForeignItem<'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 @@ fn lower_global_asm(&mut self, ga: &GlobalAsm) -> &'hir hir::GlobalAsm {
 
     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 @@ fn lower_struct_field(&mut self, (index, f): (usize, &StructField)) -> hir::Stru
             },
             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 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'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 @@ fn lower_trait_item(&mut self, i: &AssocItem) -> hir::TraitItem<'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 @@ fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem<'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 @@ fn lower_body(
 
     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,
index a66863ed77cc15a15ad20f2c0244666277432508..cf31c44ed685a0dd5d24a4ca519b2a18d1d66329 100644 (file)
@@ -10,7 +10,6 @@
 
 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;
 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;
index 35e26819b10b4167829836c74a82e7afc216b177..e12d9affdfabc8bba4a0965cb92167f6f61b68f9 100644 (file)
@@ -474,7 +474,7 @@ fn build_macro(cx: &DocContext<'_>, did: DefId, name: ast::Name) -> clean::ItemE
     let imported_from = cx.tcx.original_crate_name(did.krate);
     match cx.enter_resolver(|r| r.cstore().load_macro_untracked(did, cx.sess())) {
         LoadedMacro::MacroDef(def, _) => {
-            let matchers: hir::HirVec<Span> = if let ast::ItemKind::MacroDef(ref def) = def.kind {
+            let matchers: Vec<Span> = if let ast::ItemKind::MacroDef(ref def) = def.kind {
                 let tts: Vec<_> = def.body.inner_tokens().into_trees().collect();
                 tts.chunks(4).map(|arm| arm[0].span()).collect()
             } else {
index 46eddede0d518c5924667885db820d7c32dfcbed..07a3f663145224236548ee0d67396d8a6b78e892 100644 (file)
@@ -230,7 +230,7 @@ pub struct Macro<'hir> {
     pub def_id: hir::def_id::DefId,
     pub attrs: &'hir [ast::Attribute],
     pub whence: Span,
-    pub matchers: hir::HirVec<Span>,
+    pub matchers: Vec<Span>,
     pub imported_from: Option<Name>,
 }