Commit graph

8177 commits

Author SHA1 Message Date
Philipp Krones
ab7e525929
Merge remote-tracking branch 'upstream/master' into rustup 2025-04-03 21:31:02 +02:00
León Orell Valerian Liehr
54994b2d4b
Fix the primary span of redundant_pub_crate when flagging nameless items 2025-04-01 18:20:41 +02:00
Manish Goregaokar
7d3d824d64
Properly handle expansion in single_match (#14495)
Having a macro call as the scrutinee is supported. However, the proposed
suggestion must use the macro call itself, not its expansion.

When the scrutinee is a macro call, do not complain about an irrefutable
match, as the user may not be aware of the result of the macro. A
comparaison will be suggested instead, as if we couldn't see the outcome
of the macro.

Similarly, do not accept macro calls as arm patterns.

changelog: [`single_match`]: proper suggestions in presence of macros

Fixes #14493
2025-03-31 16:42:36 +00:00
Manish Goregaokar
1e78abca67
expand obfuscated_if_else to support {then(), then_some()}.unwrap_or_default() (#14431)
These method chains can be expressed concisely with `if` / `else`.

changelog: [`obfuscated_if_else`]: support `then().unwrap_or_default()`
and `then_some().unwrap_or_default()`
2025-03-31 16:40:32 +00:00
Alex Macleod
f894a81654 Fulfill expectations after first missing-panics-doc 2025-03-31 12:52:06 +00:00
Alex Macleod
6ee4f34741 Abide by allow/expect in bodies for missing_panics_doc 2025-03-31 12:52:06 +00:00
Alex Macleod
c89368537c Fix partially const bodies not linting missing_panics_doc 2025-03-31 12:52:06 +00:00
Jason Newcomb
b46b311ee7
add manual_dangling_ptr lint (#14107)
close #2177

changelog: [`manual_dangling_ptr`]: new lint
2025-03-31 10:14:46 +00:00
Urgau
5f26d0e970 Drop clippy::invalid_null_ptr_usage 2025-03-30 19:33:15 +02:00
y21
c7390279ca add comment and .clone() test case 2025-03-30 14:04:56 +02:00
y21
d5d2189c71 rename lint to char_indices_as_byte_indices 2025-03-30 13:40:03 +02:00
y21
fb32aaf9ac new lint: chars_enumerate_for_byte_indices 2025-03-30 13:39:01 +02:00
Timo
4c610e32ad
fix: unnested_or_patterns suggests wrongly in let (#14401)
Closes #9952

changelog: [`unnested_or_patterns`] fix wrong suggestion in `let`
2025-03-29 13:04:15 +00:00
yanglsh
2df6bba5b0 fix: unnested_or_patterns suggests wrongly in let 2025-03-29 20:52:59 +08:00
Samuel Tardieu
432a8a7a7c Properly handle expansion in single_match
Having a macro call as the scrutinee is supported. However, the proposed
suggestion must use the macro call itself, not its expansion.

When the scrutinee is a macro call, do not complain about an irrefutable
match, as the user may not be aware of the result of the macro. A
comparaison will be suggested instead, as if we couldn't see the outcome
of the macro.

Similarly, do not accept macro calls as arm patterns.
2025-03-28 22:30:09 +01:00
Philipp Krones
c2922d1213
Make collapsible_if recognize the let_chains feature (#14481)
Until `if let` chains are stabilized, we do not collapse them together
or with other `if` expressions unless the `let_chains` feature is
enabled. This is the case for example in Clippy sources.

This was made possible by converting the `collapsible_if` to a late lint
to get access to the set of enabled features. This allows this PR to
supersede #14455 and no longer require an additional configuration
option.

The three commits are, in order:
- a conversion of the existing early lint to a late lint, with no new
feature or tests changes
- the addition of the `let_chains` feature detection and action, and
tests
- the application of the enhanced lint to Clippy sources (136 files
modified)

changelog: [`collapsible_if`]: recognize the rust compiler `let_chains`
feature

r? @flip1995
2025-03-28 09:17:24 +00:00
Samuel Tardieu
01820a9efe Do not make incomplete or invalid suggestions
The `unnecessary_filter_map` and `unnecessary_find_map` lints were
making partial suggestions, proposing to replace the whole expression by
only the method name, or a subexpression which contained explicit
placeholders.

Since even `MaybeIncorrect` suggestions must generate code that
compiles, this changes those lints to recommandation lints with no
code suggestion.
2025-03-27 22:11:09 +01:00
Samuel Tardieu
cd70152470 Make collapsible_if recognize the let_chains feature
Until `if let` chains are stabilized, we do not collapse them together
or with other `if` expressions unless the `let_chains` feature is
enabled. This is the case for example in Clippy sources.
2025-03-27 14:40:44 +01:00
Samuel Tardieu
a895265a4e
Do not warn about shadowing in a destructuring assigment (#14381)
When lowering a destructuring assignment from AST to HIR, the compiler
will reuse the same identifier name (namely `sym::lhs`) for all the
fields. The desugaring must be checked for to avoid a false positive of
the `shadow_unrelated` lint.

Fix #10279
Fix #14377

changelog: [`shadow_unrelated`]: prevent false positive in destructuring
assignments
2025-03-27 11:59:27 +00:00
Samuel Tardieu
d9913dd6ad Do not warn about shadowing in a destructuring assigment
When lowering a destructuring assignment from AST to HIR, the compiler
will reuse the same identifier name (namely `sym::lhs`) for all the
fields. The desugaring must be checked for to avoid a false positive 
of the `shadow_unrelated` lint.
2025-03-27 12:31:54 +01:00
Catherine Flores
3e528672a7
more natural suggestions for cmp_owned (#14247)
Dereferencing string literals in suggestions is redundant.

changelog: [`cmp_owned`]: more natural suggestions are provided for
string literals now

fixes #8103
2025-03-27 00:00:12 +00:00
Samuel Tardieu
9b1945d9fb Prevent including preceeding whitespaces if line contains non blanks
This extra condition prevents a problem when removing the '}' in:
```rust
  ( // There was an opening bracket after the parenthesis, which has been removed
    // This is a comment
   })
```
Removing the whitespaces, including the linefeed, before the '}', would put the
closing parenthesis at the end of the `// This is a comment` line, which would
make it part of the comment as well. In this case, it is best to keep the span
on the '}' alone.
2025-03-26 21:10:09 +01:00
dswij
939d5f93eb
fix: option_if_let_else suggests wrongly when coercion requires explicit cast (#14389)
Closes #11059

changelog: `option_if_let_else`: fix wrong suggestion when coersion
requires explicit cast
2025-03-26 05:08:33 +00:00
dswij
4517b4260f
Fix various typos in lint messages, descriptions and comments (#14459)
changelog: none
2025-03-26 05:05:21 +00:00
Samuel Tardieu
94233fb0ee Unify manual_unwrap_or and manual_unwrap_or_default code
Both lints share a lot of characteristics but were implemented in
unrelated ways. This unifies them, saving around 100 SLOC in the
process, and making one more test trigger the lint. Also, this removes
useless blocks in suggestions.
2025-03-25 18:03:41 +01:00
Alex Macleod
a001ae3be8
Move uninlined_format_args back to style (#14160)
The `uninlined_format_args` was temporarily downgraded to `pedantic` in
part because rust-analyzer was not fully supporting it at the time, per
#10087. The support has been added over [a year
ago](https://github.com/rust-lang/rust-analyzer/issues/11260), so seems
like this should be back to style.

Another source of the initial frustration was fixed since then as well -
this lint does not trigger by default in case only some arguments can be
inlined.

changelog: [`uninlined_format_args`]: move back to `style`
2025-03-25 16:25:04 +00:00
Yuri Astrakhan
1ca79a8797 test fixes 2025-03-25 10:49:14 -04:00
Samuel Tardieu
9d78426b0d
suggest is_some_and instead of map_or in case_sensitive_file_extension_comparions (#14358)
close #14357

changelog: [`case_sensitive_file_extension_comparisons`]: suggest
`is_some_and` to suppress other lint warnings
2025-03-25 14:47:56 +00:00
Yuri Astrakhan
8e50cfacdf make tests consistent 2025-03-25 10:37:04 -04:00
Yuri Astrakhan
d063e09d10 Move uninlined_format_args to style
This lint was downgraded to `pedantic` in part because rust-analyzer was not fully supporting it at the time per #10087. The support has been added over [a year ago](https://github.com/rust-lang/rust-analyzer/issues/11260), so seems like this should be back to style.

Another source of the initial frustration was fixed since then as well - this lint does not trigger by default in case only some arguments can be inlined.
2025-03-25 10:27:20 -04:00
lapla-cogito
e78216c4a1
suggest is_some_and instead of map_or in case_sensitive_file_extension_comparions 2025-03-25 21:26:35 +09:00
Samuel Tardieu
621911a677 Fix various typos in lint messages, descriptions and comments 2025-03-24 16:04:32 +01:00
Aaron Ang
7b1f9d89be Update tests files for manual_dangling_ptr lint 2025-03-23 13:48:01 -07:00
Aaron Ang
de3aa1d9b1 Add new lint manual_dangling_ptr 2025-03-23 13:48:01 -07:00
Philipp Krones
07e7414fb1
fix: nonminimal_bool wrongly showed the macro definition (#14424)
Closes #14404

changelog: [`nonminimal_bool`]: fix macro definition wrongly showed in
suggestions.
2025-03-23 11:19:41 +00:00
Philipp Krones
cad9083d71
Lint more cases in collapsible_if (#14231)
Replace the use of `Sugg::ast()` which prevented combining `if` together
when they contained comments by span manipulation.

A new configuration option `lint_commented_code`, which is `true` by
default, allows opting out from this behavior.

If reviewed on GitHub, the second commit of this PR is best looked at
side by side, with whitespace differences turned off.

changelog: [`collapsible_if`]: lint more cases
2025-03-23 11:17:46 +00:00
yanglsh
8bc164b818 fix: option_if_let_else suggests wrongly when coercion 2025-03-23 12:49:23 +08:00
Alex Macleod
6166f60617
Add ignore_without_reason lint (#13931)
Closes #13066 (tests that are ignored with no reason message).

changelog: Add `ignore_without_reason` lint
2025-03-22 14:56:43 +00:00
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
yanglsh
282b61b641 fix: nonminimal_bool wrongly showed the macro definition 2025-03-22 22:20:22 +08: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
Samuel Tardieu
82381608c9 Lint more cases in collapsible_if
Replace the use of `Sugg::ast()` which prevented combining `if`
together when they contained comments by span manipulation.

A new configuration option `lint_commented_code`, which is `true` by
default, opts out from this behavior.
2025-03-22 15:12:42 +01: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