@@ -38,7 +38,6 @@ use crate::hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
3838use crate :: hir:: def_id:: { DefId , DefIndex , CRATE_DEF_INDEX } ;
3939use crate :: hir:: map:: { DefKey , DefPathData , Definitions } ;
4040use crate :: hir:: ptr:: P ;
41- use crate :: hir:: HirVec ;
4241use crate :: hir:: { self , ParamName } ;
4342use crate :: hir:: { ConstArg , GenericArg } ;
4443use 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 }
0 commit comments