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;
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);
}
}
- 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
};
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(
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,);
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={:?}, \
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(
)
}
- 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`)
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.
name,
span: param.ident.span,
pure_wrt_drop: attr::contains_name(¶m.attrs, sym::may_dangle),
- attrs: self.lower_attrs_arena(¶m.attrs),
+ attrs: self.lower_attrs(¶m.attrs),
bounds: self.arena.alloc_from_iter(bounds),
kind,
}
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) {
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(
)
},
);
- let fn_args = self.arena.alloc_from_iter(fn_args.into_iter());
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics)
}
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),
},
vis: self.lower_visibility(&f.vis, None),
ty,
- attrs: self.lower_attrs_arena(&f.attrs),
+ attrs: self.lower_attrs(&f.attrs),
}
}
}
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)))
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,
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] */),
fn lower_param(&mut self, param: &Param) -> hir::Param<'hir> {
hir::Param {
- attrs: self.lower_attrs_arena(¶m.attrs),
+ attrs: self.lower_attrs(¶m.attrs),
hir_id: self.lower_node_id(param.id),
pat: self.lower_pat(¶m.pat),
span: param.span,