Skip to content

Fix --explain lint lookup being case-mismatched - #17632

Merged
rustbot merged 1 commit into
rust-lang:masterfrom
arcusbuilds:fix-explain-lint-casing
Aug 26, 2026
Merged

Fix --explain lint lookup being case-mismatched#17632
rustbot merged 1 commit into
rust-lang:masterfrom
arcusbuilds:fix-explain-lint-casing

Conversation

@arcusbuilds

@arcusbuilds arcusbuilds commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

cargo clippy --explain <lint> prints unknown lint for every lint on beta and nightly.

src/main.rs lowercases the argument, but Lint::name is uppercase (clippy::ALLOW_ATTRIBUTES), so the lookup in explain never matches. The to_ascii_uppercase that reconciled the two was dropped in c97f7eb ("Rewrite of the config parsing code"), and this restores that line verbatim. beta and master carry the commit, stable 0.1.98 does not, which is why --explain still works there.

The lowercase rebinding below the lookup is deliberately left alone. mdconf.retain(...) keys on that form, so removing it would silently drop every configuration section.

The tests are new because --explain had no coverage at all, which is how this went unreported for three weeks.

cargo test --features internal passes here apart from the 16 tests/ui-internal cases, which fail the same way on an unmodified master checkout, so they look local to my Windows setup.

#17573 moves this code and inherits the same mismatch, so whichever lands second needs a small rebase.

fixes #17620

changelog: Fix cargo clippy --explain <lint> reporting unknown lint for every lint

@rustbot rustbot added S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Aug 26, 2026
@rustbot

rustbot commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome!

You should hear from one of our reviewers after this PR gets at least 2 reviews from the community.

Please see the contribution instructions for more information.

Comment thread tests/config-consistency.rs Outdated
Comment on lines +32 to +70
// `explain` receives the lint name already lowercased by `src/main.rs`, while
// `Lint::name` is uppercase, so the two have to be reconciled before the lookup.

#[test]
fn explain_finds_declared_lints() {
if option_env!("RUSTC_TEST_SUITE").is_some() {
return;
}

for info in clippy_lints::declared_lints::LINTS {
let name = info.lint.name.strip_prefix("clippy::").unwrap().to_lowercase();
assert_eq!(
clippy_lints::explain(&name),
0,
"`--explain {name}` did not find a lint that exists"
);
}
}

#[test]
fn explain_accepts_names_as_typed() {
if option_env!("RUSTC_TEST_SUITE").is_some() {
return;
}

// Spelled out rather than derived from `Lint::name`, so that the lookup is
// checked against the form a user actually passes to `--explain`.
for name in ["allow_attributes", "absurd_extreme_comparisons", "toplevel_ref_arg"] {
assert_eq!(clippy_lints::explain(name), 0, "`--explain {name}` did not find a lint");
}
}

#[test]
fn explain_rejects_unknown_lint() {
if option_env!("RUSTC_TEST_SUITE").is_some() {
return;
}

assert_eq!(clippy_lints::explain("this_lint_does_not_exist"), 1);

@Jarcho Jarcho Aug 26, 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.

These don't actually test what you want to test. You can get the built cargo-clippy path via env!("CARGO_BIN_EXE_cargo-clippy") and run it with --explain.

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.

Makes sense, thanks. Going through the binary also covers the lowercasing, the clippy:: stripping and the - to _ replacement in main.rs, none of which the direct call touches.

One thing before I write it: how many lints should it run? One process per lint puts all 832 at roughly a minute of wall clock, which feels like a lot to add to CI when they all go down the same path. I was going to spawn it for a couple of names plus the input forms main.rs actually rewrites:

  • allow_attributes
  • ALLOW_ATTRIBUTES
  • clippy::allow_attributes
  • allow-attributes
  • something unknown, expecting exit code 1

Would you rather it just iterate over declared_lints::LINTS and eat the runtime?

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.

I would just do lint-name, clippy::lint_name, LINT_NAME2, CLIPPY::LINT_NAME2 and not_a_lint. To test I would spawn all of them and then wait on the results; running them sequentially is pointlessly slow.

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.

Done, thanks. tests/explain.rs now spawns all five and waits afterwards, I gave it its own file rather than appending to config-consistency.rs, since that one is about config metadata and doesn't spawn anything.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Aug 26, 2026
@rustbot

rustbot commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Jarcho Jarcho added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Aug 26, 2026
`src/main.rs` lowercases the `--explain` argument, but `Lint::name` is
uppercase (`clippy::ALLOW_ATTRIBUTES`), so the lookup in `explain` never
matched and every lint reported `unknown lint`. The `to_ascii_uppercase`
that reconciled the two was dropped in c97f7eb.

Add a regression test that runs the built `cargo-clippy` binary, so the
argument conversion in `src/main.rs` is covered along with the lookup.
This code path had no tests at all.
@arcusbuilds
arcusbuilds force-pushed the fix-explain-lint-casing branch from 25a394a to 52bb2d9 Compare August 26, 2026 16:38

@Jarcho Jarcho left a comment

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.

Thank you. Going to merge this quickly since it needs to be backported.

@rustbot merge

View changes since this review

@rustbot
rustbot added this pull request to the merge queue Aug 26, 2026
Merged via the queue into rust-lang:master with commit b3e0e17 Aug 26, 2026
11 checks passed
@rustbot rustbot removed the S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. label Aug 26, 2026
This was referenced Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

beta-nominated Nominated for backporting to the compiler in the beta channel. S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cargo clippy --explain LINT only works on stable versions, regardless of which lint is passed

3 participants