Commit Graph

9554 Commits

Author SHA1 Message Date
Jana Dönszelmann
477be9470a add tests for spurious failure and fix typo 2025-02-07 16:59:17 +01:00
Jonathan Dönszelmann
4044c1aa49 fix empty after lint on impl/trait items
Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2025-02-07 16:47:26 +01:00
Guillaume Gomez
42453bd73a Update UI tests 2025-02-07 16:47:26 +01:00
Catherine Flores
0d3bf65bd4 useless_asref: no lint if in a closure to change the ref depth (#14090)
Removing the `.as_ref()` or `.as_mut()` as the top-level expression in a
closure may change the type of the result. In this case, it may be
better not to lint rather than proposing a fix that would not work.

changelog: [`useless_asref`]: do not remove the `.as_ref()` or
`.as_mut()` call if this would change the type of the enclosing closure

Fix #14088
2025-02-07 13:33:18 +00:00
llogiq
f6d23c8d59 Handle more cases in is_normalizable (#13833)
By assuming that a recursive type is normalizable within the deeper
calls to `is_normalizable_helper()`, more cases can be handled by this
function.

In order to fix stack overflows, a recursion limit has also been added
for recursive generic type instantiations.

Fix #9798
Fix #10508
Fix #11915

changelog: [`large_enum_variant`]: more precise detection of variants
with large size differences
2025-02-07 13:20:11 +00:00
Catherine Flores
b0ad06daa8 add MSRV check for lines_filter_map_ok (#14130)
fixes #14127

changelog: [`lines_filter_map_ok`]: respect MSRV
2025-02-07 12:24:50 +00:00
Jason Newcomb
888365d7e5 Don't use labeled block as top-level blocks (#14102)
Labeled blocks cannot be used as-is in the "then" or "else" part of an
`if` expression. They must be enclosed in an anonymous block.

Fix #14099

changelog: [`match_bool`]: fix suggestion when the rewritten block has a
label
2025-02-06 20:51:41 +00:00
Jason Newcomb
7cda242e3c don't emit suggestion inside macro in manual_async_fn (#14142)
fixes #12407

I think it is meaningful to emit a warning even if the span is in a
macro.

changelog: [`manual_async_fn`]: don't emit suggestion inside macro
2025-02-06 20:38:46 +00:00
Alex Macleod
20b2461938 Skip use_self inside macro expansions of a impl Self block (#13128)
changelog: [`use_self`] Skip if inside macro expansions of a `impl Self`
block
Fixes #13092.
r? Alexendoo
2025-02-06 14:43:39 +00:00
Philipp Krones
5aa9d7ae7f Merge commit '3e3715c31236bff56f1c63a1de2c7bbdfcfb0923' into clippy-subtree-update 2025-02-06 15:00:24 +01:00
Philipp Krones
f549562b81 Merge remote-tracking branch 'upstream/master' into rustup 2025-02-06 14:31:01 +01:00
Lzu Tao
9ea2b6501e add test to check for popping wrong items
co-authored-by: Alex Macleod <alex@macleod.io>
2025-02-06 14:34:55 +07:00
Lzu Tao
bcfd0d1aba Skip use_self inside macro expansion of impl Self items 2025-02-06 14:34:55 +07:00
Lzu Tao
e3e6e6ea41 add bug 13092 2025-02-06 14:31:39 +07:00
Alejandra González
f09701ab6a Do not trigger [size_of_in_element_count] for u8 (#14011)
Counting in bytes for a pointer to `u8` is legitimate and must not
trigger the lint. Also, this prevents linting the
`{std,core}::ptr::write_bytes` as it manipulates bytes.

Fix #6590

changelog: [`size_of_in_element_count`]: do not lint if the pointee type
is `u8`
2025-02-05 22:17:10 +00:00
lapla-cogito
60f9445900 don't emit lint inside macro in manual_async_fn 2025-02-05 15:06:35 +09:00
J-ZhengLi
2a4be5365a move expr_requires_coercion to clippy_utils & some other adjustments 2025-02-05 10:26:17 +08:00
yanglsh
270e52f6da fix: manual_unwrap_or_default 2025-02-04 19:23:03 -07:00
J-ZhengLi
a2f9861df8 fix [manual_map] not catching type adjustment 2025-02-05 10:18:13 +08:00
lapla-cogito
4220dbd4b3 allow assign_op_pattern in the test of string_add 2025-02-04 12:19:04 +09:00
Alejandra González
c5218d509b new manual_option_as_slice lint (#13901)
Hey folks. It's been a while since I added the `as_slice` method to
`Option`, and I totally forgot about a lint to suggest it. Well, I had
some time around Christmas, so here it is now.

---

changelog: add [`manual_option_as_slice`] lint
2025-02-03 22:00:38 +00:00
llogiq
2c51951dba add manual_slice_fill lint (#14082)
close #13856

changelog: [`manual_slice_fill`]: new lint
2025-02-03 05:03:14 +00:00
lapla-cogito
07ede9c027 ignore manual_slice_fill in other test files 2025-02-03 10:09:40 +09:00
lapla-cogito
e82b1f4653 add manual_slice_fill lint 2025-02-03 10:09:39 +09:00
lapla-cogito
a5329bd8d3 autofix for range_zip_with_len 2025-02-02 23:44:22 +09:00
Alex Macleod
b8d0b16096 autofix for cmp_null (#14122)
changelog: [`cmp_null`]: add autofix
2025-02-01 22:59:06 +00:00
lapla-cogito
3155dabeaa add autofix for cmp_null 2025-02-02 04:22:19 +09:00
Samuel Tardieu
7848488e26 Use a better message for toplevel_ref_arg lint
A `ref` pattern applied to an argument is not ignored. It creates a
reference as expected, but still requires the function to take ownership
of the argument given to it.
2025-02-01 14:23:31 +01:00
lapla-cogito
f9669e4caf add MSRV check for lines_filter_map_ok 2025-02-01 15:20:34 +09:00
lapla-cogito
2a52fbe5da add MSRV check for repeat_vec_with_capacity 2025-02-01 12:42:39 +09:00
Pavel Grigorenko
58d4834097 Resolve projections during internal mutability analysis 2025-02-01 02:30:50 +03:00
dswij
d79f86255d Do not remove semicolon if it changes the block type (#14103)
Removing the semicolon of the last statement of an expressionless block
may change the block type even if the statement's type is `()`. If the
block type is `!` because of a systematic early return, typing it as
`()` may make it incompatible with the expected type for the block (to
which `!` is cast).

Fix #14100

changelog: [`unnecessary_semicolon`]: do not remove semicolon if it
could change the block type from `!` to `()`
2025-01-31 10:47:24 +00:00
Michael Howell
045e36d6a7 doc_link_code: add check for text[adjacent] style links
This is the lint described at
https://github.com/rust-lang/rust/pull/136308#issuecomment-2625485331
that recommends using HTML to nest links inside code.
2025-01-30 16:10:05 -07:00
llogiq
398a5c2db9 New lint: precedence_bits, with recent additions to precedence (#14115)
Commit 2550530266 has extended the
`precedence` lint to include bitmasking and shift operations. The lint
is warn by default, and this generates many hits, especially in embedded
or system code, where it is very idiomatic to use expressions such as `1
<< 3 | 1 << 5` without parentheses.

This commit splits the recent addition into a new lint, which is put
into the "restriction" category, while the original one stays in
"complexity", because mixing bitmasking and arithmetic operations is
less typical.

Fix #14097

changelog: [`precedence_bits`]: new lint
2025-01-30 20:39:07 +00:00
Catherine Flores
f51e18de30 feat: new lint for and_then when returning Option or Result (#14051)
close #6436

changelog: [`return_and_then`]: new lint
2025-01-30 20:14:48 +00:00
Samuel Tardieu
8db9ecfd74 New lint: precedence_bits, with recent additions to precedence
Commit 2550530266 has extended the
`precedence` lint to include bitmasking and shift operations. The lint
is warn by default, and this generates many hits, especially in embedded
or system code, where it is very idiomatic to use expressions such as
`1 << 3 | 1 << 5` without parentheses.

This commit splits the recent addition into a new lint, which is put
into the "restriction" category, while the original one stays in
"complexity", because mixing bitmasking and arithmetic operations is
less typical.
2025-01-30 17:07:50 +01:00
llogiq
ad05bc055c Include generic arguments when suggesting a closure η-reduction (#14105)
Fix #14096

changelog: [`redundant_closure_for_method_calls`]: repeat generic args
in suggestion
2025-01-30 05:15:35 +00:00
Alejandra González
88a00a87fa autofix for redundant_else lint (#13936)
changelog: [`redundant_else`]: autofix for some cases

`redundant_else` can be fixed automatically.
2025-01-30 00:01:31 +00:00
Samuel Tardieu
e4505fb670 Include generic arguments when suggesting a closure η-reduction 2025-01-29 23:59:23 +01:00
Samuel Tardieu
78d6b2ea4e Do not remove semicolon if it changes the block type
Removing the semicolon of the last statement of an expressionless block
may change the block type even if the statement's type is `()`. If the
block type is `!` because of a systematic early return, typing it as
`()` may make it incompatible with the expected type for the block (to
which `!` is cast).
2025-01-29 23:01:08 +01:00
Aaron Ang
84fb6b1651 Add new lint return_and_then 2025-01-29 10:43:59 -08:00
Samuel Tardieu
b8275293ba Don't use labeled block as top-level blocks
Labeled blocks cannot be used as-is in the "then" or "else" part of an
`if` expression. They must be enclosed in an anonymous block.
2025-01-29 18:46:38 +01:00
Catherine Flores
6a209cdc90 Fix escaping problem in write_literal and print_literal lint suggestion (#13990)
fix #13959

The current implementation of the `write_literal` and `print_literal`
lint performs escaping for the second argument of `write!` ,`writeln!`,
`print!` and `println!` of the suggestion by first replacing `"` with
`\"`, and then replacing `\` with `\\`. Performing these replacements in
this order may lead to unnecessary backslashes being added if the
original code contains `"` (e.g. `"` -> `\\"`), potentially resulting in
a suggestion that causes the code to fail to compile.
In the issue mentioned above, it’s suggested to use raw strings as raw
strings, but implementing this would require an ad-hoc change to the
current implementation, so it has been deferred. (I'll implement this in
another PR)

changelog: [`write_literal`]: fix incorrect escaping of suggestions
changelog: [`print_literal`]: fix incorrect escaping of suggestions
2025-01-28 19:29:57 +00:00
llogiq
9ede32fe00 needless_option_take: add autofix (#14042)
changelog: [`needless_option_take`]: add autofix
2025-01-28 18:49:27 +00:00
Philipp Krones
9da9ddb7db Merge commit '51d49c1ae2785b24ef18a46ef233fc1d91844666' into clippy-subtree-update 2025-01-28 19:33:54 +01:00
Philipp Krones
145d5adf04 Merge remote-tracking branch 'upstream/master' into rustup 2025-01-28 19:14:45 +01:00
Yutaro Ohno
4693d0a9ff Add new lint doc_overindented_list_items
Add a new lint `doc_overindented_list_items` to detect and fix list items
in docs that are overindented.

For example,

```rs
/// - first line
///      second line
fn foo() {}
```

this would be fixed to:

```rs
/// - first line
///   second line
fn foo() {}
```

This lint improves readabiliy and consistency in doc.
2025-01-28 16:22:28 +09:00
Catherine Flores
66dc8a1a30 proper applicability for obfuscated_if_else (#14061)
fix #14034

The currect implementation of `obfuscated_if_else` sometimes makes
incorrect suggestions when the original code have side effects (see the
example in the above issue). I think this can be fixed by changing the
applicability depending on whether it can have side effects or not.

changelog: [`obfuscated_if_else`]: change applicability when the
original code can have side effects
2025-01-28 06:57:12 +00:00
Samuel Tardieu
16e2196fc2 useless_asref: no lint if in a closure to change the ref depth
Removing the `.as_ref()` or `.as_mut()` as the top-level expression in a
closure may change the type of the result. In this case, it may be
better not to lint rather than proposing a fix that would not work.
2025-01-28 00:08:39 +01:00
Manish Goregaokar
83bde363b6 correct suggestions in no_std (#13999)
I opened https://github.com/rust-lang/rust-clippy/pull/13896 before.
However, I found that there're more cases where Clippy suggests to use
modules that belong to the `std` crate even in a `no_std` environment.
Therefore, this PR include the changes I've made in #13896 and new
changes to fix cases I found this time to prevent wrong suggestions in
`no_std` environments as well.

changelog: [`redundant_closure`]: correct suggestion in `no_std`
changelog: [`repeat_vec_with_capacity`]: correct suggestion in `no_std`
changelog: [`single_range_in_vec_init`]: don't emit suggestion to use
`Vec` in `no_std`
changelog: [`drain_collect`]: correct suggestion in `no_std`
changelog: [`map_with_unused_argument_over_ranges`]: correct suggestion
in `no_std`

also close #13895
2025-01-27 21:36:12 +00:00