diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 0b0e6d74961..d05b802cf79 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -1128,18 +1128,23 @@ impl<'gctx> Workspace<'gctx> { pub fn emit_lints(&self, pkg: &Package, path: &Path) -> CargoResult<()> { let mut error_count = 0; - let lints = pkg + let toml_lints = pkg .manifest() .resolved_toml() .lints .clone() .map(|lints| lints.lints) - .unwrap_or(manifest::TomlLints::default()) + .unwrap_or(manifest::TomlLints::default()); + let cargo_lints = toml_lints .get("cargo") .cloned() .unwrap_or(manifest::TomlToolLints::default()); + let normalized_lints = cargo_lints + .into_iter() + .map(|(name, lint)| (name.replace('-', "_"), lint)) + .collect(); - check_implicit_features(pkg, &path, &lints, &mut error_count, self.gctx)?; + check_implicit_features(pkg, &path, &normalized_lints, &mut error_count, self.gctx)?; if error_count > 0 { Err(crate::util::errors::AlreadyPrintedError::new(anyhow!( "encountered {error_count} errors(s) while running lints" diff --git a/src/cargo/util/lints.rs b/src/cargo/util/lints.rs index 7c6ecb58ea3..f2291f1b236 100644 --- a/src/cargo/util/lints.rs +++ b/src/cargo/util/lints.rs @@ -67,7 +67,7 @@ pub struct LintGroup { } const RUST_2024_COMPATIBILITY: LintGroup = LintGroup { - name: "rust-2024-compatibility", + name: "rust_2024_compatibility", default_level: LintLevel::Allow, desc: "warn about compatibility with Rust 2024", edition_lint_opts: Some((Edition::Edition2024, LintLevel::Deny)), @@ -150,7 +150,7 @@ impl From for LintLevel { /// [RFC #3143]: https://rust-lang.github.io/rfcs/3143-cargo-weak-namespaced-features.html /// [RFC #3491]: https://rust-lang.github.io/rfcs/3491-remove-implicit-features.html const IMPLICIT_FEATURES: Lint = Lint { - name: "implicit-features", + name: "implicit_features", desc: "warn about the use of unstable features", groups: &[RUST_2024_COMPATIBILITY], default_level: LintLevel::Allow, diff --git a/tests/testsuite/lints_table.rs b/tests/testsuite/lints_table.rs index 457cbe9344c..2f37063ae47 100644 --- a/tests/testsuite/lints_table.rs +++ b/tests/testsuite/lints_table.rs @@ -846,3 +846,45 @@ fn cargo_lints_success() { ) .run(); } + +#[cargo_test] +fn cargo_lints_underscore_supported() { + Package::new("bar", "0.1.0").publish(); + let foo = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + edition = "2021" + authors = [] + + [lints.cargo] + "implicit_features" = "warn" + + [dependencies] + bar = { version = "0.1.0", optional = true } + "#, + ) + .file("src/lib.rs", "") + .build(); + + foo.cargo("check -Zcargo-lints") + .masquerade_as_nightly_cargo(&["-Zcargo-lints"]) + .with_stderr( + "\ +warning: unused optional dependency + --> Cargo.toml:12:17 + | +12 | bar = { version = \"0.1.0\", optional = true } + | --- + | +[UPDATING] `dummy-registry` index +[LOCKING] [..] +[CHECKING] foo v0.0.1 ([CWD]) +[FINISHED] [..] +", + ) + .run(); +}