@@ -491,7 +491,6 @@ fn declare_deprecated(name: &str, path: &Path, reason: &str) -> io::Result<()> {
491
491
492
492
file. seek ( SeekFrom :: End ( 0 ) ) ?;
493
493
494
- let version = crate :: new_lint:: get_stabilization_version ( ) ;
495
494
let deprecation_reason = if reason == DEFAULT_DEPRECATION_REASON {
496
495
"TODO"
497
496
} else {
@@ -508,14 +507,13 @@ fn declare_deprecated(name: &str, path: &Path, reason: &str) -> io::Result<()> {
508
507
///
509
508
/// ### Deprecation reason
510
509
/// {}
511
- #[clippy::version = \" {} \" ]
510
+ #[clippy::version = \" nightly \" ]
512
511
pub {},
513
512
\" {}\"
514
513
}}
515
514
516
515
" ,
517
516
deprecation_reason,
518
- version,
519
517
name,
520
518
reason,
521
519
)
@@ -588,17 +586,26 @@ struct Lint {
588
586
group : String ,
589
587
desc : String ,
590
588
module : String ,
589
+ has_version : bool ,
591
590
declaration_range : Range < usize > ,
592
591
}
593
592
594
593
impl Lint {
595
594
#[ must_use]
596
- fn new ( name : & str , group : & str , desc : & str , module : & str , declaration_range : Range < usize > ) -> Self {
595
+ fn new (
596
+ name : & str ,
597
+ group : & str ,
598
+ desc : & str ,
599
+ module : & str ,
600
+ has_version : bool ,
601
+ declaration_range : Range < usize > ,
602
+ ) -> Self {
597
603
Self {
598
604
name : name. to_lowercase ( ) ,
599
605
group : group. into ( ) ,
600
606
desc : remove_line_splices ( desc) ,
601
607
module : module. into ( ) ,
608
+ has_version,
602
609
declaration_range,
603
610
}
604
611
}
@@ -657,20 +664,36 @@ impl RenamedLint {
657
664
658
665
/// Generates the code for registering a group
659
666
fn gen_lint_group_list < ' a > ( group_name : & str , lints : impl Iterator < Item = & ' a Lint > ) -> String {
660
- let mut details: Vec < _ > = lints. map ( |l| ( & l. module , l. name . to_uppercase ( ) ) ) . collect ( ) ;
661
- details. sort_unstable ( ) ;
667
+ let mut stable_count = 0usize ;
668
+ let mut lints: Vec < _ > = lints
669
+ . inspect ( |l| {
670
+ if l. has_version {
671
+ stable_count += 1 ;
672
+ }
673
+ } )
674
+ . map ( |l| ( !l. has_version , & l. module , l. name . to_uppercase ( ) ) )
675
+ . collect ( ) ;
676
+ lints. sort_unstable ( ) ;
662
677
663
678
let mut output = GENERATED_FILE_COMMENT . to_string ( ) ;
664
-
679
+ let _ = write ! ( output, "{{\n let lints: [LintId; {}] = [\n " , lints. len( ) ) ;
680
+ for ( _, module, name) in & lints {
681
+ let _ = writeln ! ( output, " LintId::of({}::{})," , module, name) ;
682
+ }
683
+ output. push_str ( " ];\n " ) ;
684
+ if stable_count != lints. len ( ) {
685
+ output. push_str ( " let lints = if sess.opts.unstable_features.is_nightly_build() {\n " ) ;
686
+ output. push_str ( " lints.as_slice()\n " ) ;
687
+ output. push_str ( " } else {\n " ) ;
688
+ let _ = writeln ! ( output, " &lints[..{}]" , stable_count) ;
689
+ output. push_str ( " };\n " ) ;
690
+ }
665
691
let _ = writeln ! (
666
692
output,
667
- "store.register_group(true, \" clippy::{0}\" , Some(\" clippy_{0}\" ), vec![ " ,
693
+ " store.register_group(true, \" clippy::{0}\" , Some(\" clippy_{0}\" ), lints.to_vec()); " ,
668
694
group_name
669
695
) ;
670
- for ( module, name) in details {
671
- let _ = writeln ! ( output, " LintId::of({}::{})," , module, name) ;
672
- }
673
- output. push_str ( "])\n " ) ;
696
+ output. push_str ( "}\n " ) ;
674
697
675
698
output
676
699
}
@@ -858,21 +881,22 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
858
881
. filter ( |t| !matches ! ( t. token_kind, TokenKind :: Whitespace | TokenKind :: LineComment { .. } ) ) ;
859
882
// matches `!{`
860
883
match_tokens ! ( iter, Bang OpenBrace ) ;
861
- match iter. next ( ) {
884
+ let has_version = match iter. next ( ) {
862
885
// #[clippy::version = "version"] pub
863
886
Some ( LintDeclSearchResult {
864
887
token_kind : TokenKind :: Pound ,
865
888
..
866
889
} ) => {
867
890
match_tokens ! ( iter, OpenBracket Ident Colon Colon Ident Eq Literal { ..} CloseBracket Ident ) ;
891
+ true
868
892
} ,
869
893
// pub
870
894
Some ( LintDeclSearchResult {
871
895
token_kind : TokenKind :: Ident ,
872
896
..
873
- } ) => ( ) ,
897
+ } ) => false ,
874
898
_ => continue ,
875
- }
899
+ } ;
876
900
877
901
let ( name, group, desc) = match_tokens ! (
878
902
iter,
@@ -890,7 +914,7 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
890
914
..
891
915
} ) = iter. next ( )
892
916
{
893
- lints. push ( Lint :: new ( name, group, desc, module, start..range. end ) ) ;
917
+ lints. push ( Lint :: new ( name, group, desc, module, has_version , start..range. end ) ) ;
894
918
}
895
919
}
896
920
}
@@ -1115,13 +1139,15 @@ mod tests {
1115
1139
"style" ,
1116
1140
"\" really long text\" " ,
1117
1141
"module_name" ,
1142
+ true ,
1118
1143
Range :: default ( ) ,
1119
1144
) ,
1120
1145
Lint :: new(
1121
1146
"doc_markdown" ,
1122
1147
"pedantic" ,
1123
1148
"\" single line\" " ,
1124
1149
"module_name" ,
1150
+ true ,
1125
1151
Range :: default ( ) ,
1126
1152
) ,
1127
1153
] ;
@@ -1161,20 +1187,23 @@ mod tests {
1161
1187
"Not Deprecated" ,
1162
1188
"\" abc\" " ,
1163
1189
"module_name" ,
1190
+ true ,
1164
1191
Range :: default ( ) ,
1165
1192
) ,
1166
1193
Lint :: new(
1167
1194
"should_assert_eq2" ,
1168
1195
"internal" ,
1169
1196
"\" abc\" " ,
1170
1197
"module_name" ,
1198
+ true ,
1171
1199
Range :: default ( ) ,
1172
1200
) ,
1173
1201
Lint :: new(
1174
1202
"should_assert_eq2" ,
1175
1203
"internal_style" ,
1176
1204
"\" abc\" " ,
1177
1205
"module_name" ,
1206
+ true ,
1178
1207
Range :: default ( ) ,
1179
1208
) ,
1180
1209
] ;
@@ -1183,6 +1212,7 @@ mod tests {
1183
1212
"Not Deprecated" ,
1184
1213
"\" abc\" " ,
1185
1214
"module_name" ,
1215
+ true ,
1186
1216
Range :: default ( ) ,
1187
1217
) ] ;
1188
1218
assert_eq ! ( expected, Lint :: usable_lints( & lints) ) ;
@@ -1191,22 +1221,51 @@ mod tests {
1191
1221
#[ test]
1192
1222
fn test_by_lint_group ( ) {
1193
1223
let lints = vec ! [
1194
- Lint :: new( "should_assert_eq" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
1224
+ Lint :: new(
1225
+ "should_assert_eq" ,
1226
+ "group1" ,
1227
+ "\" abc\" " ,
1228
+ "module_name" ,
1229
+ true ,
1230
+ Range :: default ( ) ,
1231
+ ) ,
1195
1232
Lint :: new(
1196
1233
"should_assert_eq2" ,
1197
1234
"group2" ,
1198
1235
"\" abc\" " ,
1199
1236
"module_name" ,
1237
+ true ,
1238
+ Range :: default ( ) ,
1239
+ ) ,
1240
+ Lint :: new(
1241
+ "incorrect_match" ,
1242
+ "group1" ,
1243
+ "\" abc\" " ,
1244
+ "module_name" ,
1245
+ true ,
1200
1246
Range :: default ( ) ,
1201
1247
) ,
1202
- Lint :: new( "incorrect_match" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
1203
1248
] ;
1204
1249
let mut expected: HashMap < String , Vec < Lint > > = HashMap :: new ( ) ;
1205
1250
expected. insert (
1206
1251
"group1" . to_string ( ) ,
1207
1252
vec ! [
1208
- Lint :: new( "should_assert_eq" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
1209
- Lint :: new( "incorrect_match" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
1253
+ Lint :: new(
1254
+ "should_assert_eq" ,
1255
+ "group1" ,
1256
+ "\" abc\" " ,
1257
+ "module_name" ,
1258
+ true ,
1259
+ Range :: default ( ) ,
1260
+ ) ,
1261
+ Lint :: new(
1262
+ "incorrect_match" ,
1263
+ "group1" ,
1264
+ "\" abc\" " ,
1265
+ "module_name" ,
1266
+ true ,
1267
+ Range :: default ( ) ,
1268
+ ) ,
1210
1269
] ,
1211
1270
) ;
1212
1271
expected. insert (
@@ -1216,6 +1275,7 @@ mod tests {
1216
1275
"group2" ,
1217
1276
"\" abc\" " ,
1218
1277
"module_name" ,
1278
+ true ,
1219
1279
Range :: default ( ) ,
1220
1280
) ] ,
1221
1281
) ;
@@ -1255,17 +1315,34 @@ mod tests {
1255
1315
#[ test]
1256
1316
fn test_gen_lint_group_list ( ) {
1257
1317
let lints = vec ! [
1258
- Lint :: new( "abc" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
1259
- Lint :: new( "should_assert_eq" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
1260
- Lint :: new( "internal" , "internal_style" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
1318
+ Lint :: new( "abc" , "group1" , "\" abc\" " , "module_name" , true , Range :: default ( ) ) ,
1319
+ Lint :: new(
1320
+ "should_assert_eq" ,
1321
+ "group1" ,
1322
+ "\" abc\" " ,
1323
+ "module_name" ,
1324
+ true ,
1325
+ Range :: default ( ) ,
1326
+ ) ,
1327
+ Lint :: new(
1328
+ "internal" ,
1329
+ "internal_style" ,
1330
+ "\" abc\" " ,
1331
+ "module_name" ,
1332
+ true ,
1333
+ Range :: default ( ) ,
1334
+ ) ,
1261
1335
] ;
1262
1336
let expected = GENERATED_FILE_COMMENT . to_string ( )
1263
1337
+ & [
1264
- "store.register_group(true, \" clippy::group1\" , Some(\" clippy_group1\" ), vec![" ,
1265
- " LintId::of(module_name::ABC)," ,
1266
- " LintId::of(module_name::INTERNAL)," ,
1267
- " LintId::of(module_name::SHOULD_ASSERT_EQ)," ,
1268
- "])" ,
1338
+ "{" ,
1339
+ " let lints: [LintId; 3] = [" ,
1340
+ " LintId::of(module_name::ABC)," ,
1341
+ " LintId::of(module_name::INTERNAL)," ,
1342
+ " LintId::of(module_name::SHOULD_ASSERT_EQ)," ,
1343
+ " ];" ,
1344
+ " store.register_group(true, \" clippy::group1\" , Some(\" clippy_group1\" ), lints.to_vec());" ,
1345
+ "}" ,
1269
1346
]
1270
1347
. join ( "\n " )
1271
1348
+ "\n " ;
0 commit comments