Commit graph

24100 commits

Author SHA1 Message Date
Jason Newcomb
f144c6cc66
feat(search_is_some): Fix when the closure spans multiple lines (#15902)
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
2025-10-28 09:39:01 +00:00
Alex Macleod
0226fa9470
Consider labels of inline asm as conditionally executed (#15676)
Since an `asm!()` statement is mostly unknown, as we do not know what it
does, consider all labels' `break` as being conditionally executed only.

Fixes rust-lang/rust-clippy#15673

changelog: [`never_loop`]: do not consider `break` labels used in
`asm!()` as being unconditionally executed as they might not be
2025-10-27 21:22:40 +00:00
dswij
ca168c07a6
unnecessary_{find,filter}_map: make diagnostic spans more precise (#15929)
changelog: [`unnecessary_find_map`]: make diagnostic spans more precise
changelog: [`unnecessary_filter_map`]: make diagnostic spans more
precise
2025-10-27 15:32:05 +00:00
Samuel Tardieu
a5b3c445da
Consider labels of inline asm as conditionally executed
Since an `asm!()` statement is mostly unknown, as we do not know what it
does, consider all labels' `break` as being conditionally executed only.
2025-10-27 15:05:48 +01:00
Alex Macleod
0029a91219
Lint precedence possible ambiguity between closure and method call (#14421)
`|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)
2025-10-27 13:12:49 +00:00
Alex Macleod
b0d93f123a
chore(needless_if): rename to needless_ifs (#15961)
Lint names should be in plural.

changelog: [`needless_if`]: rename to `needless_ifs`
2025-10-27 13:06:57 +00:00
Ada Alakbarova
640e1188f0
chore(needless_if): rename to needless_ifs 2025-10-27 11:00:57 +01:00
Samuel Tardieu
a0a347e25c
fix(needless_if): don't expand macro invocations in the suggestion (#15960)
Fixes https://github.com/rust-lang/rust-clippy/issues/15959

changelog: [`needless_if`]: don't expand macro invocations in the
suggestion
2025-10-27 08:45:42 +00:00
Samuel Tardieu
c5714b0f0c
Prepare for mdbook 0.5 (#15965)
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
2025-10-27 08:31:11 +00:00
Samuel Tardieu
da8965202a
refactor(double_comparison): clean-up, simplify lint logic (#15955)
- use let-chains
- rm macro
- add comments explaining linted cases

changelog: none
2025-10-27 08:03:05 +00:00
Samuel Tardieu
12b011b809
Lint precedence possible ambiguity between closure and method call
`|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()`.
2025-10-27 07:58:41 +01:00
Jason Newcomb
25cbcb4331
refactor(lines_filter_map_ok): move to under methods/ (#15925)
changelog: none
2025-10-26 22:04:43 +00:00
Eric Huss
0ba9ba7db8 Prepare for mdbook 0.5
The `multilingual` field has been removed in mdbook 0.5. Additionally
this removes the unnecessary `src` value which defaults to the same
value.
2025-10-26 14:47:09 -07:00
Ada Alakbarova
ce2ef31ed6
fix(needless_if): don't expand macro invocations in the suggestion 2025-10-26 15:51:52 +01:00
Ada Alakbarova
aae10d749f
refactor(double_comparison): clean-up, simplify lint logic
- use let-chains
- rm macro
- add comments explaining linted cases
2025-10-26 10:49:08 +01:00
ceptontech
622a77d288 feat(search_is_some): Fix when the closure spans multiple lines
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
2025-10-24 14:33:47 -07:00
Jason Newcomb
d1b51eafaa
{option,result}_map_unit_fn: fix and clean-up tests, make suggestions multiline (#15871)
changelog: none
2025-10-24 20:46:18 +00:00
Jason Newcomb
3dcf3990f5
fix(manual_let_else): expressions ending with '}' (#15919)
`let-else` statements do not allow the init expression to end with '}'

Fixes rust-lang/rust-clippy#15914

changelog: [`manual_let_else`]: If the init expression ends with `'}'`
wrap it with `(...)`
2025-10-24 20:29:37 +00:00
Jason Newcomb
f975caac48
Fix trait method checking in book (#15941)
changelog: none

Fixes rust-lang/rust-clippy#15938

r? Jarcho
2025-10-24 20:15:27 +00:00
Samuel Tardieu
8ff0cf8551
Fix len_zero FP on unstable methods (#15894)
Closes rust-lang/rust-clippy#15890

changelog: [`len_zero`] fix FP on unstable methods
2025-10-23 22:16:54 +00:00
yanglsh
9eba2cccd8 fix: len_zero FP on unstable methods 2025-10-24 05:58:18 +08:00
Samuel Tardieu
0cc159480e
Fix trait method checking in book 2025-10-23 22:50:04 +02:00
Ada Alakbarova
9145cee025
make the spans more precise 2025-10-23 19:02:34 +02:00
Ada Alakbarova
9fd359b53e
clean-up
- introduce `Kind`: a bit more type-safe and hopefully a bit faster
2025-10-23 19:02:25 +02:00
dswij
09c3237590
chore(empty_enum): rename to empty_enums (#15912)
According to the lint naming guidelines[^1], lint names should use the
plural form.

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

changelog: [`empty_enum`]: rename to `empty_enums`
2025-10-23 15:50:20 +00:00
Samuel Tardieu
82d729cacb
clippy_dev: Parsing revamp part 2/N (#15921)
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
2025-10-23 09:18:46 +00:00
Jason Newcomb
bae625fed0 clippy_dev: Allocate onto an arena when parsing. 2025-10-22 19:09:23 -04:00
Jason Newcomb
7579e71c1f clippy_dev: Inline and simplify read_src_with_module. 2025-10-22 19:09:23 -04:00
Jason Newcomb
fcfab5fe4b clippy_dev: Move all parsing within a parse context. 2025-10-22 19:09:23 -04:00
Samuel Tardieu
00f68d530d
clippy_dev: parsing revamp 1/N (#15866)
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
2025-10-22 16:53:49 +00:00
Samuel Tardieu
0c592df5a5
fix(match_as_ref): suggest as_ref when the reference needs to be cast (#15934)
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
2025-10-22 11:22:20 +00:00
Ada Alakbarova
22bdd9f7c9
fix(match_as_ref): suggest as_ref when the reference needs to be cast 2025-10-22 13:16:00 +02:00
Samuel Tardieu
2bb3d0c396
refactor(elidable_lifetimes): harmonize suggestion-building logic with extra_unused_type_parameters (#15908)
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
2025-10-22 10:15:01 +00:00
Ada Alakbarova
5ff804e9b2
misc: move infallible stuff out of the way 2025-10-22 11:59:21 +02:00
Samuel Tardieu
fd208399ae
Make docs more clear (#15933)
`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
2025-10-22 08:30:46 +00:00
Zylos
bab7519d5b
Update mod.rs 2025-10-21 21:43:34 -04:00
Ada Alakbarova
17f194238d
Adapt the logic from extra_unused_type_parameters
.. and add some docs to both of them
2025-10-22 01:06:13 +02:00
Samuel Tardieu
c6c71afda1
refactor(option_as_ref_cloned): move the method_call call out of the check (#15917)
This is more consistent with what the other `methods/` lints do.

changelog: none
2025-10-21 22:49:09 +00:00
Samuel Tardieu
fb82de5ed8
`manual_option_as_slice: improve diagnostics (#15926)
- 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
2025-10-21 22:07:49 +00:00
Samuel Tardieu
039b40f7c9
match_as_ref: improve diagnostics (#15928)
- Make the diagnostic message actually desribe the problem
- Make the suggestion verbose, because we lint multiline exprs

changelog: [`match_as_ref`]: improve diagnostics
2025-10-21 22:03:15 +00:00
Ada Alakbarova
81d2300862
move to methods/, for real this time 2025-10-21 22:15:15 +02:00
Ada Alakbarova
37ebd4c97e
move the lint file to under methods/
WARNING: this commit won't compile
2025-10-21 22:14:59 +02:00
Ada Alakbarova
a6e5159c7d
fix: parenthesise the receiver if needed 2025-10-21 18:11:39 +02:00
Ada Alakbarova
cb33ccd3fe
improve diagnostics 2025-10-21 16:51:33 +02:00
Ada Alakbarova
91dbaae9ad
improve diagnostics 2025-10-21 16:51:14 +02:00
Ada Alakbarova
a8fa9e1627
clean-up 2025-10-21 16:48:37 +02:00
Ada Alakbarova
c5215b6d84
clean-up a bit 2025-10-21 15:36:06 +02:00
Ada Alakbarova
d9ecbb73e8
clean-up 2025-10-21 14:17:20 +02:00
Alex Macleod
973e596eb0
option_option: split part of diagnostic message into help message (#15870)
changelog: [`option_option`]: improve diagnostic message
2025-10-20 17:54:59 +00:00
Teodoro Freund
0702934c98 manual_let_else fix when expression finishes with '}' 2025-10-20 16:22:12 +01:00