Skip to content

fix(toml): deprecate hyphen lint names and error on duplicates#17051

Open
raushan728 wants to merge 4 commits into
rust-lang:masterfrom
raushan728:fix/lint-hyphen-deprecation-and-duplicate-detection
Open

fix(toml): deprecate hyphen lint names and error on duplicates#17051
raushan728 wants to merge 4 commits into
rust-lang:masterfrom
raushan728:fix/lint-hyphen-deprecation-and-duplicate-detection

Conversation

@raushan728

@raushan728 raushan728 commented May 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #13943

Lint names in [lints] accepted both - and _ as separators. This meant unexpected_cfgs and unexpected-cfgs were treated as distinct keys by the TOML parser, causing ambiguous behavior when both appeared in the same block.

Changes:

  • Deprecation warning when a lint name uses - instead of _, will not work in a future edition
  • Error when two lint names conflict after normalization
  • Normalize lint names to _ before passing them to rustc

@rustbot rustbot added A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2026
@rustbot

rustbot commented May 30, 2026

Copy link
Copy Markdown
Collaborator

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

));
}
if let Some(existing) = seen_normalized.get(&normalized) {
anyhow::bail!(

@epage epage May 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When a commit has "and" in it, it is a good sign it isn't atomic. This is a separate change.

This is also a breaking change. We either need to start as a future incompat warning or deprecate and error in the next edition.

View changes since the review

@raushan728 raushan728 May 31, 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.

Initially had edition-gated error for both but it broke existing crates on 2024 edition.Changed hyphen names to warnings.push only. For duplicates, kept bail! should this follow the same pattern as hyphen names warnings.push for now, error in future edition?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it is edition gated then it shouldn't affect 2024 edition.

Note: if we edition-gate an error, we need a hand-written migration in cargo fix

@raushan728 raushan728 Jun 17, 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.

Right, gating against 2024 was the bug since that's already shipped.
Which edition should the error land on, since 2024 is taken?

for (name, config) in lints {
let normalized = name.replace('-', "_");
if name.contains('-') {
warnings.push(format!(

@epage epage May 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The issue said we were suppose to error in the next edition.

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why was this resolved when that error is not present and no reason is given for why it was resolved?

@raushan728 raushan728 Jun 17, 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.

That was resolved too early without addressing your point. Will
restore the edition-gated error once we settle on the edition.

Comment thread tests/testsuite/lints/mod.rs Outdated
));
}
if let Some(existing) = seen_normalized.get(&normalized) {
anyhow::bail!(

@epage epage May 30, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we generate an error or push an error?

View changes since the review

@raushan728 raushan728 force-pushed the fix/lint-hyphen-deprecation-and-duplicate-detection branch 2 times, most recently from fae8f97 to 5cf81cd Compare May 31, 2026 06:56
@raushan728 raushan728 requested a review from epage May 31, 2026 07:21
Comment thread tests/testsuite/lints_table.rs Outdated
@raushan728 raushan728 force-pushed the fix/lint-hyphen-deprecation-and-duplicate-detection branch from 5cf81cd to 0f44606 Compare June 1, 2026 05:44
@rustbot

rustbot commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Comment on lines +2791 to +2795
let normalized_name = name.replace('-', "_");
let option = if tool == "rust" {
format!("{flag}={name}")
format!("{flag}={normalized_name}")
} else {
format!("{flag}={tool}::{name}")
format!("{flag}={tool}::{normalized_name}")

@epage epage Jun 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why does this commit exist?

View changes since the review

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.

rustc already accepts both forms in flags, so this isn't a bug fix, just consistency. Can drop it if you'd rather keep the diff minimal.

Comment on lines +50 to 51
[WARNING] Cargo.toml: `lints.cargo.im-a-teapot` is deprecated in favor of `lints.cargo.im_a_teapot` and will not work in a future edition
[WARNING] unknown lint: `im-a-teapot`

@epage epage Jun 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Something isn't working right with this

View changes since the review

Comment on lines +29 to 30
[WARNING] Cargo.toml: `lints.cargo.this-lint-does-not-exist` is deprecated in favor of `lints.cargo.this_lint_does_not_exist` and will not work in a future edition
[WARNING] unknown lint: `this-lint-does-not-exist`

@epage epage Jun 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This lint should likely be changed to this_lint_does_not_exist in a separate commit

View changes since the review

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.

These use hyphens incidentally to test something unrelated. Will add a prep commit renaming them to underscore first.


foo.cargo("check")
.with_stderr_data(str![[r#"
[WARNING] Cargo.toml: `lints.rust.confusable-idents` is deprecated in favor of `lints.rust.confusable_idents` and will not work in a future edition

@epage epage Jun 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In a separate commit, we should change this to confusable_idents

View changes since the review

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.

Same here, will fold into the prep commit.

Comment thread tests/testsuite/lints_table.rs Outdated
Comment on lines +859 to +865
unexpected-cfgs = "warn"
unexpected-cfgs = "allow"

@epage epage Jun 16, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this change made?

View changes since the review

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.

Leftover from a removed test case. Reverting to warn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-manifest Area: Cargo.toml issues S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lints table allows both - and _ separators, including allowing redundant entries.

3 participants