Commit Graph

22561 Commits

Author SHA1 Message Date
Samuel Tardieu fe4b4e8329 mem::size_of_val is const-stable since Rust 1.85 2025-05-14 23:38:37 +02:00
Samuel Tardieu 4ec219393a Fix size computation when element is a slice
In this case, a dereference is needed before using `mem::size_of_val()`.
2025-05-14 23:38:37 +02:00
dswij 40bead02a5 clippy_dev refactor (#14616)
Based on rust-lang/rust-clippy#13223

Various refactoring on `clippy_dev` before upgrading rename and
splitting `clippy_lints` into multiple crates.

Some improvements:
* The working directory is set to the root clippy directory. Running
from a subdirectory was kind of supported before sometimes. Now it just
works.
* File won't be written unless they're actually updated. Most of the
time they weren't written, but a few cases slipped through.
* Buffers are reused more for the negligible speed boost.

changelog: None
2025-05-14 16:44:08 +00:00
llogiq 1a864f34a3 Add the allow_exact_repetitions option to the module_name_repetititions lint (#14261)
changelog: [`module_name_repetitions`]: new configuration option
`allow_exact_repetitions`, enabled by default

Closes #14226
2025-05-14 10:17:45 +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`](https://github.com/rust-lang/rust-clippy/blob/81643e297cf44ce3c7648b8443fc4d6592fa81eb/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](https://github.com/rust-lang/rust-clippy/blob/81643e297cf44ce3c7648b8443fc4d6592fa81eb/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
Jason Newcomb 0636121964 clippy_dev: Remove print option from update_lints 2025-05-12 17:07:53 -04:00
Jason Newcomb a9beb8b68d clippy_dev: Refactor token parsing to avoid macros. 2025-05-12 17:07:53 -04:00
Jason Newcomb 97abf33fa0 clippy_dev: Split gathering lint decls from parsing deprecated lints. 2025-05-12 17:07:53 -04:00
Jason Newcomb 2c85cb0371 clippy_dev: Only build AhoCorasick searcher once for multiple files. 2025-05-12 17:07:52 -04:00
Jason Newcomb 98cb92f323 clippy_dev: Reuse buffers when updating files and don't write unchanged files in clippy_dev 2025-05-12 17:07:52 -04:00
Jason Newcomb 3fe5fb2967 clippy_dev: Split rename and deprecate out of update_lints 2025-05-12 17:07:52 -04:00
Jason Newcomb 2f39264d00 clippy_dev: Set the current directory to clippy's root path. 2025-05-12 17:07:52 -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
Philipp Krones 54aa120f18 Update "Changelog update walkthrough" section (#14785)
Update "Changelog update walkthrough" section based on
rust-lang/rust-clippy#14748 discussion

changelog: none
2025-05-12 19:29:36 +00:00
Alexey Semenyuk 2215282fa4 Update Changelog update walkthrough docs section 2025-05-12 22:15:53 +05: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 62ba9969a4 Fix clippy::version of elidable_lifetime_names to 1.87 (#14654)
relates to rust-lang/rust-clippy#14653

changelog: [`elidable_lifetime_names`]: Fix clippy version that this
lint was introduced in.

It might be good to have some automation to check that the version is
correct.
IIUC the version should be the current nightly version at the time a PR
is merged.
If a release happens while a PR is open, the version needs to be bumped
- this is easy to forget.
2025-05-12 15:53:05 +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
Philipp Krones 2ce5451850 Changelog for Clippy 1.87 🦡 (#14748)
Violets are red,
Roses are blue,
It’s wrong on purpose —
We don’t break tradition.

<hr>

This is cat-penguin of this release [nominated
by](https://github.com/rust-lang/rust-clippy/pull/12224#issuecomment-1927555104)
@xFrednet some time ago:

![image](https://github.com/user-attachments/assets/49bd7783-9d56-4a15-b026-1c7e799ea7ba)

Cats for the next release can be traditionally nominated in the comments
:D
Please be more active and cat-minded 😻

<hr>

changelog: none

r? flip1995
2025-05-12 10:00:01 +00:00
Alexey Semenyuk 55b5c835c5 Changelog for Clippy 1.87 2025-05-12 14:50:27 +05:00
Philipp Krones 74fd9edc49 book: modify FnKind::Fn matching (#14780)
This PR update the sample code in the development guide because `ident`
was moved to the struct `Fn` in
https://github.com/rust-lang/rust/pull/138740 .

changelog: none
2025-05-12 08:42:41 +00:00
Philipp Krones 48337da4a1 Use tempfile::TempDir::keep() instead of deprecated into_path() (#14784)
`tempfile` has deprecated `TempDir::into_path()` (replacing it by
`TempDir::keep()` between version `3.3` which Clippy required and
version `3.20` 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.

changelog: none

r? @flip1995
2025-05-12 08:27:14 +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
Kazuki Obata 18eb293435 update dev doc: update FnKind::Fn matching
Ident was moved to the struct Fn in https://github.com/rust-lang/rust/pull/138740
2025-05-11 16:05:31 +09:00
Alejandra González 7f6d507bba Fix ICE in missing_const_for_fn (#14776)
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.

changelog: [`missing_const_for_fn`]: fix ICE with some compilation
options

Fixes rust-lang/rust-clippy#14774

r? @Jarcho
2025-05-10 21:15:31 +00: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
Alejandra González 3c5e403824 char::is_digit() is const-stable only since Rust 1.87 (#14771)
The `to_digit_is_some()` lint suggests using `char::is_digit()`. It
should not trigger in const contexts before Rust 1.87.

changelog: [`to_digit_is_some`]: Do not lint in const contexts when MSRV
is below 1.87
2025-05-09 23:06:29 +00: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
dswij a67ee902df unwrap.rs cleanup (#14761)
This cleans up `unwrap.rs`:

- use interned symbols instead of strings
- update names to reflect the current implementation
- replaced a cascaded `if` by a shorter `match`

changelog: none
2025-05-09 16:55:12 +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
Philipp Krones 656b31768d Allow any rust-lang team member to close an issue with rustbot (#14765)
changelog: none

It is useful, and happened in
https://github.com/rust-lang/rust-clippy/issues/12806#issuecomment-2863646739
2025-05-09 13:08:03 +00:00
Philipp Krones 4a64903640 Use cargo dev setup toolchain in install from source docs (#14766)
changelog: none
2025-05-09 13:06:10 +00:00
bendn 35bdd25e32 remove superseded lints 2025-05-09 19:25:55 +07:00
Alex Macleod 33f81c08aa Use cargo dev setup toolchain in install from source docs 2025-05-09 01:38:20 +00:00
Samuel Tardieu 3a6fcd2170 Allow any rust-lang team member to close an issue 2025-05-09 01:13:51 +02:00
Samuel Tardieu d8726caacc fix false negative for unnecessary_unwrap (#14758)
changelog: Fix [`unnecessary_unwrap`] false negative when any assignment
occurs in `if` branch (regardless of any variable).

Fixes: rust-lang/rust-clippy#14725
2025-05-08 22:12:02 +00:00