From f3a1a6ab9318b5e02e2ca8759328295b5a749ef2 Mon Sep 17 00:00:00 2001 From: Scott Schafer Date: Fri, 26 Apr 2024 15:49:17 -0600 Subject: [PATCH] feat(cargo-lints): Add lint groups to verification --- src/cargo/util/lints.rs | 45 +++++++++++++++++++++++++++++++--- tests/testsuite/lints_table.rs | 15 +++++++++++- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/src/cargo/util/lints.rs b/src/cargo/util/lints.rs index 05b80c826130..d8adb91c7379 100644 --- a/src/cargo/util/lints.rs +++ b/src/cargo/util/lints.rs @@ -12,6 +12,7 @@ use std::ops::Range; use std::path::Path; use toml_edit::ImDocument; +const LINT_GROUPS: &[LintGroup] = &[TEST_DUMMY_UNSTABLE]; const LINTS: &[Lint] = &[IM_A_TEAPOT, IMPLICIT_FEATURES, UNUSED_OPTIONAL_DEPENDENCY]; pub fn verify_lints( @@ -33,11 +34,20 @@ pub fn verify_lints( .keys() .chain(ws_lints.map(|l| l.keys()).unwrap_or_default()) { - if let Some(lint) = LINTS.iter().find(|l| l.name == lint_name) { - let (_, reason) = lint.level(pkg_lints, ws_lints, manifest.edition()); - if let Some(feature_gate) = lint.feature_gate { + if let Some((name, default_level, edition_lint_opts, feature_gate)) = + find_lint_or_group(lint_name) + { + let (_, reason, _) = level_priority( + name, + *default_level, + *edition_lint_opts, + pkg_lints, + ws_lints, + manifest.edition(), + ); + if let Some(feature_gate) = feature_gate { feature_gated_lint( - lint.name, + name, feature_gate, reason, manifest, @@ -60,6 +70,33 @@ pub fn verify_lints( } } +fn find_lint_or_group<'a>( + name: &str, +) -> Option<( + &'static str, + &LintLevel, + &Option<(Edition, LintLevel)>, + &Option<&'static Feature>, +)> { + if let Some(lint) = LINTS.iter().find(|l| l.name == name) { + Some(( + lint.name, + &lint.default_level, + &lint.edition_lint_opts, + &lint.feature_gate, + )) + } else if let Some(group) = LINT_GROUPS.iter().find(|g| g.name == name) { + Some(( + group.name, + &group.default_level, + &group.edition_lint_opts, + &group.feature_gate, + )) + } else { + None + } +} + fn feature_gated_lint( lint_name: &str, feature_gate: &Feature, diff --git a/tests/testsuite/lints_table.rs b/tests/testsuite/lints_table.rs index 3ed6606bf3b9..6faa70944248 100644 --- a/tests/testsuite/lints_table.rs +++ b/tests/testsuite/lints_table.rs @@ -1164,7 +1164,20 @@ note: `cargo::im-a-teapot` was inherited | ---------------- | = help: consider adding `cargo-features = [\"test-dummy-unstable\"]` to the top of the manifest -error: encountered 1 errors(s) while verifying lints +error: use of unstable lint `test-dummy-unstable` + --> Cargo.toml:7:1 + | +7 | test-dummy-unstable = { level = \"forbid\", priority = -1 } + | ^^^^^^^^^^^^^^^^^^^ this is behind `test-dummy-unstable`, which is not enabled + | +note: `cargo::test-dummy-unstable` was inherited + --> foo/Cargo.toml:9:1 + | +9 | workspace = true + | ---------------- + | + = help: consider adding `cargo-features = [\"test-dummy-unstable\"]` to the top of the manifest +error: encountered 2 errors(s) while verifying lints ", ) .run();