Skip to content

Commit 8a7c93e

Browse files
committed
feat(cargo-lints): Add lint groups to verification
1 parent 81ec9e6 commit 8a7c93e

File tree

2 files changed

+55
-5
lines changed

2 files changed

+55
-5
lines changed

Diff for: src/cargo/util/lints.rs

+41-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::ops::Range;
1212
use std::path::Path;
1313
use toml_edit::ImDocument;
1414

15+
const LINT_GROUPS: &[LintGroup] = &[TEST_DUMMY_UNSTABLE];
1516
const LINTS: &[Lint] = &[IM_A_TEAPOT, IMPLICIT_FEATURES, UNUSED_OPTIONAL_DEPENDENCY];
1617

1718
pub fn verify_lints(
@@ -33,11 +34,20 @@ pub fn verify_lints(
3334
.keys()
3435
.chain(ws_lints.map(|l| l.keys()).unwrap_or_default())
3536
{
36-
if let Some(lint) = LINTS.iter().find(|l| l.name == lint_name) {
37-
let (_, reason) = lint.level(pkg_lints, ws_lints, manifest.edition());
38-
if let Some(feature_gate) = lint.feature_gate {
37+
if let Some((name, default_level, edition_lint_opts, feature_gate)) =
38+
find_lint_or_group(lint_name)
39+
{
40+
let (_, reason, _) = level_priority(
41+
name,
42+
*default_level,
43+
*edition_lint_opts,
44+
pkg_lints,
45+
ws_lints,
46+
manifest.edition(),
47+
);
48+
if let Some(feature_gate) = feature_gate {
3949
feature_gated_lint(
40-
lint.name,
50+
name,
4151
feature_gate,
4252
reason,
4353
manifest,
@@ -60,6 +70,33 @@ pub fn verify_lints(
6070
}
6171
}
6272

73+
fn find_lint_or_group<'a>(
74+
name: &str,
75+
) -> Option<(
76+
&'static str,
77+
&LintLevel,
78+
&Option<(Edition, LintLevel)>,
79+
&Option<&'static Feature>,
80+
)> {
81+
if let Some(lint) = LINTS.iter().find(|l| l.name == name) {
82+
Some((
83+
lint.name,
84+
&lint.default_level,
85+
&lint.edition_lint_opts,
86+
&lint.feature_gate,
87+
))
88+
} else if let Some(group) = LINT_GROUPS.iter().find(|g| g.name == name) {
89+
Some((
90+
group.name,
91+
&group.default_level,
92+
&group.edition_lint_opts,
93+
&group.feature_gate,
94+
))
95+
} else {
96+
None
97+
}
98+
}
99+
63100
fn feature_gated_lint(
64101
lint_name: &str,
65102
feature_gate: &Feature,

Diff for: tests/testsuite/lints_table.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,20 @@ note: `cargo::im-a-teapot` was inherited
11081108
| ----------------
11091109
|
11101110
= help: consider adding `cargo-features = [\"test-dummy-unstable\"]` to the top of the manifest
1111-
error: encountered 1 errors(s) while verifying lints
1111+
error: use of unstable lint `test-dummy-unstable`
1112+
--> Cargo.toml:7:1
1113+
|
1114+
7 | test-dummy-unstable = { level = \"forbid\", priority = -1 }
1115+
| ^^^^^^^^^^^^^^^^^^^ this is behind `test-dummy-unstable`, which is not enabled
1116+
|
1117+
note: `cargo::test-dummy-unstable` was inherited
1118+
--> foo/Cargo.toml:9:1
1119+
|
1120+
9 | workspace = true
1121+
| ----------------
1122+
|
1123+
= help: consider adding `cargo-features = [\"test-dummy-unstable\"]` to the top of the manifest
1124+
error: encountered 2 errors(s) while verifying lints
11121125
",
11131126
)
11141127
.run();

0 commit comments

Comments
 (0)