Clippy subtree update - #161416
Conversation
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.
Per [#t-infra > funding link on rust-lang/rust is broken @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/242791-t-infra/topic/funding.20link.20on.20rust-lang.2Frust.20is.20broken/near/615432496), the current link is broken. changelog: none
…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
Closes rust-lang/rust-clippy#16798 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
…blocks Adding newline at end of file
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
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
|
@birs p=1 |
|
@bors p=1 |
|
@bors r- |
|
This pull request was unapproved. |
This comment has been minimized.
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`
This comment has been minimized.
This comment has been minimized.
|
This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp. |
|
While fixing the Clippy finding, I thought a bit about what the condition in
I don't think this is necessary, as there was no behavioral change? |
afb660d to
4031602
Compare
|
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. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
In a function with multiple `if .. { return _; }`s with a trailing `!_` at the end, combining the last `if`+`!_` doesn't
make the code less complex necessarily. It just moves the "problem" one up. Piping this through the entire `if` chain in
the function either requires a non-trivial refactor or makes the code potentially less readable. Both are not acceptable
for a complexity lint.
This adds a check to the lint that makes sure that there is no other `if` statement before the last collapsible `if`
statement.
Simplify bool condition in llvm CI download availability check in bootstrap
4031602 to
49944d9
Compare
|
Latest commit is a sync from an un-merged branch, so this needs a bit of work. I just want to check if this finally passes CI. |
|
Will do another Rust->Clippy sync tomorrow, as I want to resolve all conflicts on the Clippy side, so that I can do a clean |
r? Manishearth
Cargo.lock update due to Clippy version bump