@@ -270,7 +270,7 @@ pub struct Substructure<'a> {
270
270
}
271
271
272
272
/// Summary of the relevant parts of a struct/enum field.
273
- pub struct FieldInfo {
273
+ pub struct FieldInfo < ' a > {
274
274
pub span : Span ,
275
275
/// None for tuple structs/normal enum variants, Some for normal
276
276
/// structs/struct enum variants.
@@ -281,6 +281,8 @@ pub struct FieldInfo {
281
281
/// The expressions corresponding to references to this field in
282
282
/// the other `Self` arguments.
283
283
pub other : Vec < P < Expr > > ,
284
+ /// The attributes on the field
285
+ pub attrs : & ' a [ ast:: Attribute ] ,
284
286
}
285
287
286
288
/// Fields for a static method
@@ -293,11 +295,11 @@ pub enum StaticFields {
293
295
294
296
/// A summary of the possible sets of fields.
295
297
pub enum SubstructureFields < ' a > {
296
- Struct ( Vec < FieldInfo > ) ,
298
+ Struct ( Vec < FieldInfo < ' a > > ) ,
297
299
/// Matching variants of the enum: variant index, ast::Variant,
298
300
/// fields: the field name is only non-`None` in the case of a struct
299
301
/// variant.
300
- EnumMatching ( usize , & ' a ast:: Variant , Vec < FieldInfo > ) ,
302
+ EnumMatching ( usize , & ' a ast:: Variant , Vec < FieldInfo < ' a > > ) ,
301
303
302
304
/// Non-matching variants of the enum, but with all state hidden from
303
305
/// the consequent code. The first component holds `Ident`s for all of
@@ -378,7 +380,7 @@ impl<'a> TraitDef<'a> {
378
380
pub fn expand ( & self ,
379
381
cx : & mut ExtCtxt ,
380
382
mitem : & ast:: MetaItem ,
381
- item : & ast:: Item ,
383
+ item : & ' a ast:: Item ,
382
384
push : & mut FnMut ( P < ast:: Item > ) )
383
385
{
384
386
let newitem = match item. node {
@@ -609,7 +611,7 @@ impl<'a> TraitDef<'a> {
609
611
610
612
fn expand_struct_def ( & self ,
611
613
cx : & mut ExtCtxt ,
612
- struct_def : & StructDef ,
614
+ struct_def : & ' a StructDef ,
613
615
type_ident : Ident ,
614
616
generics : & Generics ) -> P < ast:: Item > {
615
617
let field_tys: Vec < P < ast:: Ty > > = struct_def. fields . iter ( )
@@ -653,7 +655,7 @@ impl<'a> TraitDef<'a> {
653
655
654
656
fn expand_enum_def ( & self ,
655
657
cx : & mut ExtCtxt ,
656
- enum_def : & EnumDef ,
658
+ enum_def : & ' a EnumDef ,
657
659
type_attrs : & [ ast:: Attribute ] ,
658
660
type_ident : Ident ,
659
661
generics : & Generics ) -> P < ast:: Item > {
@@ -885,10 +887,10 @@ impl<'a> MethodDef<'a> {
885
887
/// }
886
888
/// }
887
889
/// ```
888
- fn expand_struct_method_body ( & self ,
890
+ fn expand_struct_method_body < ' b > ( & self ,
889
891
cx : & mut ExtCtxt ,
890
- trait_ : & TraitDef ,
891
- struct_def : & StructDef ,
892
+ trait_ : & TraitDef < ' b > ,
893
+ struct_def : & ' b StructDef ,
892
894
type_ident : Ident ,
893
895
self_args : & [ P < Expr > ] ,
894
896
nonself_args : & [ P < Expr > ] )
@@ -914,18 +916,19 @@ impl<'a> MethodDef<'a> {
914
916
let fields = if !raw_fields. is_empty ( ) {
915
917
let mut raw_fields = raw_fields. into_iter ( ) . map ( |v| v. into_iter ( ) ) ;
916
918
let first_field = raw_fields. next ( ) . unwrap ( ) ;
917
- let mut other_fields: Vec < vec:: IntoIter < ( Span , Option < Ident > , P < Expr > ) > >
919
+ let mut other_fields: Vec < vec:: IntoIter < _ > >
918
920
= raw_fields. collect ( ) ;
919
- first_field. map ( |( span, opt_id, field) | {
921
+ first_field. map ( |( span, opt_id, field, attrs ) | {
920
922
FieldInfo {
921
923
span : span,
922
924
name : opt_id,
923
925
self_ : field,
924
926
other : other_fields. iter_mut ( ) . map ( |l| {
925
927
match l. next ( ) . unwrap ( ) {
926
- ( _, _, ex) => ex
928
+ ( _, _, ex, _ ) => ex
927
929
}
928
- } ) . collect ( )
930
+ } ) . collect ( ) ,
931
+ attrs : attrs,
929
932
}
930
933
} ) . collect ( )
931
934
} else {
@@ -999,10 +1002,10 @@ impl<'a> MethodDef<'a> {
999
1002
/// `PartialEq`, and those subcomputations will hopefully be removed
1000
1003
/// as their results are unused. The point of `__self_vi` and
1001
1004
/// `__arg_1_vi` is for `PartialOrd`; see #15503.)
1002
- fn expand_enum_method_body ( & self ,
1005
+ fn expand_enum_method_body < ' b > ( & self ,
1003
1006
cx : & mut ExtCtxt ,
1004
- trait_ : & TraitDef ,
1005
- enum_def : & EnumDef ,
1007
+ trait_ : & TraitDef < ' b > ,
1008
+ enum_def : & ' b EnumDef ,
1006
1009
type_attrs : & [ ast:: Attribute ] ,
1007
1010
type_ident : Ident ,
1008
1011
self_args : Vec < P < Expr > > ,
@@ -1038,11 +1041,11 @@ impl<'a> MethodDef<'a> {
1038
1041
/// }
1039
1042
/// }
1040
1043
/// ```
1041
- fn build_enum_match_tuple (
1044
+ fn build_enum_match_tuple < ' b > (
1042
1045
& self ,
1043
1046
cx : & mut ExtCtxt ,
1044
- trait_ : & TraitDef ,
1045
- enum_def : & EnumDef ,
1047
+ trait_ : & TraitDef < ' b > ,
1048
+ enum_def : & ' b EnumDef ,
1046
1049
type_attrs : & [ ast:: Attribute ] ,
1047
1050
type_ident : Ident ,
1048
1051
self_args : Vec < P < Expr > > ,
@@ -1125,15 +1128,15 @@ impl<'a> MethodDef<'a> {
1125
1128
// arg fields of the variant for the first self pat.
1126
1129
let field_tuples = first_self_pat_idents. into_iter ( ) . enumerate ( )
1127
1130
// For each arg field of self, pull out its getter expr ...
1128
- . map ( |( field_index, ( sp, opt_ident, self_getter_expr) ) | {
1131
+ . map ( |( field_index, ( sp, opt_ident, self_getter_expr, attrs ) ) | {
1129
1132
// ... but FieldInfo also wants getter expr
1130
1133
// for matching other arguments of Self type;
1131
1134
// so walk across the *other* self_pats_idents
1132
1135
// and pull out getter for same field in each
1133
1136
// of them (using `field_index` tracked above).
1134
1137
// That is the heart of the transposition.
1135
1138
let others = self_pats_idents. iter ( ) . map ( |fields| {
1136
- let ( _, _opt_ident, ref other_getter_expr) =
1139
+ let ( _, _opt_ident, ref other_getter_expr, _ ) =
1137
1140
fields[ field_index] ;
1138
1141
1139
1142
// All Self args have same variant, so
@@ -1149,6 +1152,7 @@ impl<'a> MethodDef<'a> {
1149
1152
name : opt_ident,
1150
1153
self_ : self_getter_expr,
1151
1154
other : others,
1155
+ attrs : attrs,
1152
1156
}
1153
1157
} ) . collect :: < Vec < FieldInfo > > ( ) ;
1154
1158
@@ -1400,10 +1404,12 @@ impl<'a> TraitDef<'a> {
1400
1404
fn create_struct_pattern ( & self ,
1401
1405
cx : & mut ExtCtxt ,
1402
1406
struct_path : ast:: Path ,
1403
- struct_def : & StructDef ,
1407
+ struct_def : & ' a StructDef ,
1404
1408
prefix : & str ,
1405
1409
mutbl : ast:: Mutability )
1406
- -> ( P < ast:: Pat > , Vec < ( Span , Option < Ident > , P < Expr > ) > ) {
1410
+ -> ( P < ast:: Pat > , Vec < ( Span , Option < Ident > ,
1411
+ P < Expr > ,
1412
+ & ' a [ ast:: Attribute ] ) > ) {
1407
1413
if struct_def. fields . is_empty ( ) {
1408
1414
return ( cx. pat_enum ( self . span , struct_path, vec ! [ ] ) , vec ! [ ] ) ;
1409
1415
}
@@ -1433,15 +1439,16 @@ impl<'a> TraitDef<'a> {
1433
1439
paths. push ( codemap:: Spanned { span : sp, node : ident} ) ;
1434
1440
let val = cx. expr (
1435
1441
sp, ast:: ExprParen ( cx. expr_deref ( sp, cx. expr_path ( cx. path_ident ( sp, ident) ) ) ) ) ;
1436
- ident_expr. push ( ( sp, opt_id, val) ) ;
1442
+ ident_expr. push ( ( sp, opt_id, val, & struct_field . node . attrs [ .. ] ) ) ;
1437
1443
}
1438
1444
1439
1445
let subpats = self . create_subpatterns ( cx, paths, mutbl) ;
1440
1446
1441
1447
// struct_type is definitely not Unknown, since struct_def.fields
1442
1448
// must be nonempty to reach here
1443
1449
let pattern = if struct_type == Record {
1444
- let field_pats = subpats. into_iter ( ) . zip ( ident_expr. iter ( ) ) . map ( |( pat, & ( _, id, _) ) | {
1450
+ let field_pats = subpats. into_iter ( ) . zip ( ident_expr. iter ( ) )
1451
+ . map ( |( pat, & ( _, id, _, _) ) | {
1445
1452
// id is guaranteed to be Some
1446
1453
codemap:: Spanned {
1447
1454
span : pat. span ,
@@ -1459,10 +1466,10 @@ impl<'a> TraitDef<'a> {
1459
1466
fn create_enum_variant_pattern ( & self ,
1460
1467
cx : & mut ExtCtxt ,
1461
1468
enum_ident : ast:: Ident ,
1462
- variant : & ast:: Variant ,
1469
+ variant : & ' a ast:: Variant ,
1463
1470
prefix : & str ,
1464
1471
mutbl : ast:: Mutability )
1465
- -> ( P < ast:: Pat > , Vec < ( Span , Option < Ident > , P < Expr > ) > ) {
1472
+ -> ( P < ast:: Pat > , Vec < ( Span , Option < Ident > , P < Expr > , & ' a [ ast :: Attribute ] ) > ) {
1466
1473
let variant_ident = variant. node . name ;
1467
1474
let variant_path = cx. path ( variant. span , vec ! [ enum_ident, variant_ident] ) ;
1468
1475
match variant. node . kind {
@@ -1472,15 +1479,15 @@ impl<'a> TraitDef<'a> {
1472
1479
}
1473
1480
1474
1481
let mut paths = Vec :: new ( ) ;
1475
- let mut ident_expr = Vec :: new ( ) ;
1482
+ let mut ident_expr: Vec < ( _ , _ , _ , & ' a [ ast :: Attribute ] ) > = Vec :: new ( ) ;
1476
1483
for ( i, va) in variant_args. iter ( ) . enumerate ( ) {
1477
1484
let sp = self . set_expn_info ( cx, va. ty . span ) ;
1478
1485
let ident = cx. ident_of ( & format ! ( "{}_{}" , prefix, i) ) ;
1479
1486
let path1 = codemap:: Spanned { span : sp, node : ident} ;
1480
1487
paths. push ( path1) ;
1481
1488
let expr_path = cx. expr_path ( cx. path_ident ( sp, ident) ) ;
1482
1489
let val = cx. expr ( sp, ast:: ExprParen ( cx. expr_deref ( sp, expr_path) ) ) ;
1483
- ident_expr. push ( ( sp, None , val) ) ;
1490
+ ident_expr. push ( ( sp, None , val, & [ ] ) ) ;
1484
1491
}
1485
1492
1486
1493
let subpats = self . create_subpatterns ( cx, paths, mutbl) ;
0 commit comments