Skip to content

Commit

Permalink
fix(lints): Mark the test_dummy_unstable lint group as unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
Muscraft committed May 1, 2024
1 parent f007527 commit 712946c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
44 changes: 38 additions & 6 deletions src/cargo/util/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 analyze_cargo_lints_table(
Expand All @@ -33,11 +34,13 @@ pub fn analyze_cargo_lints_table(
.keys()
.chain(ws_lints.map(|l| l.keys()).unwrap_or_default())
{
if let Some(lint) = LINTS.iter().find(|l| l.name == lint_name) {
if let Some((name, default_level, edition_lint_opts, feature_gate)) =
find_lint_or_group(lint_name)
{
let (_, reason, _) = level_priority(
lint.name,
lint.default_level,
lint.edition_lint_opts,
name,
*default_level,
*edition_lint_opts,
pkg_lints,
ws_lints,
manifest.edition(),
Expand All @@ -49,9 +52,9 @@ pub fn analyze_cargo_lints_table(
}

// Only run this on lints that are gated by a feature
if let Some(feature_gate) = lint.feature_gate {
if let Some(feature_gate) = feature_gate {
verify_feature_enabled(
lint.name,
name,
feature_gate,
reason,
manifest,
Expand All @@ -74,6 +77,33 @@ pub fn analyze_cargo_lints_table(
}
}

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 verify_feature_enabled(
lint_name: &str,
feature_gate: &Feature,
Expand Down Expand Up @@ -224,13 +254,15 @@ pub struct LintGroup {
pub default_level: LintLevel,
pub desc: &'static str,
pub edition_lint_opts: Option<(Edition, LintLevel)>,
pub feature_gate: Option<&'static Feature>,
}

const TEST_DUMMY_UNSTABLE: LintGroup = LintGroup {
name: "test_dummy_unstable",
desc: "test_dummy_unstable is meant to only be used in tests",
default_level: LintLevel::Allow,
edition_lint_opts: None,
feature_gate: Some(Feature::test_dummy_unstable()),
};

#[derive(Copy, Clone, Debug)]
Expand Down
15 changes: 14 additions & 1 deletion tests/testsuite/lints_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 712946c

Please sign in to comment.