Commit graph

9714 commits

Author SHA1 Message Date
Philipp Krones
ab7e525929
Merge remote-tracking branch 'upstream/master' into rustup 2025-04-03 21:31:02 +02:00
Guillaume Gomez
893a6a381e Update to new rinja version (askama) 2025-04-03 15:48:20 +02:00
Samuel Moelius
dc7d9ec35c Validate paths in disallowed_* configurations 2025-04-01 14:53:48 -04:00
Alejandra González
e429bdebbd
Manually fulfill lint expectations for all unsafe blocks with metavars (#14501)
Fixes #14488

Context: the `macro_metavars_in_unsafe` lint looks for unsafe blocks
with a macro span that then contain expressions with a root context span
(which means that it is a macro with an unsafe block expanding a
metavariable inside). In order to avoid emitting a warning for every
single macro invocation, it will deduplicate the unsafe blocks by the
span in the macro.

This leads to the linked issue where because of the deduplicating and
removing unsafe blocks that all belong to the same unsafe block in the
macro, only one of the unsafe blocks will actually have its lint
expectation fulfilled. This PR fixes that by manually fulfilling all of
the unsafe blocks from all expansions before deduplicating them.

changelog: [`macro_metavars_in_unsafe`]: fix unfulfilled `#[expect]` if
macro is invoked multiple times
2025-04-01 18:05:23 +00: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
Philipp Krones
9e6c7af4ba
Suggest ./x test src/tools/clippy --bless when in rust-lang/rust (#14507)
changelog: none
2025-03-31 17:30:19 +00: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
Alex Macleod
9172556de8 Suggest ./x test src/tools/clippy --bless when in rust-lang/rust 2025-03-31 12:39:41 +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
y21
ffaecd008d manually fulfill lint expectations for all unsafe blocks with metavars 2025-03-29 17:55:30 +01: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
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
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
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
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
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
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
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
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
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