Commit graph

9903 commits

Author SHA1 Message Date
Samuel Tardieu
604b7b0c5c
Extend cargo dev rename_lint (#14633)
Based on rust-lang/rust-clippy#14616

Extends `rename_lint` to handle more cases and makes `update_lints` sort
`deprecated_lints.rs`.

changelog: None
2025-05-16 15:06:30 +00:00
llogiq
94cfebb397
Rewrite non_copy_const (#13207)
fixes #12979
fixes #12951
fixes #13233

Tests still need to be finished and the docs still need to be updated,
but this should otherwise ready.

changelog: Lint `declare_interior_mutable_const` and
`borrow_interior_mutable_const` more precisely
2025-05-16 15:05:36 +00:00
llogiq
5cb7e4039e
Reenable linting on UFCS deref calls (#14808)
Was disabled in rust-lang/rust-clippy#10855 due to a broken suggestion.
This will only lint if a type is not proveded (e.g. `T::deref`).

changelog: none
2025-05-16 14:47:34 +00:00
Alejandra González
5239b7fa2c
unnecessary_wraps: do not include the whole body in the lint span (#14777)
Using the function declaration, by stripping the body, is enough to
convey the lint message.

changelog: [`unnecessary_wraps`]: do not include the whole body in the
lint span

Closes rust-lang/rust-clippy#14773
2025-05-16 14:24:58 +00:00
Samuel Tardieu
feb70b51c4
match_same_arms, ifs_same_cond: lint once per same arm/condition (#14637)
A large fraction of the lints emitted in CI lintcheck come from [this
`match`](https://github.com/unicode-rs/unicode-normalization/blob/v0.1.23/src/tables.rs#L34289),
currently for `n` same arms `((n - 1) * n)/2` lints are emitted, with
this change it will be emitted as a single lint

Also fixes https://github.com/rust-lang/rust-clippy/issues/13835

changelog: none
2025-05-16 14:16:45 +00:00
Alex Macleod
39ab00a3a1 match_same_arms, ifs_same_cond: lint once per same arm/condition 2025-05-16 12:56:25 +00:00
Jason Newcomb
27acbf2c66 Reenable linting on UFCS deref calls. 2025-05-16 06:45:08 -04:00
Jason Newcomb
b3f490202b clippy_dev: order deprecated_lints.rs in update_lints 2025-05-16 06:43:52 -04:00
Jason Newcomb
318ba60cfb Rewrite tests for declare_interior_mutable_const and
`borrow_interior_mutable_const` to be more thorough on weird constructs
2025-05-16 06:08:41 -04:00
Jason Newcomb
7c41ec7395 Reword declare_interior_mutable_const and
`borrow_interior_mutable_const` messages to be less assertive.
Update documentation for both lints.
2025-05-16 06:08:40 -04:00
Jason Newcomb
57782e0ff1 Rewrite non_copy_const 2025-05-16 06:08:35 -04:00
llogiq
95d7eda0b4
comparison_chain: do not lint on 2 blocks expression (#14811)
Clippy should not lint 2 blocks expression for comparison_chain.

Fixes rust-lang/rust-clippy#4725

changelog: [`comparison_chain`]: do not lint 2 blocks expression
2025-05-16 06:52:35 +00:00
llogiq
ff5e626837
Fix false positive of useless_conversion when using .into_iter().any() (#14800)
Fixes: rust-lang/rust-clippy#14656

changelog: Fix [`useless_conversion`] false positive when using
`.into_iter().any()`.
2025-05-16 06:49:42 +00:00
Samuel Tardieu
a1931dd7cc
unnecessary_wraps: do not include the whole body in the lint span
Using the function declaration, by stripping the body, is enough to
convey the lint message.
2025-05-15 19:37:06 +02:00
Philipp Krones
0bb1b5bd3b
Merge remote-tracking branch 'upstream/master' into rustup 2025-05-15 19:19:08 +02:00
Georges Savoundararadj
34c6ba7354 comparison_chain: do not lint on 2 blocks expression
Clippy should not lint 2 blocks expression for comparison_chain.
2025-05-15 12:57:19 +02:00
relaxcn
f6e95a5b23 Fix false positive of useless_conversion when using into_iter() 2025-05-15 03:05:01 +00:00
SLUCHABLUB
488e4e53d2 Add the allow_exact_repetitions option to the module_name_repetitions lint. 2025-05-14 10:49:01 +02:00
Jason Newcomb
373df5265e
Post non_std_lazy_statics type warnings onto the right node (#14740)
When a `non_std_lazy_statics` warning is generated about an item type
which can be replaced by a standard library one, ensure that the lint
happens on the item HIR node so that it can be expected.

changelog: [`non_std_lazy_statics`]: generate the warning onto the right
node

Fixes rust-lang/rust-clippy#14729

Note that this doesn't change anything on lints generated for the
`lazy_static::lazy_static` macro because the `expect` attribute cannot
be applied to a macro.
2025-05-14 05:49:50 +00:00
llogiq
17f2a87c0c
Add internal lint derive_deserialize_allowing_unknown (#14360)
Adds an internal lint to check for `#[derive(serde::Deserialize)]`
without
[`#[serde(deny_unknown_fields)]`](https://serde.rs/container-attrs.html#deny_unknown_fields).

Today, if you run Clippy with the following clippy.toml, Clippy will
produce a warning, but there will be no accompanying note:
```toml
# In the following configuration, "recommendation" should be "reason" or "replacement".
disallowed-macros = [
    { path = "std::panic", recommendation = "return a `std::result::Result::Error` instead" },
]
```
```sh
$ cargo clippy
    Checking a v0.1.0 (/home/smoelius/tmp/a)
warning: use of a disallowed macro `std::panic`
 --> src/lib.rs:2:5
  |
2 |     panic!();
  |     ^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_macros
  = note: `#[warn(clippy::disallowed_macros)]` on by default
```
The underlying problem is: the enum that derives `serde::Deserialize`
([`DisallowedPathEnum`](81643e297c/clippy_config/src/types.rs (L47)))
does not have the attribute `#[serde(deny_unknown_fields)]`.

This lint identifies such problems by checking trait `impl`s. An
alternative I considered was to walk `clippy_config::conf::Conf`
directly. However, that would not catch the `DisallowedPathEnum` case
because it [is not used in `Conf`
directly](81643e297c/clippy_config/src/types.rs (L31)).

Just to be clear, no one asked for this. So I hope the maintainers do
not mind.

changelog: none
2025-05-13 15:36:57 +00:00
Samuel Moelius
9f4ecea242 Add internal lint derive_deserialize_allowing_unknown 2025-05-13 10:48:41 -04:00
llogiq
7bac114c86
Add new lint: cloned_ref_to_slice_refs (#14284)
Added lint for catching `&[foo.clone()]` where foo is a reference and
suggests `std::slice::from_ref(foo)`.

changelog: new lint: [`cloned_ref_to_slice_refs`]
2025-05-13 05:32:33 +00:00
asdfish
40e1b0ed00 add lint cloned_ref_to_slice_refs
remove merge

removed false positive and improved tests

clarify known problems for `cloned_ref_to_slice_refs`
2025-05-12 21:12:58 -04:00
Philipp Krones
bfc6ad0340
Do not use clippy_utils from UI tests (#14788)
changelog: none

r? @flip1995
2025-05-12 19:32:40 +00:00
llogiq
83248e57e9
Fix messages for type_repetition_in_bounds (#14752)
changelog: [`type_repetition_in_bounds`]: include all generic bounds in
suggestion, clearer message which now includes the repeated type name

Fixes rust-lang/rust-clippy#14744
2025-05-12 16:37:11 +00:00
Samuel Tardieu
c6a23f8fbd
Include all bounds in bounds consolidation
Also, include the type name in the lint message, and simplify the span
computation.
2025-05-12 18:32:17 +02:00
Samuel Tardieu
01e08a4c5b
Do not use clippy_utils from UI tests 2025-05-12 18:28:59 +02:00
llogiq
459364b971
return_and_then: only lint returning expressions (#14783)
If an expression is not going to return from the current function of
closure, it should not get linted.

This also allows `return` expression to be linted, in addition to the
final expression. Those require blockification and proper indentation.

changelog: [`return_and_then`]: only lint returning expressions

Fixes rust-lang/rust-clippy#14781
2025-05-12 16:01:55 +00:00
llogiq
b363499457
Add new confusing_method_to_numeric_cast lint (#13979)
Fixes https://github.com/rust-lang/rust-clippy/issues/13973.

I don't think we can make `fn_to_numeric_cast_any` to be emitted in some
special cases. Its category cannot be changed at runtime.

I think in this case, the best might be a specialized new lint so we can
target exactly what we want.

----

changelog: Add new `confusing_method_to_numeric_cast` lint
2025-05-12 15:27:33 +00:00
Samuel Tardieu
8f5dc85f37
Use tempfile::TempDir::keep() instead of deprecated into_path()
`tempfile` has deprecated `TempDir::into_path()` (replacing it by
`TempDir::keep()`) between version `3.3` which Clippy required and version
`3.20.0` which is the latest semver-compatible version. Since Clippy
doesn't use a `Cargo.lock` file, the latest version of `tempfile` is
used which leads to CI failure.
2025-05-12 09:01:42 +02:00
Samuel Tardieu
c040e9f6fc
return_and_then: only lint returning expressions
If an expression is not going to return from the current function of
closure, it should not get linted.

This also allows `return` expression to be linted, in addition to the
final expression. Those require blockification and proper indentation.
2025-05-11 18:43:01 +02:00
Samuel Tardieu
9ed53b85b7
Fix ICE in missing_const_for_fn
The `mir_drops_elaborated_and_const_checked` query result has been
stolen already and cannot be borrowed again. Use the `optimized_mir`
query result instead.
2025-05-10 22:10:28 +02:00
dswij
f60807dfee
Resolve through local re-exports in lookup_path (#14772)
Fixes https://github.com/rust-lang/rust-clippy/issues/14767

A long standing issue revealed by
https://github.com/rust-lang/rust-clippy/pull/14397

changelog: none
2025-05-10 16:55:19 +00:00
Samuel Tardieu
5262ab2416
Fix unnecessary_unwrap emitted twice in closure (#14763) (#14770)
The problem is that `check_fn` is triggered by both function and
closure, and `visit_expr` can visit expressions in another closures
within a function or closure.

So just skip walking in a inner closure.

changelog: Fix [`unnecessary_unwrap`] emitted twice in closure which
inside in a function or another closure.

Fixes: rust-lang/rust-clippy#14763
2025-05-10 14:15:50 +00:00
relaxcn
e61886a6d9 fix unnecessary_unwrap emitted twice in closure 2025-05-10 07:12:40 +08:00
Samuel Tardieu
bde939058b
char::is_digit() is const-stable only since Rust 1.87
The `to_digit_is_some()` lint suggests using `char::is_digit()`. It
should not trigger in const contexts before Rust 1.87.
2025-05-10 00:20:55 +02:00
Alex Macleod
e4d82aefd9 Resolve through local re-exports in lookup_path 2025-05-09 22:13:35 +00:00
Alejandra González
16fd2a83d7
Fix integer_division false negative for NonZero denominators (#14664)
Close rust-lang/rust-clippy#14652

changelog: [`integer_division`]: fix false negative for NonZero
denominators
2025-05-09 20:50:04 +00:00
Samuel Tardieu
756de2ab82
remove superseded lints (#14703)
changelog: [`transmute_float_to_int, transmute_int_to_char,
transmute_int_to_float`, `transmute_num_to_bytes`]: remove lints, now in
rustc

these lints are now mostly in rustc, so they dont need to be in clippy
anymore

https://github.com/rust-lang/rust/pull/136083#discussion_r2009897120

pending https://github.com/rust-lang/rust/pull/140431:
transmute_int_to_bool

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

- ["Rust version of new lints should be checked" by
@samueltardieu](https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576)

Generated by triagebot, see
[help](https://forge.rust-lang.org/triagebot/note.html) for how to add
more
<!--
TRIAGEBOT_SUMMARY_DATA_START$${"entries_by_url":{"https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576":{"title":"Rust
version of new lints should be
checked","comment_url":"https://github.com/rust-lang/rust-clippy/pull/14703#issuecomment-2861982576","author":"samueltardieu"}}}$$TRIAGEBOT_SUMMARY_DATA_END
-->

<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
2025-05-09 16:12:59 +00:00
bendn
35bdd25e32
remove superseded lints 2025-05-09 19:25:55 +07:00
relaxcn
b73d3b4384 fix issue-14725 2025-05-09 01:21:14 +08:00
Alexey Semenyuk
1fbfbb59e9 Fix integer_division false negative for NonZero denominators 2025-05-08 16:12:47 +05:00
Guillaume Gomez
06fa0452eb Rename lint into confusing_method_to_numeric_cast 2025-05-07 21:38:38 +02:00
dswij
f88f9a9dc5
Fix manual_let_else FN when diverges on simple enum variant (#14732)
Closes rust-lang/rust-clippy#14598

Implemented checks for simple enum variants when checking if match arms
are disjointed.

changelog: [`manual_let_else`] fix FN when diverges on simple enum
variant
2025-05-07 16:33:07 +00:00
Samuel Tardieu
50cff118d8
Make let_with_type_underscore help message into a suggestion (#14749)
changelog: none
2025-05-07 16:26:54 +00:00
Guillaume Gomez
c680419425 Add UI test for primitive_method_to_numeric_cast 2025-05-07 18:18:06 +02:00
Jason Newcomb
34cd9486c9
Fix diagnostic paths printed by dogfood test (#14746)
Where you would previously see

```
error: some lint
   --> src/lib.rs:1:2
```

it will now print

```
error: some lint
   --> clippy_lints/src/lib.rs:1:2
```

Ensuring you can click the link in the terminal

A workaround for us not being in a workspace

changelog: none
2025-05-07 15:24:46 +00:00
Alex Macleod
8c045221b5 Make let_with_type_underscore help message into a suggestion 2025-05-07 15:19:40 +00:00
Alex Macleod
772ea35935 Fix diagnostic paths printed by dogfood test 2025-05-07 14:32:23 +00:00
Manish Goregaokar
ca6281628e
Replace Symbol::as_str usage in match expressions (#14745)
We could do with a way to make matching on the `assert_*` macro kind
easier, this came up a bunch here. I'll take a look at that as a follow
up

changelog: none
2025-05-07 14:09:53 +00:00