Commit graph

22178 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
dswij
bc28421a7a
Take advantage of match ergonomics in clippy_utils::hir_utils (#14499)
This is a style-only change in order to use match ergonomics by removing
unneeded `&` and `ref`.

changelog: none
2025-03-29 12:20:23 +00:00
Samuel Tardieu
bc701925d8 Take advantage of match ergonomics in clippy_utils::hir_utils
This is a style-only change in order to use match ergonomics by removing
unneeded `&` and `ref`.
2025-03-29 12:04:23 +01:00
Alejandra González
d78622eeb8
Make missing_const_for_fn operate on non-optimized MIR (#14003)
The main reason for this is that 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 (`mir_for_ctfe`).

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.

changelog: none
2025-03-28 11:01:32 +00: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
Manish Goregaokar
61b38e76b2
Do not make incomplete or invalid suggestions (#14487)
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.

Fixes #14486

changelog: [`unnecessary_find_map`, `unnecessary_filter_map`]: do not
make suggestions that will not compile
2025-03-27 21:15:55 +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
Manish Goregaokar
c4789a014f
Prevent including preceeding whitespaces if line contains non blanks (#14480)
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.

changelog: none

Note to reviewer: `manual_inspect` and `collapsible_if` were two lints
exhibiting this problem in cooked up test cases, which have been
included as non-regression tests.
2025-03-26 22:03:17 +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
Samuel Tardieu
fe4dd5b92e
chore: fix some comments (#14475)
*Please write a short comment explaining your change (or "none" for
internal only changes)*

remove redundant words in comment

changelog: none
2025-03-26 11:35:57 +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
Manish Goregaokar
1893e1e5e7
Unify manual_unwrap_or and manual_unwrap_or_default code (#14332)
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.

Close #12956

changelog: none
2025-03-25 17:34:00 +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
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
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
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
ca48e461a9
Add myself to reviewer rotation (#14468)
changelog: none
2025-03-25 10:24:29 +00:00
Samuel Tardieu
b7cbb4ec8c Add myself to reviewer rotation 2025-03-25 11:19:16 +01: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 Moelius
315e9aa79f Don't check deprecated configs in configs_are_tested test 2025-03-24 09:06:13 -04: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
969b5ad65c Don't suggests deprecated congurations 2025-03-23 15:25:27 -04:00
Samuel Moelius
88b590bf46 lint-inconsistent-... -> check-inconsistent-... 2025-03-23 15:22:37 -04:00