Commit graph

9655 commits

Author SHA1 Message Date
Jason Newcomb
a65cc366f2
Add regression tests for suspicious_doc_comments (#14268)
Related to #14265 which was fixed automatically by the latest rustup.

changelog: none

*Edit: description, changelog, keep only tests*
2025-03-22 14:38:26 +00:00
Jason Newcomb
b41f2e4653
Emit collapsible_match at the right node (#14311)
Fixes https://github.com/rust-lang/rust-clippy/issues/14281

changelog: none
2025-03-22 14:35:24 +00:00
Jason Newcomb
d9934328dd
set the applicability of op_ref to MachineApplicable (#14438)
#2597 appears to be already resolved, so the applicability of `op_ref`
can be set to `MachineApplicable`.

close #2597

changelog: [`op_ref`]: set the applicability to `MachineApplicable`
2025-03-22 14:16:52 +00:00
Philipp Krones
cdf2e7c73c
fix: borrow_deref_ref suggests wrongly when coerce to mut (#14403)
Closes #11346.
Partially fix #9905. The first case in this issue is a little tricky as
the coerce does not happen in the borrowing.

changelog: [`borrow_deref_ref`]: fix wrong suggestions when coerce to
mut
2025-03-22 13:19:42 +00:00
Philipp Krones
37e1b80447
fix: manual_find suggests wrongly when early return (#14405)
Closes #9521

changelog: [`manual_find`]: fix wrong suggestions when early return
2025-03-22 13:16:11 +00:00
dswij
0a141ab7b8
fix: redundant_clone FP on enum cast (#14395)
Closes #10074

changelog: [`redundant_clone`]: fix FP on enum cast
2025-03-21 14:23:52 +00:00
dswij
c418714518
expand neg_multiply to lint float numbers as well (#14447)
changelog: [`neg_multiply`]: lint float numbers as well
2025-03-21 14:22:17 +00:00
lapla-cogito
da4f5a58a9
expand neg_multiply to lint float numbers as well 2025-03-21 21:20:39 +09:00
Alejandra González
7a92626ec2
fix: filter_map_bool_then suggest wrongly when the closure cannot be decompose directly (#14370)
Closes #11617
Closes #14368

Clippy gives wrong suggestions when the filter and then cannot be put
into closure directly. Since trying to transform these can be too
complicated, Clippy will simply warn but don't try to fix.

changelog: [`filter_map_bool_then`]: fix wrong suggestions when the
closure cannot be decompose directly
2025-03-21 12:09:12 +00:00
yanglsh
3f9ecbe341 fix: filter_map_bool_then: suggests wrongly when mut capture in then 2025-03-21 12:55:18 +08:00
yanglsh
721ac284de fix: filter_map_bool_then suggest wrongly when contain return 2025-03-21 12:55:18 +08:00
Timo
1e5237f4a5
fix: missing_const_for_fn FP on unstable const traits (#14294)
Closes #14020
Closes #14290
Closes #14091

Add checks for unstable const traits.

changelog: [`missing_const_for_fn`] fix FP on unstable const traits
2025-03-20 20:00:15 +00:00
Philipp Krones
dc4c77608e
Merge remote-tracking branch 'upstream/master' into rustup 2025-03-20 20:46:36 +01:00
Timo
f2feb0f1a9
make never_loop applicability more flexible (#14203)
The applicability of `never_loop` is currently set to `Unspecified`, but
if the loop block does not contain `break` or `continue`, it can be
`MachineApplicable`.

changelog: [`never_loop`]: the applicability is now `MachineApplicable`
when the loop block contains neither `break` nor `continue`
2025-03-20 15:18:29 +00:00
Timo
221ae5f176
fix suggestion for assignments have enclosing parentheses under needless_late_init (#14169)
fixes #9895

changelog: [`needless_late_init`]: correct suggestion when assignments
have enclosing parentheses
2025-03-19 22:51:38 +00:00
Manish Goregaokar
48ce25ea0e
Add MSRV check for question_mark (#14436)
changelog: [`question_mark`]: Now respects the [`msrv`] configuration
2025-03-19 15:56:45 +00:00
Alejandra González
31497d68fb
fix: option_if_let_else FP when value partially moved (#14209)
fixes #13964

The lint `option_map_unwrap_or` used to have a similar issue in #10579,
so I borrowed its solution to fix this one.

changelog: [`option_if_let_else`]: fix FP when value partially moved
2025-03-19 15:34:53 +00:00
lapla-cogito
a463154bf0
set the applicability of op_ref to MachineApplicable 2025-03-19 21:37:42 +09:00
Jan Verbeek
d793c0abfa Add MSRV check for question_mark 2025-03-19 09:33:58 +01:00
Alex Macleod
d443f38f73
Reinstate single_match/single_match_else lints with comments (#14420)
Commit efe3fe9b8c removed the ability for
`single_match` and `single_match_else` to trigger if comments were
present outside of the arms, as those comments would be lost while
rewriting the `match` expression.

This reinstates the lint, but prevents the suggestion from being applied
automatically in the presence of comments by using the `MaybeIncorrect`
applicability. Also, a note is added to the lint message to warn the
user about the need to preserve the comments if acting upon the
suggestion.

changelog: [`single_match`, `single_match_else`]: reinstate lint when
comments are inside the `match` but do not autofix the code

Fix #14418
2025-03-18 12:45:19 +00:00
Philipp Krones
a07e887e24
Improve string_to_string lint in case it is in a map call (#14396)
Fixes https://github.com/rust-lang/rust-clippy/issues/14175.

There are two "big" cases to handle: `.map(|x| x.to_string())` and
`.map(String::to_string)`. If the closure has more than one expression,
we should not suggest `.cloned()`.

changelog: Improve `string_to_string` lint in case it is in a map call

r? @samueltardieu
2025-03-18 10:29:10 +00:00
Guillaume Gomez
269b913bfd Better handle blocks with just one expression 2025-03-18 11:09:20 +01:00
Samuel Tardieu
a1bdc191ba Reinstate single_match/single_match_else lints with comments
Commit efe3fe9b8c removed the ability for
`single_match` and `single_match_else` to trigger if comments were
present outside of the arms, as those comments would be lost while
rewriting the `match` expression.

This reinstates the lint, but prevents the suggestion from being applied
automatically in the presence of comments by using the `MaybeIncorrect`
applicability. Also, a note is added to the lint message to warn the
user about the need to preserve the comments if acting upon the
suggestion.
2025-03-17 16:14:14 +01:00
yanglsh
a3865b1a3d fix: option_if_let_else FP when value partially moved 2025-03-17 14:36:29 +08:00
Alejandra González
4800557857
question_mark: avoid incorrect suggestion when ref binding used (#14158)
changelog: [`question_mark`]: avoid incorrect suggestion when `ref`
binding used

Fixes #13417
2025-03-16 23:25:26 +00:00
Alex Macleod
775a5c2712
fix incorrect suggestions related to parentheses in needless_return (#14094)
close #12157

`needless_return` sometimes makes incorrect suggestions by omitting
necessary enclosing parentheses. This PR resolves the issue by using
`clippy_utils::sugg::Sugg`.

changelog: [`needless_return`]: now makes correct suggestions which
require enclosing parentheses
2025-03-16 15:03:14 +00:00
Fridtjof Stoldt
3c7dfacf44
new lint: doc_comment_double_space_linebreaks (#12876)
Fixes https://github.com/rust-lang/rust-clippy/issues/12163

I decided to initially make this a restriction lint because it felt a
bit niche and opinionated to be a warn-by-default style lint. It may be
appropriate as a style lint if the standard or convention *is* to use
`\` as doc comment linebreaks - not sure if they are!

The wording on the help message could be improved, as well as the name
of the lint itself since it's a bit wordy - suggestions welcome.

This lint works on both `///` and `//!` doc comments.

changelog: new lint: `doc_comment_double_space_linebreaks`
2025-03-16 14:44:02 +00:00
Michael Howell
4e9caa3985 question_mark: suggest as_ref/as_mut if ref binding is used 2025-03-15 15:59:24 -07:00
KonaeAkira
da910b14e2 Add failing from_over_into test case 2025-03-15 00:00:01 +01:00
Esteban Küber
915e44216a Do not suggest using -Zmacro-backtrace for builtin macros
For macros that are implemented on the compiler, we do *not* mention the `-Zmacro-backtrace` flag. This includes `derive`s and standard macros.
2025-03-14 19:50:03 +00:00
yanglsh
95d72812f8 fix: manual_find suggests wrongly when early return 2025-03-14 16:06:58 +08:00
yanglsh
80ce9d1eff fix: borrow_deref_ref suggests wrongly when coerce to mut 2025-03-14 13:51:08 +08:00
Guillaume Gomez
0e4b6c8124 Make string_to_string emit a suggestion when cloned can be used 2025-03-13 11:46:02 +01:00
Catherine Flores
18061e2c42
incompatible_msrv: lint function calls with any argument count (#14216)
The lint for function calls was previously restricted to functions
taking exactly one argument. This was not documented.

Generalizing the lint to an arbitrary number of arguments in the
function call requires special casing some macro expansions from the
standard library. Macros such as `panic!()` or `assert_eq!()` exist
since Rust 1.0.0, but modern stdlib expand those macros into calls to
functions introduced in later Rust versions. While it is desirable to
lint code inside macros, using MSRV-incompatible functions coming from
`core` in macro expansions has been special-cased to not trigger this
lint.

Also, code coming from compiler desugaring may contain function calls
(for example, `a..=b` is now desugared into `RangeInclusive::new(a, b)`.
Those should not be linted either as the compiler is allowed to use
unstable function calls.

Fix #14212

changelog: [`incompatible_msrv`]: lint function calls with any argument
count
2025-03-13 04:11:42 +00:00
Guillaume Gomez
0ffc6cf097 Add ui test for string_to_string in map calls 2025-03-12 19:59:27 +01:00
Philipp Krones
72540726b1
needless_pass_by_value: reference the innermost Option content (#14392)
If types such as `Option<Option<String>>` are not used by value, then
`Option<Option<&String>>` will be suggested, instead of
`Option<&Option<String>>`.

changelog: [`needless_pass_by_value`]: suggest using a reference on the
innermost `Option` content

fix #14375
2025-03-12 16:07:47 +00:00
yanglsh
1066ee09ed fix: redundant_clone FP on enum cast 2025-03-12 21:55:31 +08:00
Samuel Tardieu
417d4e6210 needless_pass_by_value: make verbose suggestion
This reduces the number of snippet manipulations, and shows the new
reference in context.
2025-03-12 13:50:04 +01:00
Philipp Krones
0730678e26
Make annotations mandatory for internal ui tests (#14393)
Last part of https://github.com/rust-lang/rust-clippy/pull/11421.

Now all ui tests require annotations.

The change in `ui_test` is to add `ICE:` errors.

changelog: Make internals ui tests annotations mandatory

r? @flip1995
2025-03-12 11:01:24 +00:00
Guillaume Gomez
092a20ec11 Update lint_message_convention test to allow clippy "help" message 2025-03-12 11:41:26 +01:00
Guillaume Gomez
ec8c0b3755 Make annotations mandatory for internal ui tests 2025-03-12 11:32:40 +01:00
Guillaume Gomez
cfc743226e Update ui_test version to 0.29.2 2025-03-12 11:29:54 +01:00
Samuel Tardieu
35e6057e71 needless_pass_by_value: reference the innermost Option content
If types such as `Option<Option<String>>` are not used by value, then
`Option<Option<&String>>` will be suggested, instead of
`Option<&Option<String>>`.
2025-03-12 06:57:25 +01:00
Alex Macleod
714c64c7a1
fix: unnecessary_safety_comment FP on desugared assign (#14371)
Closes #13039

changelog: [`unnecessary_safety_comment`]: fix FP on desugared assign
2025-03-12 02:27:43 +00:00
Philipp Krones
8f280ff813
Add missing tests annotations for ui-internal (#14388)
Follow-up of https://github.com/rust-lang/rust-clippy/pull/11421.

I can't yet make the annotations mandatory because there is an issue
with `tests/ui-internal/custom_ice_message.rs`: the error message is not
emitted as JSON, meaning that we can't match it with `ui_test`. I need
to check if it's a bug in rustc or if `ui_test` needs to handle this
case somehow.

changelog: Add missing tests annotations for `ui-internal`

r? @flip1995
2025-03-11 16:10:14 +00:00
Guillaume Gomez
cb9682b628 Add missing tests annotations for ui-internal 2025-03-11 16:35:11 +01:00
Oli Scherer
cb044d4d7b Implement #[define_opaque] attribute for functions. 2025-03-11 12:05:02 +00:00
Philipp Krones
a25cbd50ca
Improve needless_pass_by_value suggestion (#13880)
Fixes https://github.com/rust-lang/rust-clippy/issues/13744.

A simple check to check if the type is an `Option` allows to improve the
suggestion.

changelog: Improve `needless_pass_by_value` suggestion
2025-03-10 15:48:43 +00:00
lapla-cogito
90dbc5bf94
make never_loop applicability more flexible 2025-03-10 15:00:57 +09:00
yanglsh
97275d523c fix: unnecessary_safety_comment FP on desugared assign 2025-03-10 12:36:37 +08:00