Commit graph

12848 commits

Author SHA1 Message Date
y21
32cf88450b add a note for str::bytes 2025-03-30 13:39:01 +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
Bastian Kersting
3e960c12d8 Make missing_const_for_fn operate on non-optimized MIR
This has two reasons: First of all we don't need the optimized MIR for
evaluating the checks of this lint, as const-eval anyways operates on
`mir_for_ctf` which is derived from `mir_drops_elaborated_and_const_checked`.
Second of all we might transform MIR in the optimization passes in a way
that doesn't work with const-eval, but it is irrelevant since const-eval
uses another MIR.

Specifically this came up when adding a new check in debug builds
(https://github.com/rust-lang/rust/pull/134424), which is added as part
of an optimization pass.
2025-03-28 10:46:41 +00: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
79c69112dc Apply collapsible_if to Clippy itself
Since Clippy uses the `let_chains` feature, there are many occasions to
collapse `if` and `if let` statements.
2025-03-27 14:40:44 +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
9df5177287 Convert the collapsible_if early lint to a late one 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
dswij
764c1b6d16
remove obsolete "Known Problems" in ok_expect (#14458)
It looks like `ok_expect` already
[checks](b27a2bbe26/clippy_lints/src/methods/ok_expect.rs (L16))
for the presence of the `Debug`.

changelog: none
2025-03-27 06:08:16 +00: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
todaymoon
a8bfafe929 chore: fix some comments
Signed-off-by: todaymoon <csgcgl@foxmail.com>
2025-03-26 17:40:11 +08: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
Philipp Krones
d09e658677
Apply collapsible if to Clippy sources (#14451)
This PR enables the new ability to collapse `if` statements containing
comments (without losing them) in Clippy sources, excluding tests and
lintcheck, where the default behaviour (no collapsing in presence of
comments) is preserved.

To be applied after #14231. When it is applied, #14455 will be marked as
ready for review, then #14228 afterwards.

changelog: none

r? ghost
2025-03-25 19:26:36 +00:00
Samuel Tardieu
6509de3bfb Fix situations identified by collapsible_if new hits 2025-03-25 19:50:24 +01: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
Alejandra González
d95bdcfb50
Rename Sugg::maybe_par() into Sugg::maybe_paren() (#14457)
"paren" is used throughout the Clippy codebase as an abbreviation for
"parentheses".

changelog: none
2025-03-25 16:13:29 +00: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
1d890389ff 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:19 -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
Alejandra González
f5d81a314a
Fix type error in lint description (#14466)
Fix #14465

changelog: none
2025-03-25 12:25:57 +00:00
Timo
d88818d1e7
Rename inconsistent_struct_constructor configuration; don't suggest deprecated configurations (#14280)
This PR does two things:
- It renames `inconsistent_struct_constructor`'s configuration from
`lint-inconsistent-struct-field-initializers` to
`check-inconsistent-struct-field-initializers`. (I should have suggested
`check-...` in
[#13737](https://github.com/rust-lang/rust-clippy/pull/13737#discussion_r1875118516).)
- It causes Clippy to no longer suggest deprecated configurations.
(Previously, Clippy would suggest `cyclomatic-complexity-threshold`, for
example.)

r? @y21

changelog: Rename `lint-inconsistent-struct-field-initializers` to
`check-inconsistent-struct-field-initializers`
changelog: No longer suggest deprecated configurations
2025-03-25 11:56:47 +00:00
Samuel Tardieu
de8c404ed4 Fix type error in lint description 2025-03-25 09:44:48 +01:00
Samuel Tardieu
0ff7fad3da
Use code for references to other lints in as_conversions docs (#14283)
changelog: none
2025-03-25 08:37:36 +00:00
Timo
9c6cb5150f
wildcard_imports: lint on pub use if asked to (#14182)
`warn_on_all_wildcard_imports` should warn on all wildcard imports,
including the reexported ones.

Fix #13660

changelog: [`warn_on_all_wildcard_imports`]: when asked to warn on all
wildcard imports, include the reexported ones
2025-03-25 00:08:45 +00:00
Samuel Tardieu
621911a677 Fix various typos in lint messages, descriptions and comments 2025-03-24 16:04:32 +01:00
Samuel Tardieu
809c931804 wildcard_imports: lint on pub use if asked to
`warn_on_all_wildcard_imports` should warn on all wildcard imports,
including the reexported ones.
2025-03-24 15:49:29 +01:00
lapla-cogito
e8c06a71cf
remove obsolete "Known Problems" in ok_expect 2025-03-24 22:27:44 +09:00
Samuel Tardieu
962329fd9d Rename Sugg::maybe_par() into Sugg::maybe_paren()
"paren" is used throughout the Clippy codebase as an abbreviation for
"parentheses".
2025-03-24 08:44:54 +01:00
Samuel Moelius
88b590bf46 lint-inconsistent-... -> check-inconsistent-... 2025-03-23 15:22:37 -04:00
Alex Macleod
b27a2bbe26
Clarify example for unconditional_recursion (#14385)
Clarify example for unconditional_recursion

changelog: none
2025-03-23 13:49:21 +00: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
alexey semenyuk
63e7815390 Fix example for unconditional_recursion 2025-03-23 13:28:36 +05: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
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
Samuel Moelius
5b234c965d Change category to pedantic 2025-03-21 11:10:49 -04: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