@@ -114,6 +114,11 @@ fn generate_lint_files(
114
114
update_mode,
115
115
& gen_deprecated ( deprecated_lints) ,
116
116
) ;
117
+ process_file (
118
+ "src/driver.warn_nightly_args.rs" ,
119
+ update_mode,
120
+ & gen_warn_nightly_lints ( lints) ,
121
+ ) ;
117
122
118
123
let all_group_lints = usable_lints. iter ( ) . filter ( |l| {
119
124
matches ! (
@@ -664,28 +669,39 @@ impl RenamedLint {
664
669
665
670
/// Generates the code for registering a group
666
671
fn gen_lint_group_list < ' a > ( group_name : & str , lints : impl Iterator < Item = & ' a Lint > ) -> String {
667
- let mut details: Vec < _ > = lints
668
- . map ( |l| ( & l. module , l. name . to_uppercase ( ) , l. has_version ) )
672
+ let mut stable_count = 0usize ;
673
+ let mut lints: Vec < _ > = lints
674
+ . inspect ( |l| {
675
+ if l. has_version {
676
+ stable_count += 1
677
+ }
678
+ } )
679
+ . map ( |l| ( !l. has_version , & l. module , l. name . to_uppercase ( ) ) )
669
680
. collect ( ) ;
670
- details. sort_unstable ( ) ;
681
+ // Sort stable lints first
682
+ lints. sort_unstable ( ) ;
671
683
672
684
let mut output = GENERATED_FILE_COMMENT . to_string ( ) ;
673
685
686
+ let _ = write ! ( output, "{{\n let lints: [LintId; {}] = [\n " , lints. len( ) ) ;
687
+ for ( _, module, name) in & lints {
688
+ let _ = writeln ! ( output, " LintId::of({}::{})," , module, name) ;
689
+ }
690
+ output. push_str ( " ];\n " ) ;
691
+ if stable_count != lints. len ( ) {
692
+ output. push_str ( " let lints = if enable_unstable_lints {\n " ) ;
693
+ output. push_str ( " lints.as_slice()\n " ) ;
694
+ output. push_str ( " } else {\n " ) ;
695
+ let _ = write ! ( output, " &lints[..{}]\n }};\n " , stable_count) ;
696
+ } else {
697
+ output. push_str ( " let lints = lints.as_slice();\n " ) ;
698
+ }
674
699
let _ = writeln ! (
675
700
output,
676
- "store.register_group(true, \" clippy::{0}\" , Some(\" clippy_{0}\" ), vec![ " ,
677
- group_name
701
+ " store.register_group(true, \" clippy::{0}\" , Some(\" clippy_{0}\" ), lints.into()); " ,
702
+ group_name,
678
703
) ;
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
- ) ;
687
- }
688
- output. push_str ( "])\n " ) ;
704
+ output. push_str ( "}\n " ) ;
689
705
690
706
output
691
707
}
@@ -780,6 +796,21 @@ fn gen_renamed_lints_list(lints: &[RenamedLint]) -> String {
780
796
res
781
797
}
782
798
799
+ fn gen_warn_nightly_lints ( lints : & [ Lint ] ) -> String {
800
+ let mut res: String = GENERATED_FILE_COMMENT . into ( ) ;
801
+ res. push_str ( "[\n " ) ;
802
+ for lint in lints. iter ( ) . filter ( |l| !l. has_version ) {
803
+ let level = match & * lint. group {
804
+ "correctness" => "D" ,
805
+ "suspicious" | "style" | "perf" | "complexity" => "W" ,
806
+ _ => continue ,
807
+ } ;
808
+ let _ = write ! ( res, " \" -{}\" ,\n \" clippy::{}\" ,\n " , level, lint. name) ;
809
+ }
810
+ res. push_str ( "]\n " ) ;
811
+ res
812
+ }
813
+
783
814
/// Gathers all lints defined in `clippy_lints/src`
784
815
fn gather_all ( ) -> ( Vec < Lint > , Vec < DeprecatedLint > , Vec < RenamedLint > ) {
785
816
let mut lints = Vec :: with_capacity ( 1000 ) ;
@@ -1327,11 +1358,15 @@ mod tests {
1327
1358
] ;
1328
1359
let expected = GENERATED_FILE_COMMENT . to_string ( )
1329
1360
+ & [
1330
- "store.register_group(true, \" clippy::group1\" , Some(\" clippy_group1\" ), vec![" ,
1331
- " LintId::of(module_name::ABC)," ,
1332
- " LintId::of(module_name::INTERNAL)," ,
1333
- " LintId::of(module_name::SHOULD_ASSERT_EQ)," ,
1334
- "])" ,
1361
+ "{" ,
1362
+ " let lints: [LintId; 3] = [" ,
1363
+ " LintId::of(module_name::ABC)," ,
1364
+ " LintId::of(module_name::INTERNAL)," ,
1365
+ " LintId::of(module_name::SHOULD_ASSERT_EQ)," ,
1366
+ " ];" ,
1367
+ " let lints = lints.as_slice();" ,
1368
+ " store.register_group(true, \" clippy::group1\" , Some(\" clippy_group1\" ), lints.into());" ,
1369
+ "}" ,
1335
1370
]
1336
1371
. join ( "\n " )
1337
1372
+ "\n " ;
0 commit comments