Skip to content

Rewrite cargo-clippy - #17573

Open
Jarcho wants to merge 1 commit into
rust-lang:masterfrom
Jarcho:cargo-clippy
Open

Rewrite cargo-clippy#17573
Jarcho wants to merge 1 commit into
rust-lang:masterfrom
Jarcho:cargo-clippy

Conversation

@Jarcho

@Jarcho Jarcho commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Not at all necessary rewrite, but it fixes a couple of weird things.

  • -h, -V and --explain are no longer parsed if they occur after the -- argument. Doesn't really make a difference in practice, but this matches how other programs with argument forwarding work.
  • --explain actually prints an error message when there's no argument.
  • --explain gives an error when it appears multiple times instead of only printing the first. Alternatively we could just print all lints.

This also doesn't walk the argument list four times. Not a big deal since the argument list is usually short and running cargo isn't exactly fast in the first place.

changelog: none

@rustbot rustbot added the S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. label Aug 16, 2026
@rustbot

rustbot commented Aug 16, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request. A reviewer will take a look after it receives 2 community reviews.

In the meantime, we would highly appreciate if you could try to review any of PRs waiting on community reviews.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 16, 2026
* Move all argument parsing into a single loop.
* Print an error when `--explain` is missing an argument.
* Print an error when there are multiple `--explain` arguments.
* Don't parse flags after `--`

@CommanderStorm CommanderStorm 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.

community review: LGTM, but two questions

View changes since this review

Comment thread src/main.rs
Comment on lines +51 to +52
// Cargo exited due to a signal
ExitCode::from(u8::MAX)

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.

not https://doc.rust-lang.org/beta/std/process/struct.ExitCode.html#associatedconstant.FAILURE ?

Both versions are fine with me, just asking if intentional.

Suggested change
// Cargo exited due to a signal
ExitCode::from(u8::MAX)
// Cargo exited due to a signal
ExitCode::FAILURE

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

We already have a unique exit code for this. Is it useful; probably not.

Comment thread src/main.rs
@@ -1,153 +1,167 @@
// We need this feature as it changes `dylib` linking behavior and allows us to link to
// `rustc_driver`.
#![feature(rustc_private)]

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 find the dylib explaination quite usefull as it is non-obvious.. can you re-add the comment here or in below expect?

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 feature doesn't change linking behaviour. Importing rustc_driver is what links to the dylib.

@rustbot

rustbot commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (possibly #17632) made this pull request unmergeable. Please resolve the merge conflicts.

pull Bot pushed a commit to Mattlk13/rust-clippy that referenced this pull request Aug 26, 2026
`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.

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

fixes rust-lang#17620

changelog: Fix `cargo clippy --explain <lint>` reporting `unknown lint`
for every lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants