@@ -483,7 +483,7 @@ impl<'a> LoweringContext<'a> {
483
483
visit:: walk_crate ( & mut ItemLowerer { lctx : & mut self } , c) ;
484
484
485
485
let module = self . lower_mod ( & c. module ) ;
486
- let attrs = self . lower_attrs ( & c. attrs ) ;
486
+ let attrs = self . lower_attrs ( & c. attrs ) . into ( ) ;
487
487
let body_ids = body_ids ( & self . bodies ) ;
488
488
489
489
self . resolver
@@ -1057,21 +1057,32 @@ impl<'a> LoweringContext<'a> {
1057
1057
}
1058
1058
}
1059
1059
1060
- fn lower_attrs ( & mut self , attrs : & [ Attribute ] ) -> hir:: HirVec < Attribute > {
1060
+ fn lower_attrs ( & mut self , attrs : & [ Attribute ] ) -> Vec < hir:: Attribute > {
1061
1061
attrs
1062
1062
. iter ( )
1063
1063
. map ( |a| self . lower_attr ( a) )
1064
1064
. collect ( )
1065
1065
}
1066
1066
1067
- fn lower_attr ( & mut self , attr : & Attribute ) -> Attribute {
1068
- // Note that we explicitly do not walk the path. Since we don't really
1069
- // lower attributes (we use the AST version) there is nowhere to keep
1070
- // the HirIds. We don't actually need HIR version of attributes anyway.
1071
- Attribute {
1067
+ fn lower_attr ( & mut self , attr : & Attribute ) -> hir:: Attribute {
1068
+ hir:: Attribute {
1072
1069
id : attr. id ,
1073
1070
style : attr. style ,
1074
- path : attr. path . clone ( ) ,
1071
+ // HACK(eddyb) manual conversion because `lower_path(_extra)`
1072
+ // use `lower_path_segment` and that allocates `ItemLocalId`s.
1073
+ path : hir:: Path {
1074
+ def : Def :: Err ,
1075
+ segments : attr. path . segments . iter ( ) . map ( |segment| {
1076
+ hir:: PathSegment :: new (
1077
+ segment. ident ,
1078
+ None ,
1079
+ None ,
1080
+ hir:: GenericArgs :: none ( ) ,
1081
+ false ,
1082
+ )
1083
+ } ) . collect ( ) ,
1084
+ span : attr. path . span ,
1085
+ } ,
1075
1086
tokens : self . lower_token_stream ( attr. tokens . clone ( ) ) ,
1076
1087
is_sugared_doc : attr. is_sugared_doc ,
1077
1088
span : attr. span ,
@@ -1110,7 +1121,7 @@ impl<'a> LoweringContext<'a> {
1110
1121
1111
1122
fn lower_arm ( & mut self , arm : & Arm ) -> hir:: Arm {
1112
1123
hir:: Arm {
1113
- attrs : self . lower_attrs ( & arm. attrs ) ,
1124
+ attrs : self . lower_attrs ( & arm. attrs ) . into ( ) ,
1114
1125
pats : arm. pats . iter ( ) . map ( |x| self . lower_pat ( x) ) . collect ( ) ,
1115
1126
guard : match arm. guard {
1116
1127
Some ( Guard :: If ( ref x) ) => Some ( hir:: Guard :: If ( P ( self . lower_expr ( x) ) ) ) ,
@@ -1576,7 +1587,7 @@ impl<'a> LoweringContext<'a> {
1576
1587
Spanned {
1577
1588
node : hir:: VariantKind {
1578
1589
name : v. node . ident . name ,
1579
- attrs : self . lower_attrs ( & v. node . attrs ) ,
1590
+ attrs : self . lower_attrs ( & v. node . attrs ) . into ( ) ,
1580
1591
data : self . lower_variant_data ( & v. node . data ) ,
1581
1592
disr_expr : v. node . disr_expr . as_ref ( ) . map ( |e| self . lower_anon_const ( e) ) ,
1582
1593
} ,
@@ -1967,7 +1978,7 @@ impl<'a> LoweringContext<'a> {
1967
1978
pat : self . lower_pat ( & l. pat ) ,
1968
1979
init : l. init . as_ref ( ) . map ( |e| P ( self . lower_expr ( e) ) ) ,
1969
1980
span : l. span ,
1970
- attrs : l. attrs . clone ( ) ,
1981
+ attrs : self . lower_attrs ( & l. attrs ) . into ( ) ,
1971
1982
source : hir:: LocalSource :: Normal ,
1972
1983
} ) , ids)
1973
1984
}
@@ -2410,7 +2421,7 @@ impl<'a> LoweringContext<'a> {
2410
2421
name : param_name,
2411
2422
span : lt. span ,
2412
2423
pure_wrt_drop : attr:: contains_name ( & param. attrs , "may_dangle" ) ,
2413
- attrs : self . lower_attrs ( & param. attrs ) ,
2424
+ attrs : self . lower_attrs ( & param. attrs ) . into ( ) ,
2414
2425
bounds,
2415
2426
kind : hir:: GenericParamKind :: Lifetime {
2416
2427
kind : hir:: LifetimeParamKind :: Explicit ,
@@ -2443,7 +2454,7 @@ impl<'a> LoweringContext<'a> {
2443
2454
id : self . lower_node_id ( param. id ) . node_id ,
2444
2455
name : hir:: ParamName :: Plain ( ident) ,
2445
2456
pure_wrt_drop : attr:: contains_name ( & param. attrs , "may_dangle" ) ,
2446
- attrs : self . lower_attrs ( & param. attrs ) ,
2457
+ attrs : self . lower_attrs ( & param. attrs ) . into ( ) ,
2447
2458
bounds,
2448
2459
span : ident. span ,
2449
2460
kind : hir:: GenericParamKind :: Type {
@@ -2667,7 +2678,7 @@ impl<'a> LoweringContext<'a> {
2667
2678
} ,
2668
2679
vis : self . lower_visibility ( & f. vis , None ) ,
2669
2680
ty : self . lower_ty ( & f. ty , ImplTraitContext :: disallowed ( ) ) ,
2670
- attrs : self . lower_attrs ( & f. attrs ) ,
2681
+ attrs : self . lower_attrs ( & f. attrs ) . into ( ) ,
2671
2682
}
2672
2683
}
2673
2684
@@ -2750,7 +2761,7 @@ impl<'a> LoweringContext<'a> {
2750
2761
& mut self ,
2751
2762
id : NodeId ,
2752
2763
name : & mut Name ,
2753
- attrs : & hir:: HirVec < Attribute > ,
2764
+ attrs : & hir:: HirVec < hir :: Attribute > ,
2754
2765
vis : & mut hir:: Visibility ,
2755
2766
i : & ItemKind ,
2756
2767
) -> hir:: ItemKind {
@@ -2956,7 +2967,7 @@ impl<'a> LoweringContext<'a> {
2956
2967
id : NodeId ,
2957
2968
vis : & mut hir:: Visibility ,
2958
2969
name : & mut Name ,
2959
- attrs : & hir:: HirVec < Attribute > ,
2970
+ attrs : & hir:: HirVec < hir :: Attribute > ,
2960
2971
) -> hir:: ItemKind {
2961
2972
debug ! ( "lower_use_tree(tree={:?})" , tree) ;
2962
2973
debug ! ( "lower_use_tree: vis = {:?}" , vis) ;
@@ -3257,7 +3268,7 @@ impl<'a> LoweringContext<'a> {
3257
3268
id : node_id,
3258
3269
hir_id,
3259
3270
ident : i. ident ,
3260
- attrs : self . lower_attrs ( & i. attrs ) ,
3271
+ attrs : self . lower_attrs ( & i. attrs ) . into ( ) ,
3261
3272
generics,
3262
3273
node,
3263
3274
span : i. span ,
@@ -3333,7 +3344,7 @@ impl<'a> LoweringContext<'a> {
3333
3344
id : node_id,
3334
3345
hir_id,
3335
3346
ident : i. ident ,
3336
- attrs : self . lower_attrs ( & i. attrs ) ,
3347
+ attrs : self . lower_attrs ( & i. attrs ) . into ( ) ,
3337
3348
generics,
3338
3349
vis : self . lower_visibility ( & i. vis , None ) ,
3339
3350
defaultness : self . lower_defaultness ( i. defaultness , true /* [1] */ ) ,
@@ -3427,7 +3438,7 @@ impl<'a> LoweringContext<'a> {
3427
3438
pub fn lower_item ( & mut self , i : & Item ) -> Option < hir:: Item > {
3428
3439
let mut name = i. ident . name ;
3429
3440
let mut vis = self . lower_visibility ( & i. vis , None ) ;
3430
- let attrs = self . lower_attrs ( & i. attrs ) ;
3441
+ let attrs = self . lower_attrs ( & i. attrs ) . into ( ) ;
3431
3442
if let ItemKind :: MacroDef ( ref def) = i. node {
3432
3443
if !def. legacy || attr:: contains_name ( & i. attrs , "macro_export" ) ||
3433
3444
attr:: contains_name ( & i. attrs , "rustc_doc_only_macro" ) {
@@ -3466,7 +3477,7 @@ impl<'a> LoweringContext<'a> {
3466
3477
hir:: ForeignItem {
3467
3478
id : node_id,
3468
3479
name : i. ident . name ,
3469
- attrs : self . lower_attrs ( & i. attrs ) ,
3480
+ attrs : self . lower_attrs ( & i. attrs ) . into ( ) ,
3470
3481
node : match i. node {
3471
3482
ForeignItemKind :: Fn ( ref fdec, ref generics) => {
3472
3483
let ( generics, ( fn_dec, fn_args) ) = self . add_in_band_defs (
@@ -4025,7 +4036,7 @@ impl<'a> LoweringContext<'a> {
4025
4036
hir:: ExprKind :: Struct ( struct_path, fields, None )
4026
4037
} ,
4027
4038
span : e. span ,
4028
- attrs : e. attrs . clone ( ) ,
4039
+ attrs : self . lower_attrs ( & e. attrs ) . into ( ) ,
4029
4040
} ;
4030
4041
}
4031
4042
ExprKind :: Path ( ref qself, ref path) => {
@@ -4111,7 +4122,7 @@ impl<'a> LoweringContext<'a> {
4111
4122
ex. span = e. span ;
4112
4123
}
4113
4124
// merge attributes into the inner expression.
4114
- let mut attrs = e. attrs . clone ( ) ;
4125
+ let mut attrs: ThinVec < _ > = self . lower_attrs ( & e. attrs ) . into ( ) ;
4115
4126
attrs. extend :: < Vec < _ > > ( ex. attrs . into ( ) ) ;
4116
4127
ex. attrs = attrs;
4117
4128
return ex;
@@ -4394,7 +4405,8 @@ impl<'a> LoweringContext<'a> {
4394
4405
let result = P ( self . expr_ident ( e. span , result_ident, let_stmt_binding) ) ;
4395
4406
let block = P ( self . block_all ( e. span , hir_vec ! [ let_stmt] , Some ( result) ) ) ;
4396
4407
// add the attributes to the outer returned expr node
4397
- return self . expr_block ( block, e. attrs . clone ( ) ) ;
4408
+ let attrs = self . lower_attrs ( & e. attrs ) . into ( ) ;
4409
+ return self . expr_block ( block, attrs) ;
4398
4410
}
4399
4411
4400
4412
// Desugar ExprKind::Try
@@ -4507,7 +4519,7 @@ impl<'a> LoweringContext<'a> {
4507
4519
hir_id,
4508
4520
node : kind,
4509
4521
span : e. span ,
4510
- attrs : e. attrs . clone ( ) ,
4522
+ attrs : self . lower_attrs ( & e. attrs ) . into ( ) ,
4511
4523
}
4512
4524
}
4513
4525
@@ -4685,7 +4697,7 @@ impl<'a> LoweringContext<'a> {
4685
4697
}
4686
4698
}
4687
4699
4688
- fn expr_break ( & mut self , span : Span , attrs : ThinVec < Attribute > ) -> P < hir:: Expr > {
4700
+ fn expr_break ( & mut self , span : Span , attrs : ThinVec < hir :: Attribute > ) -> P < hir:: Expr > {
4689
4701
let expr_break = hir:: ExprKind :: Break ( self . lower_loop_destination ( None ) , None ) ;
4690
4702
P ( self . expr ( span, expr_break, attrs) )
4691
4703
}
@@ -4708,7 +4720,7 @@ impl<'a> LoweringContext<'a> {
4708
4720
span : Span ,
4709
4721
ident : Ident ,
4710
4722
binding : NodeId ,
4711
- attrs : ThinVec < Attribute > ,
4723
+ attrs : ThinVec < hir :: Attribute > ,
4712
4724
) -> hir:: Expr {
4713
4725
let expr_path = hir:: ExprKind :: Path ( hir:: QPath :: Resolved (
4714
4726
None ,
@@ -4731,7 +4743,7 @@ impl<'a> LoweringContext<'a> {
4731
4743
span : Span ,
4732
4744
components : & [ & str ] ,
4733
4745
params : Option < P < hir:: GenericArgs > > ,
4734
- attrs : ThinVec < Attribute > ,
4746
+ attrs : ThinVec < hir :: Attribute > ,
4735
4747
) -> hir:: Expr {
4736
4748
let path = self . std_path ( span, components, params, true ) ;
4737
4749
self . expr (
@@ -4751,15 +4763,20 @@ impl<'a> LoweringContext<'a> {
4751
4763
self . expr ( span, hir:: ExprKind :: Match ( arg, arms, source) , ThinVec :: new ( ) )
4752
4764
}
4753
4765
4754
- fn expr_block ( & mut self , b : P < hir:: Block > , attrs : ThinVec < Attribute > ) -> hir:: Expr {
4766
+ fn expr_block ( & mut self , b : P < hir:: Block > , attrs : ThinVec < hir :: Attribute > ) -> hir:: Expr {
4755
4767
self . expr ( b. span , hir:: ExprKind :: Block ( b, None ) , attrs)
4756
4768
}
4757
4769
4758
4770
fn expr_tuple ( & mut self , sp : Span , exprs : hir:: HirVec < hir:: Expr > ) -> P < hir:: Expr > {
4759
4771
P ( self . expr ( sp, hir:: ExprKind :: Tup ( exprs) , ThinVec :: new ( ) ) )
4760
4772
}
4761
4773
4762
- fn expr ( & mut self , span : Span , node : hir:: ExprKind , attrs : ThinVec < Attribute > ) -> hir:: Expr {
4774
+ fn expr (
4775
+ & mut self ,
4776
+ span : Span ,
4777
+ node : hir:: ExprKind ,
4778
+ attrs : ThinVec < hir:: Attribute > ,
4779
+ ) -> hir:: Expr {
4763
4780
let LoweredNodeId { node_id, hir_id } = self . next_id ( ) ;
4764
4781
hir:: Expr {
4765
4782
id : node_id,
0 commit comments