@@ -921,7 +921,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
921
921
922
922
fn with_new_scopes < T , F > ( & mut self , f : F ) -> T
923
923
where
924
- F : FnOnce ( & mut LoweringContext < ' _ , ' _ > ) -> T ,
924
+ F : FnOnce ( & mut Self ) -> T ,
925
925
{
926
926
let was_in_loop_condition = self . is_in_loop_condition ;
927
927
self . is_in_loop_condition = false ;
@@ -2031,21 +2031,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2031
2031
}
2032
2032
}
2033
2033
let parent_def_id = DefId :: local ( self . current_hir_id_owner . last ( ) . unwrap ( ) . 0 ) ;
2034
+ let ty = l. ty . as_ref ( ) . map ( |t| {
2035
+ self . lower_ty (
2036
+ t,
2037
+ if self . sess . features_untracked ( ) . impl_trait_in_bindings {
2038
+ ImplTraitContext :: OpaqueTy ( Some ( parent_def_id) )
2039
+ } else {
2040
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding )
2041
+ } ,
2042
+ )
2043
+ } ) ;
2044
+ let ty = ty. map ( |ty| -> & ' hir hir:: Ty { self . arena . alloc ( ty. into_inner ( ) ) } ) ;
2045
+ let init = l
2046
+ . init
2047
+ . as_ref ( )
2048
+ . map ( |e| -> & ' hir hir:: Expr < ' hir > { self . arena . alloc ( self . lower_expr ( e) ) } ) ;
2034
2049
(
2035
2050
hir:: Local {
2036
2051
hir_id : self . lower_node_id ( l. id ) ,
2037
- ty : l. ty . as_ref ( ) . map ( |t| {
2038
- self . lower_ty (
2039
- t,
2040
- if self . sess . features_untracked ( ) . impl_trait_in_bindings {
2041
- ImplTraitContext :: OpaqueTy ( Some ( parent_def_id) )
2042
- } else {
2043
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Binding )
2044
- } ,
2045
- )
2046
- } ) ,
2052
+ ty,
2047
2053
pat : self . lower_pat ( & l. pat ) ,
2048
- init : l . init . as_ref ( ) . map ( |e| P ( self . lower_expr ( e ) ) ) ,
2054
+ init,
2049
2055
span : l. span ,
2050
2056
attrs : l. attrs . clone ( ) ,
2051
2057
source : hir:: LocalSource :: Normal ,
@@ -2586,14 +2592,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2586
2592
bounds. iter ( ) . map ( |bound| self . lower_param_bound ( bound, itctx. reborrow ( ) ) ) . collect ( )
2587
2593
}
2588
2594
2589
- fn lower_block ( & mut self , b : & Block , targeted_by_break : bool ) -> P < hir:: Block < ' hir > > {
2595
+ fn lower_block ( & mut self , b : & Block , targeted_by_break : bool ) -> & ' hir hir:: Block < ' hir > {
2596
+ self . arena . alloc ( self . lower_block_noalloc ( b, targeted_by_break) )
2597
+ }
2598
+
2599
+ fn lower_block_noalloc ( & mut self , b : & Block , targeted_by_break : bool ) -> hir:: Block < ' hir > {
2590
2600
let mut stmts = vec ! [ ] ;
2591
- let mut expr = None ;
2601
+ let mut expr: Option < & ' hir _ > = None ;
2592
2602
2593
2603
for ( index, stmt) in b. stmts . iter ( ) . enumerate ( ) {
2594
2604
if index == b. stmts . len ( ) - 1 {
2595
2605
if let StmtKind :: Expr ( ref e) = stmt. kind {
2596
- expr = Some ( P ( self . lower_expr ( e) ) ) ;
2606
+ expr = Some ( self . arena . alloc ( self . lower_expr ( e) ) ) ;
2597
2607
} else {
2598
2608
stmts. extend ( self . lower_stmt ( stmt) ) ;
2599
2609
}
@@ -2602,14 +2612,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2602
2612
}
2603
2613
}
2604
2614
2605
- P ( hir:: Block {
2615
+ hir:: Block {
2606
2616
hir_id : self . lower_node_id ( b. id ) ,
2607
- stmts : stmts . into ( ) ,
2617
+ stmts : self . arena . alloc_from_iter ( stmts ) ,
2608
2618
expr,
2609
2619
rules : self . lower_block_check_mode ( & b. rules ) ,
2610
2620
span : b. span ,
2611
2621
targeted_by_break,
2612
- } )
2622
+ }
2613
2623
}
2614
2624
2615
2625
/// Lowers a block directly to an expression, presuming that it
@@ -2619,15 +2629,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2619
2629
self . expr_block ( block, AttrVec :: new ( ) )
2620
2630
}
2621
2631
2622
- fn lower_pat ( & mut self , p : & Pat ) -> P < hir:: Pat < ' hir > > {
2632
+ fn lower_pat ( & mut self , p : & Pat ) -> & ' hir hir :: Pat < ' hir > {
2623
2633
let node = match p. kind {
2624
2634
PatKind :: Wild => hir:: PatKind :: Wild ,
2625
2635
PatKind :: Ident ( ref binding_mode, ident, ref sub) => {
2626
2636
let lower_sub = |this : & mut Self | sub. as_ref ( ) . map ( |s| this. lower_pat ( & * s) ) ;
2627
2637
let node = self . lower_pat_ident ( p, binding_mode, ident, lower_sub) ;
2628
2638
node
2629
2639
}
2630
- PatKind :: Lit ( ref e) => hir:: PatKind :: Lit ( P ( self . lower_expr ( e) ) ) ,
2640
+ PatKind :: Lit ( ref e) => hir:: PatKind :: Lit ( self . arena . alloc ( self . lower_expr ( e) ) ) ,
2631
2641
PatKind :: TupleStruct ( ref path, ref pats) => {
2632
2642
let qpath = self . lower_qpath (
2633
2643
p. id ,
@@ -2640,7 +2650,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2640
2650
hir:: PatKind :: TupleStruct ( qpath, pats, ddpos)
2641
2651
}
2642
2652
PatKind :: Or ( ref pats) => {
2643
- hir:: PatKind :: Or ( pats. iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) )
2653
+ hir:: PatKind :: Or ( self . arena . alloc_from_iter ( pats. iter ( ) . map ( |x| self . lower_pat ( x) ) ) )
2644
2654
}
2645
2655
PatKind :: Path ( ref qself, ref path) => {
2646
2656
let qpath = self . lower_qpath (
@@ -2661,16 +2671,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2661
2671
ImplTraitContext :: disallowed ( ) ,
2662
2672
) ;
2663
2673
2664
- let fs = fields
2665
- . iter ( )
2666
- . map ( |f| hir:: FieldPat {
2667
- hir_id : self . next_id ( ) ,
2668
- ident : f. ident ,
2669
- pat : self . lower_pat ( & f. pat ) ,
2670
- is_shorthand : f. is_shorthand ,
2671
- span : f. span ,
2672
- } )
2673
- . collect ( ) ;
2674
+ let fs = self . arena . alloc_from_iter ( fields. iter ( ) . map ( |f| hir:: FieldPat {
2675
+ hir_id : self . next_id ( ) ,
2676
+ ident : f. ident ,
2677
+ pat : self . lower_pat ( & f. pat ) ,
2678
+ is_shorthand : f. is_shorthand ,
2679
+ span : f. span ,
2680
+ } ) ) ;
2674
2681
hir:: PatKind :: Struct ( qpath, fs, etc)
2675
2682
}
2676
2683
PatKind :: Tuple ( ref pats) => {
@@ -2680,8 +2687,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2680
2687
PatKind :: Box ( ref inner) => hir:: PatKind :: Box ( self . lower_pat ( inner) ) ,
2681
2688
PatKind :: Ref ( ref inner, mutbl) => hir:: PatKind :: Ref ( self . lower_pat ( inner) , mutbl) ,
2682
2689
PatKind :: Range ( ref e1, ref e2, Spanned { node : ref end, .. } ) => hir:: PatKind :: Range (
2683
- P ( self . lower_expr ( e1) ) ,
2684
- P ( self . lower_expr ( e2) ) ,
2690
+ self . arena . alloc ( self . lower_expr ( e1) ) ,
2691
+ self . arena . alloc ( self . lower_expr ( e2) ) ,
2685
2692
self . lower_range_end ( end) ,
2686
2693
) ,
2687
2694
PatKind :: Slice ( ref pats) => self . lower_pat_slice ( pats) ,
@@ -2700,7 +2707,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2700
2707
& mut self ,
2701
2708
pats : & [ AstP < Pat > ] ,
2702
2709
ctx : & str ,
2703
- ) -> ( HirVec < P < hir:: Pat < ' hir > > > , Option < usize > ) {
2710
+ ) -> ( & ' hir [ & ' hir hir :: Pat < ' hir > ] , Option < usize > ) {
2704
2711
let mut elems = Vec :: with_capacity ( pats. len ( ) ) ;
2705
2712
let mut rest = None ;
2706
2713
@@ -2728,7 +2735,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2728
2735
}
2729
2736
}
2730
2737
2731
- ( elems . into ( ) , rest. map ( |( ddpos, _) | ddpos) )
2738
+ ( self . arena . alloc_from_iter ( elems ) , rest. map ( |( ddpos, _) | ddpos) )
2732
2739
}
2733
2740
2734
2741
/// Lower a slice pattern of form `[pat_0, ..., pat_n]` into
@@ -2788,15 +2795,19 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2788
2795
}
2789
2796
}
2790
2797
2791
- hir:: PatKind :: Slice ( before. into ( ) , slice, after. into ( ) )
2798
+ hir:: PatKind :: Slice (
2799
+ self . arena . alloc_from_iter ( before) ,
2800
+ slice,
2801
+ self . arena . alloc_from_iter ( after) ,
2802
+ )
2792
2803
}
2793
2804
2794
2805
fn lower_pat_ident (
2795
2806
& mut self ,
2796
2807
p : & Pat ,
2797
2808
binding_mode : & BindingMode ,
2798
2809
ident : Ident ,
2799
- lower_sub : impl FnOnce ( & mut Self ) -> Option < P < hir:: Pat < ' hir > > > ,
2810
+ lower_sub : impl FnOnce ( & mut Self ) -> Option < & ' hir hir :: Pat < ' hir > > ,
2800
2811
) -> hir:: PatKind < ' hir > {
2801
2812
match self . resolver . get_partial_res ( p. id ) . map ( |d| d. base_res ( ) ) {
2802
2813
// `None` can occur in body-less function signatures
@@ -2824,13 +2835,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2824
2835
}
2825
2836
}
2826
2837
2827
- fn pat_wild_with_node_id_of ( & mut self , p : & Pat ) -> P < hir:: Pat < ' hir > > {
2838
+ fn pat_wild_with_node_id_of ( & mut self , p : & Pat ) -> & ' hir hir :: Pat < ' hir > {
2828
2839
self . pat_with_node_id_of ( p, hir:: PatKind :: Wild )
2829
2840
}
2830
2841
2831
2842
/// Construct a `Pat` with the `HirId` of `p.id` lowered.
2832
- fn pat_with_node_id_of ( & mut self , p : & Pat , kind : hir:: PatKind < ' hir > ) -> P < hir:: Pat < ' hir > > {
2833
- P ( hir:: Pat { hir_id : self . lower_node_id ( p. id ) , kind, span : p. span } )
2843
+ fn pat_with_node_id_of ( & mut self , p : & Pat , kind : hir:: PatKind < ' hir > ) -> & ' hir hir :: Pat < ' hir > {
2844
+ self . arena . alloc ( hir:: Pat { hir_id : self . lower_node_id ( p. id ) , kind, span : p. span } )
2834
2845
}
2835
2846
2836
2847
/// Emit a friendly error for extra `..` patterns in a tuple/tuple struct/slice pattern.
@@ -2883,7 +2894,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2883
2894
ids. push ( {
2884
2895
hir:: Stmt {
2885
2896
hir_id : self . lower_node_id ( s. id ) ,
2886
- kind : hir:: StmtKind :: Local ( P ( l) ) ,
2897
+ kind : hir:: StmtKind :: Local ( self . arena . alloc ( l) ) ,
2887
2898
span : s. span ,
2888
2899
}
2889
2900
} ) ;
@@ -2905,8 +2916,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2905
2916
} )
2906
2917
. collect ( ) ;
2907
2918
}
2908
- StmtKind :: Expr ( ref e) => hir:: StmtKind :: Expr ( P ( self . lower_expr ( e) ) ) ,
2909
- StmtKind :: Semi ( ref e) => hir:: StmtKind :: Semi ( P ( self . lower_expr ( e) ) ) ,
2919
+ StmtKind :: Expr ( ref e) => hir:: StmtKind :: Expr ( self . arena . alloc ( self . lower_expr ( e) ) ) ,
2920
+ StmtKind :: Semi ( ref e) => hir:: StmtKind :: Semi ( self . arena . alloc ( self . lower_expr ( e) ) ) ,
2910
2921
StmtKind :: Mac ( ..) => panic ! ( "shouldn't exist here" ) ,
2911
2922
} ;
2912
2923
smallvec ! [ hir:: Stmt { hir_id: self . lower_node_id( s. id) , kind, span: s. span } ]
@@ -2949,30 +2960,30 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2949
2960
}
2950
2961
2951
2962
fn stmt_expr ( & mut self , span : Span , expr : hir:: Expr < ' hir > ) -> hir:: Stmt < ' hir > {
2952
- self . stmt ( span, hir:: StmtKind :: Expr ( P ( expr) ) )
2963
+ self . stmt ( span, hir:: StmtKind :: Expr ( self . arena . alloc ( expr) ) )
2953
2964
}
2954
2965
2955
2966
fn stmt_let_pat (
2956
2967
& mut self ,
2957
2968
attrs : AttrVec ,
2958
2969
span : Span ,
2959
- init : Option < P < hir:: Expr < ' hir > > > ,
2960
- pat : P < hir:: Pat < ' hir > > ,
2970
+ init : Option < & ' hir hir :: Expr < ' hir > > ,
2971
+ pat : & ' hir hir :: Pat < ' hir > ,
2961
2972
source : hir:: LocalSource ,
2962
2973
) -> hir:: Stmt < ' hir > {
2963
2974
let local = hir:: Local { attrs, hir_id : self . next_id ( ) , init, pat, source, span, ty : None } ;
2964
- self . stmt ( span, hir:: StmtKind :: Local ( P ( local) ) )
2975
+ self . stmt ( span, hir:: StmtKind :: Local ( self . arena . alloc ( local) ) )
2965
2976
}
2966
2977
2967
- fn block_expr ( & mut self , expr : P < hir:: Expr < ' hir > > ) -> hir:: Block < ' hir > {
2968
- self . block_all ( expr. span , hir :: HirVec :: new ( ) , Some ( expr) )
2978
+ fn block_expr ( & mut self , expr : & ' hir hir :: Expr < ' hir > ) -> hir:: Block < ' hir > {
2979
+ self . block_all ( expr. span , & [ ] , Some ( expr) )
2969
2980
}
2970
2981
2971
2982
fn block_all (
2972
2983
& mut self ,
2973
2984
span : Span ,
2974
- stmts : hir:: HirVec < hir:: Stmt < ' hir > > ,
2975
- expr : Option < P < hir:: Expr < ' hir > > > ,
2985
+ stmts : & ' hir [ hir:: Stmt < ' hir > ] ,
2986
+ expr : Option < & ' hir hir :: Expr < ' hir > > ,
2976
2987
) -> hir:: Block < ' hir > {
2977
2988
hir:: Block {
2978
2989
stmts,
@@ -2985,33 +2996,33 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2985
2996
}
2986
2997
2987
2998
/// Constructs a `true` or `false` literal pattern.
2988
- fn pat_bool ( & mut self , span : Span , val : bool ) -> P < hir:: Pat < ' hir > > {
2999
+ fn pat_bool ( & mut self , span : Span , val : bool ) -> & ' hir hir :: Pat < ' hir > {
2989
3000
let expr = self . expr_bool ( span, val) ;
2990
- self . pat ( span, hir:: PatKind :: Lit ( P ( expr) ) )
3001
+ self . pat ( span, hir:: PatKind :: Lit ( self . arena . alloc ( expr) ) )
2991
3002
}
2992
3003
2993
- fn pat_ok ( & mut self , span : Span , pat : P < hir:: Pat < ' hir > > ) -> P < hir:: Pat < ' hir > > {
2994
- self . pat_std_enum ( span, & [ sym:: result, sym:: Result , sym:: Ok ] , hir_vec ! [ pat] )
3004
+ fn pat_ok ( & mut self , span : Span , pat : & ' hir hir :: Pat < ' hir > ) -> & ' hir hir :: Pat < ' hir > {
3005
+ self . pat_std_enum ( span, & [ sym:: result, sym:: Result , sym:: Ok ] , arena_vec ! [ self ; pat] )
2995
3006
}
2996
3007
2997
- fn pat_err ( & mut self , span : Span , pat : P < hir:: Pat < ' hir > > ) -> P < hir:: Pat < ' hir > > {
2998
- self . pat_std_enum ( span, & [ sym:: result, sym:: Result , sym:: Err ] , hir_vec ! [ pat] )
3008
+ fn pat_err ( & mut self , span : Span , pat : & ' hir hir :: Pat < ' hir > ) -> & ' hir hir :: Pat < ' hir > {
3009
+ self . pat_std_enum ( span, & [ sym:: result, sym:: Result , sym:: Err ] , arena_vec ! [ self ; pat] )
2999
3010
}
3000
3011
3001
- fn pat_some ( & mut self , span : Span , pat : P < hir:: Pat < ' hir > > ) -> P < hir:: Pat < ' hir > > {
3002
- self . pat_std_enum ( span, & [ sym:: option, sym:: Option , sym:: Some ] , hir_vec ! [ pat] )
3012
+ fn pat_some ( & mut self , span : Span , pat : & ' hir hir :: Pat < ' hir > ) -> & ' hir hir :: Pat < ' hir > {
3013
+ self . pat_std_enum ( span, & [ sym:: option, sym:: Option , sym:: Some ] , arena_vec ! [ self ; pat] )
3003
3014
}
3004
3015
3005
- fn pat_none ( & mut self , span : Span ) -> P < hir:: Pat < ' hir > > {
3006
- self . pat_std_enum ( span, & [ sym:: option, sym:: Option , sym:: None ] , hir_vec ! [ ] )
3016
+ fn pat_none ( & mut self , span : Span ) -> & ' hir hir :: Pat < ' hir > {
3017
+ self . pat_std_enum ( span, & [ sym:: option, sym:: Option , sym:: None ] , & [ ] )
3007
3018
}
3008
3019
3009
3020
fn pat_std_enum (
3010
3021
& mut self ,
3011
3022
span : Span ,
3012
3023
components : & [ Symbol ] ,
3013
- subpats : hir:: HirVec < P < hir:: Pat < ' hir > > > ,
3014
- ) -> P < hir:: Pat < ' hir > > {
3024
+ subpats : & ' hir [ & ' hir hir :: Pat < ' hir > ] ,
3025
+ ) -> & ' hir hir :: Pat < ' hir > {
3015
3026
let path = self . std_path ( span, components, None , true ) ;
3016
3027
let qpath = hir:: QPath :: Resolved ( None , P ( path) ) ;
3017
3028
let pt = if subpats. is_empty ( ) {
@@ -3022,7 +3033,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3022
3033
self . pat ( span, pt)
3023
3034
}
3024
3035
3025
- fn pat_ident ( & mut self , span : Span , ident : Ident ) -> ( P < hir:: Pat < ' hir > > , hir:: HirId ) {
3036
+ fn pat_ident ( & mut self , span : Span , ident : Ident ) -> ( & ' hir hir :: Pat < ' hir > , hir:: HirId ) {
3026
3037
self . pat_ident_binding_mode ( span, ident, hir:: BindingAnnotation :: Unannotated )
3027
3038
}
3028
3039
@@ -3031,11 +3042,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3031
3042
span : Span ,
3032
3043
ident : Ident ,
3033
3044
bm : hir:: BindingAnnotation ,
3034
- ) -> ( P < hir:: Pat < ' hir > > , hir:: HirId ) {
3045
+ ) -> ( & ' hir hir :: Pat < ' hir > , hir:: HirId ) {
3035
3046
let hir_id = self . next_id ( ) ;
3036
3047
3037
3048
(
3038
- P ( hir:: Pat {
3049
+ self . arena . alloc ( hir:: Pat {
3039
3050
hir_id,
3040
3051
kind : hir:: PatKind :: Binding ( bm, hir_id, ident. with_span_pos ( span) , None ) ,
3041
3052
span,
@@ -3044,12 +3055,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3044
3055
)
3045
3056
}
3046
3057
3047
- fn pat_wild ( & mut self , span : Span ) -> P < hir:: Pat < ' hir > > {
3058
+ fn pat_wild ( & mut self , span : Span ) -> & ' hir hir :: Pat < ' hir > {
3048
3059
self . pat ( span, hir:: PatKind :: Wild )
3049
3060
}
3050
3061
3051
- fn pat ( & mut self , span : Span , kind : hir:: PatKind < ' hir > ) -> P < hir:: Pat < ' hir > > {
3052
- P ( hir:: Pat { hir_id : self . next_id ( ) , kind, span } )
3062
+ fn pat ( & mut self , span : Span , kind : hir:: PatKind < ' hir > ) -> & ' hir hir :: Pat < ' hir > {
3063
+ self . arena . alloc ( hir:: Pat { hir_id : self . next_id ( ) , kind, span } )
3053
3064
}
3054
3065
3055
3066
/// Given a suffix `["b", "c", "d"]`, returns path `::std::b::c::d` when
0 commit comments