@@ -259,7 +259,7 @@ pub struct Substructure<'a> {
259
259
}
260
260
261
261
/// Summary of the relevant parts of a struct/enum field.
262
- pub struct FieldInfo {
262
+ pub struct FieldInfo < ' a > {
263
263
pub span : Span ,
264
264
/// None for tuple structs/normal enum variants, Some for normal
265
265
/// structs/struct enum variants.
@@ -270,6 +270,8 @@ pub struct FieldInfo {
270
270
/// The expressions corresponding to references to this field in
271
271
/// the other Self arguments.
272
272
pub other : Vec < Gc < Expr > > ,
273
+ /// The attributes attached to this field.
274
+ pub attrs : & ' a [ ast:: Attribute ] ,
273
275
}
274
276
275
277
/// Fields for a static method
@@ -283,13 +285,13 @@ pub enum StaticFields {
283
285
/// A summary of the possible sets of fields. See above for details
284
286
/// and examples
285
287
pub enum SubstructureFields < ' a > {
286
- Struct ( Vec < FieldInfo > ) ,
288
+ Struct ( Vec < FieldInfo < ' a > > ) ,
287
289
/**
288
290
Matching variants of the enum: variant index, ast::Variant,
289
291
fields: the field name is only non-`None` in the case of a struct
290
292
variant.
291
293
*/
292
- EnumMatching ( uint , & ' a ast:: Variant , Vec < FieldInfo > ) ,
294
+ EnumMatching ( uint , & ' a ast:: Variant , Vec < FieldInfo < ' a > > ) ,
293
295
294
296
/**
295
297
non-matching variants of the enum, but with all state hidden from
@@ -472,11 +474,11 @@ impl<'a> TraitDef<'a> {
472
474
} ) . collect ( ) ) )
473
475
}
474
476
475
- fn expand_struct_def ( & self ,
476
- cx : & mut ExtCtxt ,
477
- struct_def : & StructDef ,
478
- type_ident : Ident ,
479
- generics : & Generics ) -> Gc < ast:: Item > {
477
+ fn expand_struct_def < ' b > ( & self ,
478
+ cx : & mut ExtCtxt ,
479
+ struct_def : & ' b StructDef ,
480
+ type_ident : Ident ,
481
+ generics : & Generics ) -> Gc < ast:: Item > {
480
482
let methods = self . methods . iter ( ) . map ( |method_def| {
481
483
let ( explicit_self, self_args, nonself_args, tys) =
482
484
method_def. split_self_nonself_args (
@@ -512,11 +514,11 @@ impl<'a> TraitDef<'a> {
512
514
self . create_derived_impl ( cx, type_ident, generics, methods)
513
515
}
514
516
515
- fn expand_enum_def ( & self ,
516
- cx : & mut ExtCtxt ,
517
- enum_def : & EnumDef ,
518
- type_ident : Ident ,
519
- generics : & Generics ) -> Gc < ast:: Item > {
517
+ fn expand_enum_def < ' b > ( & self ,
518
+ cx : & mut ExtCtxt ,
519
+ enum_def : & ' b EnumDef ,
520
+ type_ident : Ident ,
521
+ generics : & Generics ) -> Gc < ast:: Item > {
520
522
let methods = self . methods . iter ( ) . map ( |method_def| {
521
523
let ( explicit_self, self_args, nonself_args, tys) =
522
524
method_def. split_self_nonself_args ( cx, self ,
@@ -563,13 +565,13 @@ fn variant_to_pat(cx: &mut ExtCtxt, sp: Span, variant: &ast::Variant)
563
565
}
564
566
565
567
impl < ' a > MethodDef < ' a > {
566
- fn call_substructure_method ( & self ,
567
- cx : & mut ExtCtxt ,
568
- trait_ : & TraitDef ,
569
- type_ident : Ident ,
570
- self_args : & [ Gc < Expr > ] ,
571
- nonself_args : & [ Gc < Expr > ] ,
572
- fields : SubstructureFields )
568
+ fn call_substructure_method < ' b > ( & self ,
569
+ cx : & mut ExtCtxt ,
570
+ trait_ : & TraitDef ,
571
+ type_ident : Ident ,
572
+ self_args : & ' b [ Gc < Expr > ] ,
573
+ nonself_args : & ' b [ Gc < Expr > ] ,
574
+ fields : SubstructureFields < ' b > )
573
575
-> Gc < Expr > {
574
576
let substructure = Substructure {
575
577
type_ident : type_ident,
@@ -715,13 +717,13 @@ impl<'a> MethodDef<'a> {
715
717
}
716
718
~~~
717
719
*/
718
- fn expand_struct_method_body ( & self ,
719
- cx : & mut ExtCtxt ,
720
- trait_ : & TraitDef ,
721
- struct_def : & StructDef ,
722
- type_ident : Ident ,
723
- self_args : & [ Gc < Expr > ] ,
724
- nonself_args : & [ Gc < Expr > ] )
720
+ fn expand_struct_method_body < ' b > ( & self ,
721
+ cx : & mut ExtCtxt ,
722
+ trait_ : & TraitDef ,
723
+ struct_def : & ' b StructDef ,
724
+ type_ident : Ident ,
725
+ self_args : & ' b [ Gc < Expr > ] ,
726
+ nonself_args : & ' b [ Gc < Expr > ] )
725
727
-> Gc < Expr > {
726
728
727
729
let mut raw_fields = Vec :: new ( ) ; // ~[[fields of self],
@@ -744,17 +746,18 @@ impl<'a> MethodDef<'a> {
744
746
raw_fields. get ( 0 )
745
747
. iter ( )
746
748
. enumerate ( )
747
- . map ( |( i, & ( span, opt_id, field) ) | {
749
+ . map ( |( i, & ( span, opt_id, field, attrs ) ) | {
748
750
let other_fields = raw_fields. tail ( ) . iter ( ) . map ( |l| {
749
751
match l. get ( i) {
750
- & ( _, _, ex) => ex
752
+ & ( _, _, ex, _ ) => ex
751
753
}
752
754
} ) . collect ( ) ;
753
755
FieldInfo {
754
756
span : span,
755
757
name : opt_id,
756
758
self_ : field,
757
- other : other_fields
759
+ other : other_fields,
760
+ attrs : attrs,
758
761
}
759
762
} ) . collect ( )
760
763
} else {
@@ -782,13 +785,13 @@ impl<'a> MethodDef<'a> {
782
785
body
783
786
}
784
787
785
- fn expand_static_struct_method_body ( & self ,
786
- cx : & mut ExtCtxt ,
787
- trait_ : & TraitDef ,
788
- struct_def : & StructDef ,
789
- type_ident : Ident ,
790
- self_args : & [ Gc < Expr > ] ,
791
- nonself_args : & [ Gc < Expr > ] )
788
+ fn expand_static_struct_method_body < ' b > ( & self ,
789
+ cx : & mut ExtCtxt ,
790
+ trait_ : & TraitDef ,
791
+ struct_def : & ' b StructDef ,
792
+ type_ident : Ident ,
793
+ self_args : & [ Gc < Expr > ] ,
794
+ nonself_args : & [ Gc < Expr > ] )
792
795
-> Gc < Expr > {
793
796
let summary = trait_. summarise_struct ( cx, struct_def) ;
794
797
@@ -830,14 +833,14 @@ impl<'a> MethodDef<'a> {
830
833
as their results are unused. The point of `__self_vi` and
831
834
`__arg_1_vi` is for `PartialOrd`; see #15503.)
832
835
*/
833
- fn expand_enum_method_body ( & self ,
834
- cx : & mut ExtCtxt ,
835
- trait_ : & TraitDef ,
836
- enum_def : & EnumDef ,
837
- type_ident : Ident ,
838
- self_args : & [ Gc < Expr > ] ,
839
- nonself_args : & [ Gc < Expr > ] )
840
- -> Gc < Expr > {
836
+ fn expand_enum_method_body < ' b > ( & self ,
837
+ cx : & mut ExtCtxt ,
838
+ trait_ : & TraitDef ,
839
+ enum_def : & ' b EnumDef ,
840
+ type_ident : Ident ,
841
+ self_args : & [ Gc < Expr > ] ,
842
+ nonself_args : & [ Gc < Expr > ] )
843
+ -> Gc < Expr > {
841
844
self . build_enum_match_tuple (
842
845
cx, trait_, enum_def, type_ident, self_args, nonself_args)
843
846
}
@@ -870,14 +873,14 @@ impl<'a> MethodDef<'a> {
870
873
}
871
874
~~~
872
875
*/
873
- fn build_enum_match_tuple (
874
- & self ,
875
- cx : & mut ExtCtxt ,
876
- trait_ : & TraitDef ,
877
- enum_def : & EnumDef ,
878
- type_ident : Ident ,
879
- self_args : & [ Gc < Expr > ] ,
880
- nonself_args : & [ Gc < Expr > ] ) -> Gc < Expr > {
876
+ fn build_enum_match_tuple < ' b > ( & self ,
877
+ cx : & mut ExtCtxt ,
878
+ trait_ : & TraitDef ,
879
+ enum_def : & ' b EnumDef ,
880
+ type_ident : Ident ,
881
+ self_args : & [ Gc < Expr > ] ,
882
+ nonself_args : & [ Gc < Expr > ] )
883
+ -> Gc < Expr > {
881
884
882
885
let sp = trait_. span ;
883
886
let variants = & enum_def. variants ;
@@ -920,7 +923,7 @@ impl<'a> MethodDef<'a> {
920
923
921
924
// These self_pats have form Variant1, Variant2, ...
922
925
let self_pats : Vec < ( Gc < ast:: Pat > ,
923
- Vec < ( Span , Option < Ident > , Gc < Expr > ) > ) > ;
926
+ Vec < ( Span , Option < Ident > , Gc < Expr > , & [ ast :: Attribute ] ) > ) > ;
924
927
self_pats = self_arg_names. iter ( )
925
928
. map ( |self_arg_name|
926
929
trait_. create_enum_variant_pattern (
@@ -954,7 +957,7 @@ impl<'a> MethodDef<'a> {
954
957
955
958
field_tuples = self_arg_fields. iter ( ) . enumerate ( )
956
959
// For each arg field of self, pull out its getter expr ...
957
- . map ( |( field_index, & ( sp, opt_ident, self_getter_expr) ) | {
960
+ . map ( |( field_index, & ( sp, opt_ident, self_getter_expr, attrs ) ) | {
958
961
// ... but FieldInfo also wants getter expr
959
962
// for matching other arguments of Self type;
960
963
// so walk across the *other* self_pats and
@@ -964,7 +967,7 @@ impl<'a> MethodDef<'a> {
964
967
let others = self_pats. tail ( ) . iter ( )
965
968
. map ( |& ( _pat, ref fields) | {
966
969
967
- let & ( _, _opt_ident, other_getter_expr) =
970
+ let & ( _, _opt_ident, other_getter_expr, _ ) =
968
971
fields. get ( field_index) ;
969
972
970
973
// All Self args have same variant, so
@@ -980,6 +983,7 @@ impl<'a> MethodDef<'a> {
980
983
name : opt_ident,
981
984
self_ : self_getter_expr,
982
985
other : others,
986
+ attrs : attrs,
983
987
}
984
988
} ) . collect :: < Vec < FieldInfo > > ( ) ;
985
989
@@ -1132,13 +1136,13 @@ impl<'a> MethodDef<'a> {
1132
1136
cx. expr_match ( sp, match_arg, match_arms)
1133
1137
}
1134
1138
1135
- fn expand_static_enum_method_body ( & self ,
1136
- cx : & mut ExtCtxt ,
1137
- trait_ : & TraitDef ,
1138
- enum_def : & EnumDef ,
1139
- type_ident : Ident ,
1140
- self_args : & [ Gc < Expr > ] ,
1141
- nonself_args : & [ Gc < Expr > ] )
1139
+ fn expand_static_enum_method_body < ' b > ( & self ,
1140
+ cx : & mut ExtCtxt ,
1141
+ trait_ : & TraitDef ,
1142
+ enum_def : & ' b EnumDef ,
1143
+ type_ident : Ident ,
1144
+ self_args : & [ Gc < Expr > ] ,
1145
+ nonself_args : & [ Gc < Expr > ] )
1142
1146
-> Gc < Expr > {
1143
1147
let summary = enum_def. variants . iter ( ) . map ( |v| {
1144
1148
let ident = v. node . name ;
@@ -1218,13 +1222,13 @@ impl<'a> TraitDef<'a> {
1218
1222
} ) . collect ( )
1219
1223
}
1220
1224
1221
- fn create_struct_pattern ( & self ,
1222
- cx : & mut ExtCtxt ,
1223
- struct_ident : Ident ,
1224
- struct_def : & StructDef ,
1225
- prefix : & str ,
1226
- mutbl : ast:: Mutability )
1227
- -> ( Gc < ast:: Pat > , Vec < ( Span , Option < Ident > , Gc < Expr > ) > ) {
1225
+ fn create_struct_pattern < ' b > ( & self ,
1226
+ cx : & mut ExtCtxt ,
1227
+ struct_ident : Ident ,
1228
+ struct_def : & ' b StructDef ,
1229
+ prefix : & str ,
1230
+ mutbl : ast:: Mutability )
1231
+ -> ( Gc < ast:: Pat > , Vec < ( Span , Option < Ident > , Gc < Expr > , & ' b [ ast :: Attribute ] ) > ) {
1228
1232
if struct_def. fields . is_empty ( ) {
1229
1233
return (
1230
1234
cx. pat_ident_binding_mode (
@@ -1259,15 +1263,15 @@ impl<'a> TraitDef<'a> {
1259
1263
paths. push ( codemap:: Spanned { span : sp, node : ident} ) ;
1260
1264
let val = cx. expr (
1261
1265
sp, ast:: ExprParen ( cx. expr_deref ( sp, cx. expr_path ( cx. path_ident ( sp, ident) ) ) ) ) ;
1262
- ident_expr. push ( ( sp, opt_id, val) ) ;
1266
+ ident_expr. push ( ( sp, opt_id, val, struct_field . node . attrs . as_slice ( ) ) ) ;
1263
1267
}
1264
1268
1265
1269
let subpats = self . create_subpatterns ( cx, paths, mutbl) ;
1266
1270
1267
1271
// struct_type is definitely not Unknown, since struct_def.fields
1268
1272
// must be nonempty to reach here
1269
1273
let pattern = if struct_type == Record {
1270
- let field_pats = subpats. iter ( ) . zip ( ident_expr. iter ( ) ) . map ( |( & pat, & ( _, id, _) ) | {
1274
+ let field_pats = subpats. iter ( ) . zip ( ident_expr. iter ( ) ) . map ( |( & pat, & ( _, id, _, _ ) ) | {
1271
1275
// id is guaranteed to be Some
1272
1276
ast:: FieldPat { ident : id. unwrap ( ) , pat : pat }
1273
1277
} ) . collect ( ) ;
@@ -1279,12 +1283,12 @@ impl<'a> TraitDef<'a> {
1279
1283
( pattern, ident_expr)
1280
1284
}
1281
1285
1282
- fn create_enum_variant_pattern ( & self ,
1283
- cx : & mut ExtCtxt ,
1284
- variant : & ast:: Variant ,
1285
- prefix : & str ,
1286
- mutbl : ast:: Mutability )
1287
- -> ( Gc < ast:: Pat > , Vec < ( Span , Option < Ident > , Gc < Expr > ) > ) {
1286
+ fn create_enum_variant_pattern < ' a > ( & self ,
1287
+ cx : & mut ExtCtxt ,
1288
+ variant : & ' a ast:: Variant ,
1289
+ prefix : & str ,
1290
+ mutbl : ast:: Mutability )
1291
+ -> ( Gc < ast:: Pat > , Vec < ( Span , Option < Ident > , Gc < Expr > , & ' a [ ast :: Attribute ] ) > ) {
1288
1292
let variant_ident = variant. node . name ;
1289
1293
match variant. node . kind {
1290
1294
ast:: TupleVariantKind ( ref variant_args) => {
@@ -1305,7 +1309,7 @@ impl<'a> TraitDef<'a> {
1305
1309
paths. push ( path1) ;
1306
1310
let expr_path = cx. expr_path ( cx. path_ident ( sp, ident) ) ;
1307
1311
let val = cx. expr ( sp, ast:: ExprParen ( cx. expr_deref ( sp, expr_path) ) ) ;
1308
- ident_expr. push ( ( sp, None , val) ) ;
1312
+ ident_expr. push ( ( sp, None , val, variant . node . attrs . as_slice ( ) ) ) ;
1309
1313
}
1310
1314
1311
1315
let subpats = self . create_subpatterns ( cx, paths, mutbl) ;
0 commit comments