@@ -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,7 +664,9 @@ 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 ( ) ;
667
+ let mut details: Vec < _ > = lints
668
+ . map ( |l| ( & l. module , l. name . to_uppercase ( ) , l. has_version ) )
669
+ . collect ( ) ;
661
670
details. sort_unstable ( ) ;
662
671
663
672
let mut output = GENERATED_FILE_COMMENT . to_string ( ) ;
@@ -667,8 +676,14 @@ fn gen_lint_group_list<'a>(group_name: &str, lints: impl Iterator<Item = &'a Lin
667
676
"store.register_group(true, \" clippy::{0}\" , Some(\" clippy_{0}\" ), vec![" ,
668
677
group_name
669
678
) ;
670
- for ( module, name) in details {
671
- let _ = writeln ! ( output, " LintId::of({}::{})," , module, name) ;
679
+ for ( module, name, has_version) in details {
680
+ let _ = writeln ! (
681
+ output,
682
+ " {}LintId::of({}::{})," ,
683
+ if has_version { "" } else { "#[cfg(nightly)] " } ,
684
+ module,
685
+ name,
686
+ ) ;
672
687
}
673
688
output. push_str ( "])\n " ) ;
674
689
@@ -858,21 +873,22 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
858
873
. filter ( |t| !matches ! ( t. token_kind, TokenKind :: Whitespace | TokenKind :: LineComment { .. } ) ) ;
859
874
// matches `!{`
860
875
match_tokens ! ( iter, Bang OpenBrace ) ;
861
- match iter. next ( ) {
876
+ let has_version = match iter. next ( ) {
862
877
// #[clippy::version = "version"] pub
863
878
Some ( LintDeclSearchResult {
864
879
token_kind : TokenKind :: Pound ,
865
880
..
866
881
} ) => {
867
882
match_tokens ! ( iter, OpenBracket Ident Colon Colon Ident Eq Literal { ..} CloseBracket Ident ) ;
883
+ true
868
884
} ,
869
885
// pub
870
886
Some ( LintDeclSearchResult {
871
887
token_kind : TokenKind :: Ident ,
872
888
..
873
- } ) => ( ) ,
889
+ } ) => false ,
874
890
_ => continue ,
875
- }
891
+ } ;
876
892
877
893
let ( name, group, desc) = match_tokens ! (
878
894
iter,
@@ -890,7 +906,7 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
890
906
..
891
907
} ) = iter. next ( )
892
908
{
893
- lints. push ( Lint :: new ( name, group, desc, module, start..range. end ) ) ;
909
+ lints. push ( Lint :: new ( name, group, desc, module, has_version , start..range. end ) ) ;
894
910
}
895
911
}
896
912
}
@@ -1115,13 +1131,15 @@ mod tests {
1115
1131
"style" ,
1116
1132
"\" really long text\" " ,
1117
1133
"module_name" ,
1134
+ true ,
1118
1135
Range :: default ( ) ,
1119
1136
) ,
1120
1137
Lint :: new(
1121
1138
"doc_markdown" ,
1122
1139
"pedantic" ,
1123
1140
"\" single line\" " ,
1124
1141
"module_name" ,
1142
+ true ,
1125
1143
Range :: default ( ) ,
1126
1144
) ,
1127
1145
] ;
@@ -1161,20 +1179,23 @@ mod tests {
1161
1179
"Not Deprecated" ,
1162
1180
"\" abc\" " ,
1163
1181
"module_name" ,
1182
+ true ,
1164
1183
Range :: default ( ) ,
1165
1184
) ,
1166
1185
Lint :: new(
1167
1186
"should_assert_eq2" ,
1168
1187
"internal" ,
1169
1188
"\" abc\" " ,
1170
1189
"module_name" ,
1190
+ true ,
1171
1191
Range :: default ( ) ,
1172
1192
) ,
1173
1193
Lint :: new(
1174
1194
"should_assert_eq2" ,
1175
1195
"internal_style" ,
1176
1196
"\" abc\" " ,
1177
1197
"module_name" ,
1198
+ true ,
1178
1199
Range :: default ( ) ,
1179
1200
) ,
1180
1201
] ;
@@ -1183,6 +1204,7 @@ mod tests {
1183
1204
"Not Deprecated" ,
1184
1205
"\" abc\" " ,
1185
1206
"module_name" ,
1207
+ true ,
1186
1208
Range :: default ( ) ,
1187
1209
) ] ;
1188
1210
assert_eq ! ( expected, Lint :: usable_lints( & lints) ) ;
@@ -1191,22 +1213,51 @@ mod tests {
1191
1213
#[ test]
1192
1214
fn test_by_lint_group ( ) {
1193
1215
let lints = vec ! [
1194
- Lint :: new( "should_assert_eq" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
1216
+ Lint :: new(
1217
+ "should_assert_eq" ,
1218
+ "group1" ,
1219
+ "\" abc\" " ,
1220
+ "module_name" ,
1221
+ true ,
1222
+ Range :: default ( ) ,
1223
+ ) ,
1195
1224
Lint :: new(
1196
1225
"should_assert_eq2" ,
1197
1226
"group2" ,
1198
1227
"\" abc\" " ,
1199
1228
"module_name" ,
1229
+ true ,
1230
+ Range :: default ( ) ,
1231
+ ) ,
1232
+ Lint :: new(
1233
+ "incorrect_match" ,
1234
+ "group1" ,
1235
+ "\" abc\" " ,
1236
+ "module_name" ,
1237
+ true ,
1200
1238
Range :: default ( ) ,
1201
1239
) ,
1202
- Lint :: new( "incorrect_match" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
1203
1240
] ;
1204
1241
let mut expected: HashMap < String , Vec < Lint > > = HashMap :: new ( ) ;
1205
1242
expected. insert (
1206
1243
"group1" . to_string ( ) ,
1207
1244
vec ! [
1208
- Lint :: new( "should_assert_eq" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
1209
- Lint :: new( "incorrect_match" , "group1" , "\" abc\" " , "module_name" , Range :: default ( ) ) ,
1245
+ Lint :: new(
1246
+ "should_assert_eq" ,
1247
+ "group1" ,
1248
+ "\" abc\" " ,
1249
+ "module_name" ,
1250
+ true ,
1251
+ Range :: default ( ) ,
1252
+ ) ,
1253
+ Lint :: new(
1254
+ "incorrect_match" ,
1255
+ "group1" ,
1256
+ "\" abc\" " ,
1257
+ "module_name" ,
1258
+ true ,
1259
+ Range :: default ( ) ,
1260
+ ) ,
1210
1261
] ,
1211
1262
) ;
1212
1263
expected. insert (
@@ -1216,6 +1267,7 @@ mod tests {
1216
1267
"group2" ,
1217
1268
"\" abc\" " ,
1218
1269
"module_name" ,
1270
+ true ,
1219
1271
Range :: default ( ) ,
1220
1272
) ] ,
1221
1273
) ;
@@ -1255,9 +1307,23 @@ mod tests {
1255
1307
#[ test]
1256
1308
fn test_gen_lint_group_list ( ) {
1257
1309
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 ( ) ) ,
1310
+ Lint :: new( "abc" , "group1" , "\" abc\" " , "module_name" , true , Range :: default ( ) ) ,
1311
+ Lint :: new(
1312
+ "should_assert_eq" ,
1313
+ "group1" ,
1314
+ "\" abc\" " ,
1315
+ "module_name" ,
1316
+ true ,
1317
+ Range :: default ( ) ,
1318
+ ) ,
1319
+ Lint :: new(
1320
+ "internal" ,
1321
+ "internal_style" ,
1322
+ "\" abc\" " ,
1323
+ "module_name" ,
1324
+ true ,
1325
+ Range :: default ( ) ,
1326
+ ) ,
1261
1327
] ;
1262
1328
let expected = GENERATED_FILE_COMMENT . to_string ( )
1263
1329
+ & [
0 commit comments