Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/workspace/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2698,7 +2698,23 @@ supported tools: {}",
if tool == "cargo" && !gctx.cli_unstable().cargo_lints {
warn_for_cargo_lint_feature(gctx, warnings);
}
let mut seen_normalized: HashMap<String, String> = HashMap::default();
for (name, config) in lints {
let normalized = name.replace('-', "_");
if name.contains('-') {
warnings.push(format!(
"`lints.{tool}.{name}` is deprecated in favor of \
`lints.{tool}.{normalized}` and will not work in a \
future edition"
));
}
if let Some(existing) = seen_normalized.get(&normalized) {
warnings.push(format!(
"duplicate lint `{existing}` in `[lints.{tool}]`, \
conflicts with `{name}` and will not work in a future edition"
));
}
seen_normalized.insert(normalized.clone(), name.to_string());
if let Some((prefix, suffix)) = name.split_once("::") {
if tool == prefix {
anyhow::bail!(
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3273,7 +3273,7 @@ authors = []
im-a-teapot = true

[lints.cargo]
im-a-teapot = "deny"
im_a_teapot = "deny"
"#,
)
.file("src/main.rs", "fn main() { let unused = 10; }")
Expand Down
17 changes: 8 additions & 9 deletions tests/testsuite/lints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ authors = []
im-a-teapot = true

[lints.cargo]
im-a-teapot = "warn"
im_a_teapot = "warn"
"#,
)
.file("src/lib.rs", "")
Expand All @@ -47,14 +47,13 @@ im-a-teapot = "warn"
foo.cargo("fetch -Zcargo-lints")
.masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"])
.with_stderr_data(str![[r#"
[WARNING] unknown lint: `im-a-teapot`
--> Cargo.toml:12:1
|
12 | im-a-teapot = "warn"
| ^^^^^^^^^^^
|
= [NOTE] `cargo::unknown_lints` is set to `warn` by default
= [HELP] there is a lint with a similar name: `im_a_teapot`
[WARNING] `im_a_teapot` is specified
--> Cargo.toml:9:1
|
9 | im-a-teapot = true
| ^^^^^^^^^^^^^^^^^^
|
= [NOTE] `cargo::im_a_teapot` is set to `warn` in `[lints]`
[WARNING] `foo` (manifest) generated 1 warning

"#]])
Expand Down
18 changes: 9 additions & 9 deletions tests/testsuite/lints/unknown_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ authors = []
[lints.cargo]
default = { level = "allow", priority = -1 }
unknown_lints = "warn"
this-lint-does-not-exist = "warn"
this_lint_does_not_exist = "warn"
"#,
)
.file("src/lib.rs", "")
Expand All @@ -26,10 +26,10 @@ this-lint-does-not-exist = "warn"
p.cargo("fetch -Zcargo-lints")
.masquerade_as_nightly_cargo(&["cargo-lints"])
.with_stderr_data(str![[r#"
[WARNING] unknown lint: `this-lint-does-not-exist`
[WARNING] unknown lint: `this_lint_does_not_exist`
--> Cargo.toml:11:1
|
11 | this-lint-does-not-exist = "warn"
11 | this_lint_does_not_exist = "warn"
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= [NOTE] `cargo::unknown_lints` is set to `warn` in `[lints]`
Expand All @@ -51,7 +51,7 @@ members = ["foo"]
[workspace.lints.cargo]
default = { level = "allow", priority = -1 }
unknown_lints = "warn"
this-lint-does-not-exist = "warn"
this_lint_does_not_exist = "warn"
"#,
)
.file(
Expand All @@ -73,10 +73,10 @@ workspace = true
p.cargo("fetch -Zcargo-lints")
.masquerade_as_nightly_cargo(&["cargo-lints"])
.with_stderr_data(str![[r#"
[WARNING] unknown lint: `this-lint-does-not-exist`
[WARNING] unknown lint: `this_lint_does_not_exist`
--> Cargo.toml:8:1
|
8 | this-lint-does-not-exist = "warn"
8 | this_lint_does_not_exist = "warn"
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= [NOTE] `cargo::unknown_lints` is set to `warn` in `[lints]`
Expand All @@ -98,7 +98,7 @@ members = ["foo"]
[workspace.lints.cargo]
default = { level = "allow", priority = -1 }
unknown_lints = "warn"
this-lint-does-not-exist = "warn"
this_lint_does_not_exist = "warn"
"#,
)
.file(
Expand All @@ -117,10 +117,10 @@ authors = []
p.cargo("fetch -Zcargo-lints")
.masquerade_as_nightly_cargo(&["cargo-lints"])
.with_stderr_data(str![[r#"
[WARNING] unknown lint: `this-lint-does-not-exist`
[WARNING] unknown lint: `this_lint_does_not_exist`
--> Cargo.toml:8:1
|
8 | this-lint-does-not-exist = "warn"
8 | this_lint_does_not_exist = "warn"
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= [NOTE] `cargo::unknown_lints` is set to `warn` in `[lints]`
Expand Down
74 changes: 67 additions & 7 deletions tests/testsuite/lints_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn invalid_type_in_lint_value() {
edition = "2015"

[workspace.lints.rust]
rust-2018-idioms = -1
rust_2018_idioms = -1
"#,
)
.file("src/lib.rs", "")
Expand All @@ -137,7 +137,7 @@ fn invalid_type_in_lint_value() {
[ERROR] invalid type: integer `-1`, expected a string or map
--> Cargo.toml:8:36
|
8 | rust-2018-idioms = -1
8 | rust_2018_idioms = -1
| ^^

"#]])
Expand All @@ -156,18 +156,18 @@ fn warn_on_unused_key() {
edition = "2015"

[workspace.lints.rust]
rust-2018-idioms = { level = "allow", unused = true }
rust_2018_idioms = { level = "allow", unused = true }
[lints.rust]
rust-2018-idioms = { level = "allow", unused = true }
rust_2018_idioms = { level = "allow", unused = true }
"#,
)
.file("src/lib.rs", "")
.build();

foo.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] Cargo.toml: unused manifest key: `lints.rust.rust-2018-idioms.unused`
[WARNING] Cargo.toml: unused manifest key: `lints.rust.rust-2018-idioms.unused`
[WARNING] Cargo.toml: unused manifest key: `lints.rust.rust_2018_idioms.unused`
[WARNING] Cargo.toml: unused manifest key: `lints.rust.rust_2018_idioms.unused`
[WARNING] `foo` (manifest) generated 2 warnings
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
Expand Down Expand Up @@ -697,7 +697,7 @@ fn doctest_respects_lints() {
authors = []

[lints.rust]
confusable-idents = 'allow'
confusable_idents = 'allow'
"#,
)
.file(
Expand Down Expand Up @@ -843,3 +843,63 @@ im_a_teapot = "warn"
"#]])
.run();
}

#[cargo_test]
fn hyphen_in_lint_name() {
let foo = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"

[lints.rust]
unexpected-cfgs = "warn"
"#,
)
.file("src/lib.rs", "")
.build();

foo.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] Cargo.toml: `lints.rust.unexpected-cfgs` is deprecated in favor of `lints.rust.unexpected_cfgs` and will not work in a future edition
[WARNING] `foo` (manifest) generated 1 warning
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run();
}

#[cargo_test]
fn duplicate_lint_name_hyphen_and_underscore() {
let foo = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
edition = "2015"

[lints.rust]
unexpected_cfgs = "warn"
unexpected-cfgs = "allow"
"#,
)
.file("src/lib.rs", "")
.build();

foo.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] Cargo.toml: `lints.rust.unexpected-cfgs` is deprecated in favor of `lints.rust.unexpected_cfgs` and will not work in a future edition
[WARNING] Cargo.toml: duplicate lint `unexpected-cfgs` in `[lints.rust]`, conflicts with `unexpected_cfgs` and will not work in a future edition
Comment on lines +897 to +898

@raushan728 raushan728 Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first one fires simply for using a hyphen in the lint name, and the second one fires because it creates a duplicate conflict after normalization.

View changes since the review

[WARNING] `foo` (manifest) generated 2 warnings
[CHECKING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run();
}