Skip to content

Commit 2b34abc

Browse files
committed
Auto merge of rust-lang#12730 - Alexendoo:lint-groups-workspace-priority, r=xFrednet
Lint direct priority conflicts in `[workspace.lints]` Partially addresses rust-lang#12729 This still doesn't do any workspace resolution stuff, so it will not catch any virtual workspaces or conflicts from inherited definitions. But while we're parsing the `Cargo.toml` we might as well check the workspace definitions if we find them changelog: none
2 parents 412b691 + fa8f4b8 commit 2b34abc

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

clippy_lints/src/cargo/lint_groups_priority.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,26 @@ impl LintConfig {
4949

5050
type LintTable = BTreeMap<Spanned<String>, Spanned<LintConfig>>;
5151

52-
#[derive(Deserialize, Debug)]
52+
#[derive(Deserialize, Debug, Default)]
5353
struct Lints {
5454
#[serde(default)]
5555
rust: LintTable,
5656
#[serde(default)]
5757
clippy: LintTable,
5858
}
5959

60+
#[derive(Deserialize, Debug, Default)]
61+
struct Workspace {
62+
#[serde(default)]
63+
lints: Lints,
64+
}
65+
6066
#[derive(Deserialize, Debug)]
6167
struct CargoToml {
68+
#[serde(default)]
6269
lints: Lints,
70+
#[serde(default)]
71+
workspace: Workspace,
6372
}
6473

6574
#[derive(Default, Debug)]
@@ -164,5 +173,7 @@ pub fn check(cx: &LateContext<'_>) {
164173

165174
check_table(cx, cargo_toml.lints.rust, &rustc_groups, &file);
166175
check_table(cx, cargo_toml.lints.clippy, &clippy_groups, &file);
176+
check_table(cx, cargo_toml.workspace.lints.rust, &rustc_groups, &file);
177+
check_table(cx, cargo_toml.workspace.lints.clippy, &clippy_groups, &file);
167178
}
168179
}

tests/ui-cargo/lint_groups_priority/fail/Cargo.stderr

+29-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,32 @@ help: to have lints override the group set `pedantic` to a lower priority
4242
19 | pedantic = { level = "warn", priority = -2 }
4343
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4444

45-
error: could not compile `fail` (lib) due to 3 previous errors
45+
error: lint group `rust_2018_idioms` has the same priority (0) as a lint
46+
--> Cargo.toml:23:1
47+
|
48+
23 | rust_2018_idioms = "warn"
49+
| ^^^^^^^^^^^^^^^^ ------ has an implicit priority of 0
50+
24 | bare_trait_objects = "allow"
51+
| ------------------ has the same priority as this lint
52+
|
53+
= note: the order of the lints in the table is ignored by Cargo
54+
help: to have lints override the group set `rust_2018_idioms` to a lower priority
55+
|
56+
23 | rust_2018_idioms = { level = "warn", priority = -1 }
57+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58+
59+
error: lint group `pedantic` has the same priority (0) as a lint
60+
--> Cargo.toml:27:1
61+
|
62+
27 | pedantic = "warn"
63+
| ^^^^^^^^ ------ has an implicit priority of 0
64+
28 | similar_names = "allow"
65+
| ------------- has the same priority as this lint
66+
|
67+
= note: the order of the lints in the table is ignored by Cargo
68+
help: to have lints override the group set `pedantic` to a lower priority
69+
|
70+
27 | pedantic = { level = "warn", priority = -1 }
71+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72+
73+
error: could not compile `fail` (lib) due to 5 previous errors

tests/ui-cargo/lint_groups_priority/fail/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,11 @@ deprecated = "allow"
1818
[lints.clippy]
1919
pedantic = { level = "warn", priority = -1 }
2020
similar_names = { level = "allow", priority = -1 }
21+
22+
[workspace.lints.rust]
23+
rust_2018_idioms = "warn"
24+
bare_trait_objects = "allow"
25+
26+
[workspace.lints.clippy]
27+
pedantic = "warn"
28+
similar_names = "allow"

0 commit comments

Comments
 (0)