Previously the program only fixed the code when the closure supplied to
the method contained only 1 line. This patch removes the restriction.
The code already works. This patch only removes the extra check that
causes the restriction. The test cases that can now be fixed are moved
into the files containing tests cases that can be fixed.
The unnecessary check has survived in the code this way.
- In Dec 2015, patch a6bd2d0622, pull request
rust-lang/rust-clippy#524. The lint was first added. The program did not
support fixing code automatically yet. So the suggested fix was printed
as a part of the diagnostic message. When the original code contained
multiple lines, the suggested fix was omitted in order to keep the
diagnostic message concise.
- In May 2019, patch bd0b75f6c3, pull request
rust-lang/rust-clippy#4049. Logic was added to strip the reference in
the closure when the suggested replacement method required it. Because
the fix was still only printed when the code contained a single line,
the new transformation was only done when the code contained a single
line.
- In Aug 2019, patch 945d4cf69f, pull request
rust-lang/rust-clippy#4454. The lint was updated to fix code
automatically. Because the fixed code had only been printed in the
diagnostic message for a single line, the fix was only added for a
single line.
- In Nov 2021, patch 092fe209a6, pull request
rust-lang/rust-clippy#7463. The logic for transforming the closure was
moved into another file. A comment was added saying that it was only
good for a single line because it had only been used for a single line.
changelog: [`search_is_some`] now fixes code spanning multiple lines
Since an `asm!()` statement is mostly unknown, as we do not know what it
does, consider all labels' `break` as being conditionally executed only.
Fixesrust-lang/rust-clippy#15673
changelog: [`never_loop`]: do not consider `break` labels used in
`asm!()` as being unconditionally executed as they might not be
`|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)
The `multilingual` field has been removed in mdbook 0.5. Additionally
this removes the unnecessary `src` value which defaults to the same
value.
changelog: none
`|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()`.
Previously the program only fixed the code when the closure supplied to
the method contained only 1 line. This patch removes the restriction.
The code already works. This patch only removes the extra check that
causes the restriction. The test cases that can now be fixed are moved
into the files containing tests cases that can be fixed.
The unnecessary check has survived in the code this way.
- In Dec 2015, patch a6bd2d0622, pull request 524. The lint was first
added. The program did not support fixing code automatically yet. So
the suggested fix was printed as a part of the diagnostic message.
When the original code contained multiple lines, the suggested fix was
omitted in order to keep the diagnostic message concise.
- In May 2019, patch bd0b75f6c3, pull request 4049. Logic was added
to strip the reference in the closure when the suggested replacement
method required it. Because the fix was still only printed when the
code contained a single line, the new transformation was only done
when the code contained a single line.
- In Aug 2019, patch 945d4cf69f, pull request 4454. The lint was
updated to fix code automatically. Because the fixed code had only
been printed in the diagnostic message for a single line, the fix was
only added for a single line.
- In Nov 2021, patch 092fe209a6, pull request 7463. The logic for
transforming the closure was moved into another file. A comment was
added saying that it was only good for a single line because it had
only been used for a single line.
changelog: [`search_is_some`] now fixes code spanning multiple lines
`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 `(...)`
Based on rust-lang/rust-clippy#15866
This adds a parsing context that can allocate from an arena. Ultimately
this will also store a source map for better error reporting, but a few
other changes are happening before that.
The arena itself is unlikely to be needed from a perf standpoint
(reading all the files should be the slow part), but having more things
be copyable is nice. For reference the perf impact of this change is
within the noise.
changelog: none
Supercedes rust-lang/rust-clippy#15270
This first PR just moves the existing code and simplifies a few things.
The switch to use the new range API isn't really used in this PR , but
it's needed by future changes to avoid having to add `.clone()` all over
the place.
changelog: none
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
`NB!` is extremely alien + not used anywhere else in repo (per github
search).
`Notes => Note`. At first thought was convention (written from
perspective of the lint), but not seen anywhere else in repo (per github
search).
Implication: clearer docs
Changes made from github web editor; no tests/checks performed.
changelog: none
- 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
- Make the diagnostic message actually desribe the problem
- Make the suggestion verbose, because we lint multiline exprs
changelog: [`match_as_ref`]: improve diagnostics