Skip to content

Commit 3c18dcf

Browse files
committed
Enable nightly lints via cli args
1 parent 9e61b0d commit 3c18dcf

17 files changed

+1093
-985
lines changed

clippy_dev/src/update_lints.rs

+55-20
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ fn generate_lint_files(
114114
update_mode,
115115
&gen_deprecated(deprecated_lints),
116116
);
117+
process_file(
118+
"src/driver.warn_nightly_args.rs",
119+
update_mode,
120+
&gen_warn_nightly_lints(lints),
121+
);
117122

118123
let all_group_lints = usable_lints.iter().filter(|l| {
119124
matches!(
@@ -664,28 +669,39 @@ impl RenamedLint {
664669

665670
/// Generates the code for registering a group
666671
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()))
669680
.collect();
670-
details.sort_unstable();
681+
// Sort stable lints first
682+
lints.sort_unstable();
671683

672684
let mut output = GENERATED_FILE_COMMENT.to_string();
673685

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+
}
674699
let _ = writeln!(
675700
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,
678703
);
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");
689705

690706
output
691707
}
@@ -780,6 +796,21 @@ fn gen_renamed_lints_list(lints: &[RenamedLint]) -> String {
780796
res
781797
}
782798

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+
783814
/// Gathers all lints defined in `clippy_lints/src`
784815
fn gather_all() -> (Vec<Lint>, Vec<DeprecatedLint>, Vec<RenamedLint>) {
785816
let mut lints = Vec::with_capacity(1000);
@@ -1327,11 +1358,15 @@ mod tests {
13271358
];
13281359
let expected = GENERATED_FILE_COMMENT.to_string()
13291360
+ &[
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+
"}",
13351370
]
13361371
.join("\n")
13371372
+ "\n";

clippy_lints/build.rs

-6
This file was deleted.

0 commit comments

Comments
 (0)