@@ -220,14 +220,6 @@ pub struct Invocation {
220
220
pub expansion_data : ExpansionData ,
221
221
}
222
222
223
- // Needed for feature-gating attributes used after derives or together with test/bench
224
- #[ derive( Clone , Copy , PartialEq ) ]
225
- pub enum TogetherWith {
226
- None ,
227
- Derive ,
228
- TestBench ,
229
- }
230
-
231
223
pub enum InvocationKind {
232
224
Bang {
233
225
mac : ast:: Mac ,
@@ -238,7 +230,8 @@ pub enum InvocationKind {
238
230
attr : Option < ast:: Attribute > ,
239
231
traits : Vec < Path > ,
240
232
item : Annotatable ,
241
- together_with : TogetherWith ,
233
+ // We temporarily report errors for attribute macros placed after derives
234
+ after_derive : bool ,
242
235
} ,
243
236
Derive {
244
237
path : Path ,
@@ -1084,19 +1077,17 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
1084
1077
traits : Vec < Path > ,
1085
1078
item : Annotatable ,
1086
1079
kind : AstFragmentKind ,
1087
- together_with : TogetherWith )
1080
+ after_derive : bool )
1088
1081
-> AstFragment {
1089
- self . collect ( kind, InvocationKind :: Attr { attr, traits, item, together_with } )
1082
+ self . collect ( kind, InvocationKind :: Attr { attr, traits, item, after_derive } )
1090
1083
}
1091
1084
1092
- fn find_attr_invoc ( & self , attrs : & mut Vec < ast:: Attribute > , together_with : & mut TogetherWith )
1085
+ fn find_attr_invoc ( & self , attrs : & mut Vec < ast:: Attribute > , after_derive : & mut bool )
1093
1086
-> Option < ast:: Attribute > {
1094
1087
let attr = attrs. iter ( )
1095
1088
. position ( |a| {
1096
1089
if a. path == "derive" {
1097
- * together_with = TogetherWith :: Derive
1098
- } else if a. path == "rustc_test_marker2" {
1099
- * together_with = TogetherWith :: TestBench
1090
+ * after_derive = true ;
1100
1091
}
1101
1092
!attr:: is_known ( a) && !is_builtin_attr ( a)
1102
1093
} )
@@ -1109,19 +1100,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
1109
1100
"non-builtin inner attributes are unstable" ) ;
1110
1101
}
1111
1102
}
1112
- if together_with == & TogetherWith :: None &&
1113
- attrs. iter ( ) . any ( |a| a. path == "rustc_test_marker2" ) {
1114
- * together_with = TogetherWith :: TestBench ;
1115
- }
1116
1103
attr
1117
1104
}
1118
1105
1119
1106
/// If `item` is an attr invocation, remove and return the macro attribute and derive traits.
1120
1107
fn classify_item < T > ( & mut self , mut item : T )
1121
- -> ( Option < ast:: Attribute > , Vec < Path > , T , TogetherWith )
1108
+ -> ( Option < ast:: Attribute > , Vec < Path > , T , /* after_derive */ bool )
1122
1109
where T : HasAttrs ,
1123
1110
{
1124
- let ( mut attr, mut traits, mut together_with ) = ( None , Vec :: new ( ) , TogetherWith :: None ) ;
1111
+ let ( mut attr, mut traits, mut after_derive ) = ( None , Vec :: new ( ) , false ) ;
1125
1112
1126
1113
item = item. map_attrs ( |mut attrs| {
1127
1114
if let Some ( legacy_attr_invoc) = self . cx . resolver . find_legacy_attr_invoc ( & mut attrs,
@@ -1130,20 +1117,20 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
1130
1117
return attrs;
1131
1118
}
1132
1119
1133
- attr = self . find_attr_invoc ( & mut attrs, & mut together_with ) ;
1120
+ attr = self . find_attr_invoc ( & mut attrs, & mut after_derive ) ;
1134
1121
traits = collect_derives ( & mut self . cx , & mut attrs) ;
1135
1122
attrs
1136
1123
} ) ;
1137
1124
1138
- ( attr, traits, item, together_with )
1125
+ ( attr, traits, item, after_derive )
1139
1126
}
1140
1127
1141
1128
/// Alternative of `classify_item()` that ignores `#[derive]` so invocations fallthrough
1142
1129
/// to the unused-attributes lint (making it an error on statements and expressions
1143
1130
/// is a breaking change)
1144
1131
fn classify_nonitem < T : HasAttrs > ( & mut self , mut item : T )
1145
- -> ( Option < ast:: Attribute > , T , TogetherWith ) {
1146
- let ( mut attr, mut together_with ) = ( None , TogetherWith :: None ) ;
1132
+ -> ( Option < ast:: Attribute > , T , /* after_derive */ bool ) {
1133
+ let ( mut attr, mut after_derive ) = ( None , false ) ;
1147
1134
1148
1135
item = item. map_attrs ( |mut attrs| {
1149
1136
if let Some ( legacy_attr_invoc) = self . cx . resolver . find_legacy_attr_invoc ( & mut attrs,
@@ -1152,11 +1139,11 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
1152
1139
return attrs;
1153
1140
}
1154
1141
1155
- attr = self . find_attr_invoc ( & mut attrs, & mut together_with ) ;
1142
+ attr = self . find_attr_invoc ( & mut attrs, & mut after_derive ) ;
1156
1143
attrs
1157
1144
} ) ;
1158
1145
1159
- ( attr, item, together_with )
1146
+ ( attr, item, after_derive )
1160
1147
}
1161
1148
1162
1149
fn configure < T : HasAttrs > ( & mut self , node : T ) -> Option < T > {
@@ -1195,7 +1182,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1195
1182
expr. node = self . cfg . configure_expr_kind ( expr. node ) ;
1196
1183
1197
1184
// ignore derives so they remain unused
1198
- let ( attr, expr, together_with ) = self . classify_nonitem ( expr) ;
1185
+ let ( attr, expr, after_derive ) = self . classify_nonitem ( expr) ;
1199
1186
1200
1187
if attr. is_some ( ) {
1201
1188
// collect the invoc regardless of whether or not attributes are permitted here
@@ -1204,7 +1191,7 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1204
1191
1205
1192
// AstFragmentKind::Expr requires the macro to emit an expression
1206
1193
return self . collect_attr ( attr, vec ! [ ] , Annotatable :: Expr ( P ( expr) ) ,
1207
- AstFragmentKind :: Expr , together_with ) . make_expr ( ) ;
1194
+ AstFragmentKind :: Expr , after_derive ) . make_expr ( ) ;
1208
1195
}
1209
1196
1210
1197
if let ast:: ExprKind :: Mac ( mac) = expr. node {
@@ -1220,13 +1207,13 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1220
1207
expr. node = self . cfg . configure_expr_kind ( expr. node ) ;
1221
1208
1222
1209
// ignore derives so they remain unused
1223
- let ( attr, expr, together_with ) = self . classify_nonitem ( expr) ;
1210
+ let ( attr, expr, after_derive ) = self . classify_nonitem ( expr) ;
1224
1211
1225
1212
if attr. is_some ( ) {
1226
1213
attr. as_ref ( ) . map ( |a| self . cfg . maybe_emit_expr_attr_err ( a) ) ;
1227
1214
1228
1215
return self . collect_attr ( attr, vec ! [ ] , Annotatable :: Expr ( P ( expr) ) ,
1229
- AstFragmentKind :: OptExpr , together_with ) . make_opt_expr ( ) ;
1216
+ AstFragmentKind :: OptExpr , after_derive ) . make_opt_expr ( ) ;
1230
1217
}
1231
1218
1232
1219
if let ast:: ExprKind :: Mac ( mac) = expr. node {
@@ -1258,18 +1245,18 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1258
1245
1259
1246
// we'll expand attributes on expressions separately
1260
1247
if !stmt. is_expr ( ) {
1261
- let ( attr, derives, stmt_, together_with ) = if stmt. is_item ( ) {
1248
+ let ( attr, derives, stmt_, after_derive ) = if stmt. is_item ( ) {
1262
1249
self . classify_item ( stmt)
1263
1250
} else {
1264
1251
// ignore derives on non-item statements so it falls through
1265
1252
// to the unused-attributes lint
1266
- let ( attr, stmt, together_with ) = self . classify_nonitem ( stmt) ;
1267
- ( attr, vec ! [ ] , stmt, together_with )
1253
+ let ( attr, stmt, after_derive ) = self . classify_nonitem ( stmt) ;
1254
+ ( attr, vec ! [ ] , stmt, after_derive )
1268
1255
} ;
1269
1256
1270
1257
if attr. is_some ( ) || !derives. is_empty ( ) {
1271
1258
return self . collect_attr ( attr, derives, Annotatable :: Stmt ( P ( stmt_) ) ,
1272
- AstFragmentKind :: Stmts , together_with ) . make_stmts ( ) ;
1259
+ AstFragmentKind :: Stmts , after_derive ) . make_stmts ( ) ;
1273
1260
}
1274
1261
1275
1262
stmt = stmt_;
@@ -1311,10 +1298,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1311
1298
fn fold_item ( & mut self , item : P < ast:: Item > ) -> SmallVec < [ P < ast:: Item > ; 1 ] > {
1312
1299
let item = configure ! ( self , item) ;
1313
1300
1314
- let ( attr, traits, item, together_with ) = self . classify_item ( item) ;
1301
+ let ( attr, traits, item, after_derive ) = self . classify_item ( item) ;
1315
1302
if attr. is_some ( ) || !traits. is_empty ( ) {
1316
1303
return self . collect_attr ( attr, traits, Annotatable :: Item ( item) ,
1317
- AstFragmentKind :: Items , together_with ) . make_items ( ) ;
1304
+ AstFragmentKind :: Items , after_derive ) . make_items ( ) ;
1318
1305
}
1319
1306
1320
1307
match item. node {
@@ -1386,10 +1373,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1386
1373
fn fold_trait_item ( & mut self , item : ast:: TraitItem ) -> SmallVec < [ ast:: TraitItem ; 1 ] > {
1387
1374
let item = configure ! ( self , item) ;
1388
1375
1389
- let ( attr, traits, item, together_with ) = self . classify_item ( item) ;
1376
+ let ( attr, traits, item, after_derive ) = self . classify_item ( item) ;
1390
1377
if attr. is_some ( ) || !traits. is_empty ( ) {
1391
1378
return self . collect_attr ( attr, traits, Annotatable :: TraitItem ( P ( item) ) ,
1392
- AstFragmentKind :: TraitItems , together_with ) . make_trait_items ( )
1379
+ AstFragmentKind :: TraitItems , after_derive ) . make_trait_items ( )
1393
1380
}
1394
1381
1395
1382
match item. node {
@@ -1405,10 +1392,10 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1405
1392
fn fold_impl_item ( & mut self , item : ast:: ImplItem ) -> SmallVec < [ ast:: ImplItem ; 1 ] > {
1406
1393
let item = configure ! ( self , item) ;
1407
1394
1408
- let ( attr, traits, item, together_with ) = self . classify_item ( item) ;
1395
+ let ( attr, traits, item, after_derive ) = self . classify_item ( item) ;
1409
1396
if attr. is_some ( ) || !traits. is_empty ( ) {
1410
1397
return self . collect_attr ( attr, traits, Annotatable :: ImplItem ( P ( item) ) ,
1411
- AstFragmentKind :: ImplItems , together_with ) . make_impl_items ( ) ;
1398
+ AstFragmentKind :: ImplItems , after_derive ) . make_impl_items ( ) ;
1412
1399
}
1413
1400
1414
1401
match item. node {
@@ -1440,11 +1427,11 @@ impl<'a, 'b> Folder for InvocationCollector<'a, 'b> {
1440
1427
fn fold_foreign_item ( & mut self , foreign_item : ast:: ForeignItem )
1441
1428
-> SmallVec < [ ast:: ForeignItem ; 1 ] >
1442
1429
{
1443
- let ( attr, traits, foreign_item, together_with ) = self . classify_item ( foreign_item) ;
1430
+ let ( attr, traits, foreign_item, after_derive ) = self . classify_item ( foreign_item) ;
1444
1431
1445
1432
if attr. is_some ( ) || !traits. is_empty ( ) {
1446
1433
return self . collect_attr ( attr, traits, Annotatable :: ForeignItem ( P ( foreign_item) ) ,
1447
- AstFragmentKind :: ForeignItems , together_with )
1434
+ AstFragmentKind :: ForeignItems , after_derive )
1448
1435
. make_foreign_items ( ) ;
1449
1436
}
1450
1437
0 commit comments