diff --git a/src/cargo/util/lints.rs b/src/cargo/util/lints.rs index da6d1c69a677..efc5d82c2654 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( @@ -29,20 +30,41 @@ pub fn verify_lints( let manifest_path = rel_cwd_manifest_path(path, gctx); let ws_path = rel_cwd_manifest_path(ws_path, gctx); + let iter = LINTS + .iter() + .map(|l| (l.name, l.default_level, l.edition_lint_opts, l.feature_gate)) + .chain( + LINT_GROUPS + .iter() + .map(|g| (g.name, g.default_level, g.edition_lint_opts, g.feature_gate)), + ) + .collect::>(); for lint_name in pkg_lints.keys().chain(ws_lints.keys()) { - if let Some(lint) = LINTS.iter().find(|l| l.name == lint_name) { - let (_, reason) = lint.level(pkg_lints, ws_lints, manifest.edition()); - feature_gated_lint( - lint, - reason, - manifest, - &manifest_path, - ws_contents, - ws_document, - &ws_path, - &mut error_count, - gctx, - )?; + if let Some((name, default_level, edition_lint_opts, feature_gate)) = + iter.iter().find(|(n, _, _, _)| n == &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( + name, + feature_gate, + reason, + manifest, + &manifest_path, + ws_contents, + ws_document, + &ws_path, + &mut error_count, + gctx, + )?; + } } } if error_count > 0 { @@ -55,7 +77,8 @@ pub fn verify_lints( } fn feature_gated_lint( - lint: &Lint, + lint_name: &str, + feature_gate: &Feature, reason: LintLevelReason, manifest: &Manifest, manifest_path: &str, @@ -65,14 +88,11 @@ fn feature_gated_lint( error_count: &mut usize, gctx: &GlobalContext, ) -> CargoResult<()> { - if lint - .feature_gate - .map_or(false, |f| !manifest.unstable_features().is_enabled(f)) - { - let dash_name = lint.name.replace("_", "-"); + if !manifest.unstable_features().is_enabled(feature_gate) { + let dash_name = lint_name.replace("_", "-"); let title = "verification of lint failed"; let label = "use of unstable lint that has not been enabled"; - let second_title = format!("`cargo::{}` was inherited", lint.name); + let second_title = format!("`cargo::{}` was inherited", lint_name); let message = match reason { LintLevelReason::Package => { let span = get_span( @@ -82,7 +102,7 @@ fn feature_gated_lint( ) .or(get_span( manifest.document(), - &["lints", "cargo", lint.name], + &["lints", "cargo", lint_name], false, )) .unwrap(); @@ -103,7 +123,7 @@ fn feature_gated_lint( ) .or(get_span( ws_document, - &["workspace", "lints", "cargo", lint.name], + &["workspace", "lints", "cargo", lint_name], false, )) .unwrap(); diff --git a/tests/testsuite/lints_table.rs b/tests/testsuite/lints_table.rs index 51d00300279a..b921a57267ff 100644 --- a/tests/testsuite/lints_table.rs +++ b/tests/testsuite/lints_table.rs @@ -1066,7 +1066,19 @@ note: `cargo::im_a_teapot` was inherited 9 | workspace = true | --------- | -error: encountered 1 errors(s) while verifying lints +error: verification of lint failed + --> Cargo.toml:7:1 + | +7 | test-dummy-unstable = { level = \"forbid\", priority = -1 } + | ^^^^^^^^^^^^^^^^^^^ use of unstable lint that has not been enabled + | +note: `cargo::test_dummy_unstable` was inherited + --> foo/Cargo.toml:9:1 + | +9 | workspace = true + | --------- + | +error: encountered 2 errors(s) while verifying lints ", ) .run();