`|x: String| {x}.clone()` applies `clone()` to `{x}`, while `|x: String|
-> String {x}.clone()` applies `.clone()` to the closure because a
closure with an explicit return type requires a block as its body.
This extends the `precedence` lint to suggest using parentheses around
the closure definition in the second case, when `.clone()` would apply
to the whole closure.
changelog: [`precedence`]: warn about ambiguity when a closure is used
as a method call receiver
[Related
discussion](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/Closure.20syntax.20ambiguity/with/504671477)
`|x: String| {x}.clone()` applies `clone()` to {x}, while
`|x: String| -> String {x}.clone()` applies `.clone()` to
the closure because a closure with an explicit return type
requires a block.
This extends the `precedence` lint to suggest using parentheses
around the closure definition when the closure would be cloned,
as in `(|x: String| -> String {x}).clone()`.
`let-else` statements do not allow the init expression to end with '}'
Fixesrust-lang/rust-clippy#15914
changelog: [`manual_let_else`]: If the init expression ends with `'}'`
wrap it with `(...)`
I first implemented the naive version, which just talks about, and
suggests using, `Option::as_ref`. But the resulting error message
sounded a bit misleading -- after all, the manual implementation was
factually that of `Option::as_mut`, and we only suggest `as_ref` as a
means of downcasting. So then I added another help message to mention
the need for reference downcasting, which.. still looks awkward.
Honestly it might be the easiest to hide the reference downcasting into
the `.map` after all, so that it encapsulates _all_ the casting needed
following the switch to `as_ref`/`as_mut`.
changelog: [`match_as_ref`]: suggest `as_ref` when the reference needs
to be cast
r? @samueltardieu
It's nice to come up with a clever algorithm
(https://github.com/rust-lang/rust-clippy/pull/15667), but it's even
nicer to reuse logic that already exists elsewhere.
changelog: none
r? @samueltardieu as you reviewed the original PR
- Make the diagnostic message actually desribe the problem
- Always give the suggestion, by using `snippet_with_context`
- Make the suggestion verbose, because we sometimes lint multiline exprs
like `match`es
changelog: [`manual_option_as_slice`]: improve diagnostics
- only lint on definitions of offending mutexes, not all their uses
(fixes https://github.com/rust-lang/rust-clippy/issues/13378)
- give more orderly help messages
- stop linting on `Mutex<*const T>` (see the corresponding commit for
context)
- offer (partial) suggestions
The last change might be deemed a bit too much for the feature freeze,
but it can be easily extracted out into a separate PR.
changelog: [`mutex_atomic`]: only lint the definitions, not uses
changelog: [`mutex_atomic`]: better help messages, and suggestions
changelog: [`mutex_atomic`]: don't lint `Mutex<*const T>`
changelog: [`mutex_integer`]: only lint the definitions, not uses
changelog: [`mutex_integer`]: better help messages, and suggestions
It's common to import dependencies from the sysroot via `extern crate`
rather than use an explicit cargo dependency, when it's necessary to use
the same dependency version as used by rustc itself. However, this is
dangerous for crates.io crates, since rustc may not pull in the
dependency on some targets, or may pull in multiple versions. In both
cases, the `extern crate` fails to resolve.
To address this, re-export all such dependencies from the appropriate
`rustc_*` crates, and use this alias from crates which would otherwise
need to use `extern crate`.
Based on
https://github.com/rust-lang/rust-clippy/pull/15520#discussion_r2372599748,
with the following changes/additions:
- No longer use the `Trait` enum for quickly filtering out irrelevant
impls -- instead, check the `trait_of` basically right away:
1. pre-fetch `DefId`s of the relevant traits into the lint pass
2. reuse `cx.tcx.impl_trait_ref`'s output for the the `DefId` of the
trait being implemented
3. compare those `DefId`s, which should be very cheap
- Next, check whether `self_ty` implements the other relevant trait.
- Pre-filter impl items in the same (lazy) iterator, but delay the
proc-macro check as much as possible
changelog: none
Not auto-assigning since @blyxyas and/or @Jarcho will be the ones
reviewing it:
r? ghost
Resolvesrust-lang/rust-clippy#15780.
I didn't get any feedback on that issue. So I hope it is okay that I
charged ahead and addressed it.
changelog: Allow `explicit_write` in tests