Skip to content

Clippy subtree update - #161416

Draft
flip1995 wants to merge 91 commits into
rust-lang:mainfrom
flip1995:clippy-subtree-update
Draft

Clippy subtree update#161416
flip1995 wants to merge 91 commits into
rust-lang:mainfrom
flip1995:clippy-subtree-update

Conversation

@flip1995

@flip1995 flip1995 commented Aug 20, 2026

Copy link
Copy Markdown
Member

r? Manishearth

Cargo.lock update due to Clippy version bump

Gri-ffin and others added 30 commits July 10, 2026 20:08
This has multiple advantages:

 - Performance. The new type is 1/3 the size of `Vec` (being equivalent in layout to `Option<ThinVec>`) and can be kept in a register.
 - Type safety. We mark the type `#[must_use]`, and thinks requiring errors take `ThinVec`, which requires unwrapping the type and verifying there is indeed an error. We still provide conversions to slices, `ThinVec`, and iteration, because some code needs this and I saw no benefit in changing it, but we deliberately do not provide `Deref<Target = [E]>` or things like that.
…g#16634)

Closes rust-lang/rust-clippy#11529
Closes rust-lang/rust-clippy#16631
Closes rust-lang/rust-clippy#15560
Closes rust-lang/rust-clippy#16344

This PR addresses two problems of `needless_range_loop`:
1. It suggests wrongly when the index is after other indexes or field
accesses.
2. When the index is nested, it does not specify which index to replace,
making the suggestion confusing.

changelog: [`needless_range_loop`] fix wrong suggestions for nested
index
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/17499)*

Adds `unnecessary_nonzero_get`, a `complexity` lint that drops
`NonZero::get()` when the following method or operator is available on
`NonZero` itself with the same return type.

```rust
let _ = nz.get().leading_zeros();  // -> nz.leading_zeros()
let _ = x / nz.get();              // -> x / nz
```

Methods only match when the `NonZero` version returns the same type.
Cases like `bit_width` and `count_ones` return `NonZero`, so rewriting
those would move the `get` instead of removing it, and they are skipped.

Operators cover `/`, `%`, `/=` and `%=`. Three constraints keep the
suggestion sound:

- unsigned only, since `core` generates `Div`/`Rem` for `NonZero` from
the unsigned arm only
- not in const contexts, since the impls are `#[rustc_const_unstable]`
- exact operand types, since primitive operators forward references but
the `NonZero` impls do not

MSRV is read from the impl or method rather than hardcoded.

fixes rust-lang/rust-clippy#17483

- [x] Followed [lint naming conventions][lint_naming]
- [x] Added passing UI tests (including committed `.stderr` file)
- [x] `cargo test` passes locally
- [x] Executed `cargo dev update_lints`
- [x] Added lint documentation
- [x] Run `cargo dev fmt`

[lint_naming]:
https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

changelog: new lint: [`unnecessary_nonzero_get`]
When checking stdout/err, color codes will get in the way of the simple comparisons that are performed during tests.
Anyone setting CARGO_TERM_COLOR=always will experience test failures as a result.
This forcibly disables coloring.
…ust-lang#17530)

fixes rust-lang/rust-clippy#17501

changelog: [`cast_possible_truncation`]: fix `try_from` suggestion
expanding macros instead of showing the macro call
When checking stdout/err, color codes will get in the way of the simple
comparisons that are performed during tests. Anyone setting
CARGO_TERM_COLOR=always will experience test failures as a result. This
forcibly disables coloring for those tests that rely on doing a direct
comparison.

changelog: none
Extend the lint to catch

    if c {
        return W(true);
    }
    W(false)

and reduce it to `W(c)` (or `W(!c)`), where `W` is an optional tuple-like
constructor (`Ok`/`Some`/user enum & tuple-struct ctors) shared by both the
guard and the trailing expression, or absent.

Constructors are pure, so folding the condition into them preserves behavior.
The values must differ (equal values are skipped, since the condition could
have side effects), the guard body must be only the `return`, and the same
constructor must wrap both bools.

Also applies the new check to clippy's own source (dogfood).
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/17185)*

Extend the lint to catch

    if c {
        return W(true);
    }
    W(false)

and reduce it to `W(c)` (or `W(!c)`), where `W` is an optional
tuple-like
constructor (`Ok`/`Some`/user enum & tuple-struct ctors) shared by both
the
guard and the trailing expression, or absent.

Constructors are pure, so folding the condition into them preserves
behavior.
The values must differ (equal values are skipped, since the condition
could
have side effects), the guard body must be only the `return`, and the
same
constructor must wrap both bools.

---

See example in the wild: uutils/coreutils#12689

changelog: needless_bool: lint the early-return guard form
This is in preparation for renaming the default branch to `main`
(https://rust-lang.zulipchat.com/#narrow/channel/257328-t-clippy/topic/Renaming.20the.20Clippy.27s.20default.20branch.20to.20main/with/615804918).

It should build the docs into both the `master` and `main` directories.
After we confirm that this works, and that
https://rust-lang.github.io/rust-clippy/main is available, we can modify
Clippy to start generating links that will point to `main`, instead of
`master`.

changelog: none
@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Aug 20, 2026
@flip1995
flip1995 marked this pull request as ready for review August 20, 2026 17:59
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 20, 2026
@rustbot

rustbot commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 20, 2026
@rustbot

This comment has been minimized.

@Manishearth

Copy link
Copy Markdown
Member

@bors r+

@rust-bors

rust-bors Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 2b371e4 has been approved by Manishearth

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 20, 2026
@Manishearth

Copy link
Copy Markdown
Member

@birs p=1

@Manishearth

Copy link
Copy Markdown
Member

@bors p=1

@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors r-
Failed PR ci

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Aug 20, 2026
@rust-bors

rust-bors Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

View changes since this unapproval

@rust-log-analyzer

This comment has been minimized.

*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust-clippy/pull/17537)*

changelog: [`unnecessary_map_or`]: suggest `Result::is_ok` and
`Result::is_err` for boolean `map_or` and `map_or_else` branches

Fixes rust-lang/rust-clippy#5718

## Summary

- recognize `Result::map_or` and `Result::map_or_else` calls whose
branches return opposite boolean literals without using their arguments
- suggest `is_ok()` when the `Ok` branch is `true`, and `is_err()` when
the `Err` branch is `true`
- keep rustfix machine-applicable when drop order is insignificant,
while downgrading the suggestion and explaining the difference when the
result or its temporaries need ordered drop
- extend the lint documentation and cover single-line, multiline,
rustfix, negative, and significant-drop cases

## Validation

- `TESTNAME=unnecessary_map_or cargo uitest`
- `cargo dev fmt --check`
- `cargo test`
@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp.

@rustbot rustbot added the T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) label Aug 21, 2026
@flip1995

Copy link
Copy Markdown
Member Author

While fixing the Clippy finding, I thought a bit about what the condition in llvm.rs actually is trying to express. This was quite confusing with the double/triple negation going on there. So this requires bootstrap review. Or at least another person double checking my reasoning.

Consider updating src/bootstrap/download-ci-llvm-stamp.

I don't think this is necessary, as there was no behavioral change?

@flip1995
flip1995 force-pushed the clippy-subtree-update branch from afb660d to 4031602 Compare August 21, 2026 09:31
@rustbot

rustbot commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main 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.

@rustbot

This comment was marked as resolved.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    Checking tracing-subscriber v0.3.23
error: this `if` guard returns a bool literal and is followed by another
   --> compiler/rustc_target/src/callconv/mod.rs:201:9
    |
201 | /         if self.arg_ext != other.arg_ext {
202 | |             return false;
203 | |         }
204 | |         true
    | |____________^ help: you can reduce it to: `self.arg_ext == other.arg_ext`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/main/index.html#needless_bool
    = note: requested on the command line with `-D clippy::needless-bool`

[RUSTC-TIMING] nix test:false 1.397

@flip1995
flip1995 marked this pull request as draft August 21, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-clippy Relevant to the Clippy team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.