Commit graph

22786 commits

Author SHA1 Message Date
Samuel Tardieu
ce8d263874
Fixes manual_flatten removes the useless if let (#14861)
Closes rust-lang/rust-clippy#14692

The suggestion of `manual_flatten` does not includes the replacement of
`if let` so far despite of `.flatten()` suggestion.
This PR eliminates a redundant `if let`.

changelog: [`manual_flatten`] the suggestion removes `if let`
2025-06-12 23:20:25 +00:00
Alejandra González
6d7c16a3d6
Remove ClippyCtfe pass (#14712)
It doesn't seem to be load bearing for any clippy lints and the rustc
ones that no longer appear behave the same as they would for a `cargo
check`

r? @blyxyas

changelog: none
2025-06-11 22:14:03 +00:00
donkomura
358b80cc1f
Fix manual_flatten removes the useless if let
The suggestion of `manual_flatten` does not includes the replacement
of `if let` so far despite of `.flatten()` suggestion. This change
eliminates a redundant `if let`.

changelog: [`manual_flatten`] the suggestion removes `if let`
2025-06-09 22:00:55 +09:00
llogiq
9e7782b809
Fix match_single_binding misses curlies on type signatures (#15017)
Closes rust-lang/rust-clippy#14991

----

changelog: [`match_single_binding`] fix missing curlies on type
signatures
2025-06-08 13:21:14 +00:00
Alex Macleod
3af333e346
Fix create_dir ignores paths in suggestions (#15011)
Closes rust-lang/rust-clippy#14994

changelog: [`create_dir`] fix missing paths in suggestions
2025-06-08 13:07:59 +00:00
yanglsh
b5eac24820 fix: match_single_binding misses curlies on type signatures 2025-06-08 20:19:24 +08:00
llogiq
737b8be34d
Fix std_instead_of_core FP when part of the use cannot be replaced (#15016)
Closes rust-lang/rust-clippy#14982

----

changelog: [`std_instead_of_core`] fix FP when part of the `use` cannot
be replaced
2025-06-08 11:58:08 +00:00
yanglsh
d98070dbdb fix: std_instead_of_core FP when part of the use cannot be replaced 2025-06-08 19:31:15 +08:00
llogiq
a1a1393171
Invert suggestion if pointer is tested for non-nullness (#15015)
Fixes rust-lang/rust-clippy#15010

----

changelog: [`cmp_null`]: emit proper suggestion when pointer is checked
for non-nullness
2025-06-08 08:57:45 +00:00
Samuel Tardieu
f397a302a9
Invert suggestion if pointer is tested for non-nullness 2025-06-08 10:29:30 +02:00
yanglsh
4d6254c688 fix: create_dir ignores paths in suggestions 2025-06-08 13:15:29 +08:00
Catherine Flores
0138c79f76
Add missing word to cloned_ref_to_slice_refs docs (#15012)
changelog: none
2025-06-08 00:48:50 +00:00
Vincent Ging Ho Yim
aace547a00
Add missing word to cloned_ref_to_slice_refs docs
changelog: none
2025-06-08 01:49:36 +10:00
dswij
33052be5a6
Fix branches_sharing_code suggests wrongly when dealing with macros (#14907)
Closes rust-lang/rust-clippy#14873

changelog: [`branches_sharing_code`] fix wrong suggestions when dealing
with macros
2025-06-07 13:52:02 +00:00
Samuel Tardieu
f2922e7a27
fix typo (#14995)
changelog: none
2025-06-06 10:39:17 +00:00
Ada Alakbarova
5930e54ce5
fix typo 2025-06-06 12:28:44 +02:00
llogiq
6bb0c97409
Fix false positive for unused_unit (#14962)
Given a type alias as follows, clippy would detect a false positive for
`unused_unit`.

```rust
type UnusedParensButNoUnit = Box<dyn (Fn())>;
```

changelog: [`unused_unit`]: fix false positive for `Fn` bounds
2025-06-05 19:44:04 +00:00
llogiq
da93448c98
Do not recurse indefinitely while checking for inner mutability (#14965)
`clippy_utils::ty::InteriorMut::interior_mut_ty_chain` must stop
recursing forever when types are chained indefinitely due to the use of
associated types in generics. A false negative is acceptable, and
documented here.

Should this situation be later identified specifically, a conversion of
`Option` to `Result` would allow separating the infinitely recursive
case from a negative one.

changelog: [`mutable_key_type`]: fix ICE when infinitely associated
generic types are used

Fixes rust-lang/rust-clippy#14935
2025-06-05 19:39:14 +00:00
llogiq
b379d54c22
Introduce coerce_container_to_any (#14812)
This PR introduces a lint which detects when `&Box<dyn Any>` is coerced
to `&dyn Any`, which is usually a mistake where the intent was to
directly pass the `dyn Any` inside the box without coercion.

cc @llogiq

Remaining work:
- [x] Documentation
- [x] Generalize from Box to any implementer of `Deref<Target=dyn Any>`

----

changelog: add [`coerce_container_to_any`] lint
2025-06-05 19:37:32 +00:00
llogiq
6ef2a2d177
add new lint: ip_constant (#14878)
Closes: rust-lang/rust-clippy#14819

changelog: new lint: [`ip_constant`]
2025-06-05 19:36:33 +00:00
Alex Macleod
f8a3929c3c
Do not lint macro generated codes (#14976)
Fixes rust-lang/rust-clippy#14958

`disallowed_names` was used to lint code generated by macros. This
behavior can confuse programmers who did not write the macro themselves.
This change suppresses lints for code originating from macros, including
external ones.

changelog: [`disallowed_names`] do not lint macro generated codes
2025-06-05 15:45:51 +00:00
dswij
cf75dd4700
Remove incremental test, disable incremental for cargo tests (#14910)
Fixes https://github.com/rust-lang/rust-clippy/issues/11126

It avoids the ICE when the number of lints changes, this is only a
problem for clippy in development but cleaning the clippy dir requires a
lot of rebuilding

changelog: none
2025-06-05 15:45:47 +00:00
Alejandra González
c90c7c494d
doc_suspicious_footnotes: lint text that looks like a footnote (#14708)
changelog: [`doc_suspicious_footnotes`]: lint for text that looks like a
footnote reference but has no definition

This is an alternative to https://github.com/rust-lang/rust/pull/137803,
meant to address the concerns about false positives.

This lint only fires when the apparent footnote reference has a name
that's made from pure ASCII digits. This choice is justified by running
lintcheck on the top 200 crates, plus the clippy default set:

1. [I ran
lintcheck](https://gist.github.com/notriddle/59072476c9c1fd569fee421270dad665)
with a modded version of this lint that didn't check for digits only. It
produced a false positive warning on a line in mdbook that had a regex,
and no true positives at all.
2. [I also ran
lintcheck](https://gist.github.com/notriddle/74eb8c9e1939b9f5c5549bf1d4fa238a)
with a custom lint that fired on any valid footnote reference with a
non-ascii-digit name. `cargo` uses one in its job_queue module, and
that's all it found.

cc @GuillaumeGomez
2025-06-05 09:09:59 +00:00
dswij
a76c2b34e7
Fix unnecessary_debug_formatting FP inside Debug impl (#14955)
Closes rust-lang/rust-clippy#14952

The lint suggests using `.display()` on `Path`, which is actually
correct.

changelog: [`unnecessary_debug_formatting`] fix FP inside `Debug` impl
2025-06-04 15:54:56 +00:00
donkomura
c9a97e1f82
Do not lint macro generated codes
`disallowed_names` was used to lint code generated by macros.
This behavior can confuse programmers who did not write the macro
themselves. This change suppresses lints for code originating from
macros, including external ones.

changelog: [`disallowed_names`] do not lint macro generated codes
2025-06-05 00:44:39 +09:00
Samuel Tardieu
ed143afc7f
fix suggestion-causes-error of print_literal and write_literal (#14961)
Fixes: rust-lang/rust-clippy#14930

changelog: Fix [`print_literal`] and [`write_literal`]'s
suggestion-causes-error when using format argument like `{0:2$.1$}`
2025-06-04 08:27:33 +00:00
Samuel Tardieu
1ae37ada08
Do not recurse indefinitely while checking for inner mutability
`clippy_utils::ty::InteriorMut::interior_mut_ty_chain` must stop
recursing forever when types are chained indefinitely due to the use of
associated types in generics. A false negative is acceptable, and
documented here.

Should this situation be later identified specifically, a conversion of
`Option` to `Result` would allow separating the infinitely recursive
case from a negative one.
2025-06-04 10:11:56 +02:00
relaxcn
6ed003d893 fix suggestion-causes-error of print_literal and write_literal 2025-06-04 07:27:23 +00:00
llogiq
84ef7fb414
Use interned strings when possible, for efficiency purposes (#14963)
Also, a number of unnecessary `.as_str()` calls have been removed for
clarity.

changelog: none
2025-06-04 05:16:22 +00:00
Samuel Tardieu
2a5a2fae2c
Use interned strings when possible, for efficiency purposes
Also, a number of unnecessary `.as_str()` calls have been removed for
clarity.
2025-06-03 20:50:40 +02:00
Benjamin Schulz
1e96456b84 Reference correct PR 2025-06-03 19:35:39 +02:00
Benjamin Schulz
ed226d2c6b Fix false positive for unused_unit 2025-06-03 19:25:43 +02:00
Samuel Tardieu
a4debd2345
Lint reversed ordering in partial ord impl (#14945)
Fixes rust-lang/rust-clippy#14574

Lint reversed ordering in partial ord impl

changelog: [`non_canonical_partial_ord_impl`] lint reversed ordering
2025-06-03 15:37:41 +00:00
donkomura
3b64c5c465
Lint reversed ordering in partial ord impl
changelog: [non_canonical_partial_ord_impl] lint reversed ordering

Co-authored-by: Samuel Tardieu <sam@rfc1149.net>
2025-06-04 00:00:19 +09:00
Jason Newcomb
eafef84736
missing_const_for_fn: consider constness of instance (#14759)
When determining when a function or method can be called from a `const`
context, the determination must be made on the instance, not on the
declaration. This makes a difference, for example, with `const_trait`
traits whose implementations may or may not be `const`.

changelog: [`missing_const_for_fn`]: when checking if a function or
method can be called from a `const` context, look at the concrete
implementation rather than at the trait definition

Fixes rust-lang/rust-clippy#14658

r? @Jarcho
2025-06-03 14:03:51 +00:00
Jason Newcomb
716eadf674
zombie_processes: do not complain about early early returns (#14912)
If an early return is found under the HIR local declaration node but
before the child process is created, it should not trigger the lint
because the child process has not yet been created.

changelog: [`zombie_process`]: do not complain about early early returns

Fixes rust-lang/rust-clippy#14911
2025-06-03 13:48:53 +00:00
relaxcn
8d8b3f16d7 Add new lint: ip_consant 2025-06-03 09:11:20 +00:00
Michael Howell
fcfbcc81f2 doc_suspicious_footnotes: lint text that looks like a footnote 2025-06-02 13:20:49 -07:00
Benjamin Saunders
b51e73701d Introduce coerce_container_to_any 2025-06-02 11:11:56 -07:00
Alex Macleod
9b8c42cbb1
Test that all interned symbols are referenced in Clippy sources (#14842)
This test checks that all symbols defined in Clippy's `sym.rs` file are
used in Clippy. Otherwise, it will fail with a list of symbols which are
unused.

This test only runs when the `internal` feature is set, to allow
developers to temporarily define new, yet unused symbols without failing
the tests. Also, it will not run as part of the compiler test suite, as
an extra symbol should never be seen as a fatal problem in the compiler
repo.

changelog: none
2025-06-02 15:22:31 +00:00
llogiq
6fa2866a96
Use None::<u64> instead of 0 to denote an absence of value (#14957)
`clippy_lints::casts::utils::int_ty_to_nbits` used to return `0` to
indicate that the argument was not an integral type. It is more
idiomatic to use `Option<u64>` as a return type.

Also, I've added a few `FIXME:` at places where only `f32` and `f64` are
considered, as we now have `f16` and `f128` to deal with.

changelog: none
2025-06-02 12:41:09 +00:00
llogiq
d7b27ecbf3
add lint infallible_try_from (#14813)
Looks for `TryFrom` implementations with uninhabited error types and
suggests to implement `From` instead.

Fixes rust-lang/rust-clippy#2144

---

changelog: Add [`infallible_try_from`] lint
2025-06-02 11:52:57 +00:00
Samuel Tardieu
225abd6c0a
Use None::<u64> instead of 0 to denote an absence of value
`clippy_lints::casts::utils::int_ty_to_nbits` used to return `0` to
indicate that the argument was not an integral type. It is more
idiomatic to use `Option<u64>` as a return type.
2025-06-02 13:32:30 +02:00
yanglsh
a4360d6fc3 fix: unnecessary_debug_formatting FP inside Debug impl 2025-06-02 17:23:56 +08:00
Samuel Tardieu
88bb8d169b
Fix semicolon_outside_block suggests wrongly when inside macros (#14954)
Closes rust-lang/rust-clippy#14926

changelog: [`semicolon_outside_block`] fix wrong suggestions when inside
macros
2025-06-02 09:17:55 +00:00
yanglsh
12fc6c7cc9 fix: semicolon_outside_block suggests wrongly when inside macros 2025-06-02 17:03:08 +08:00
Catherine Flores
a5a7eea0a2
chore: replace smart quote with straight quote in update_lints comment (#14949)
changelog: [update_lints]: replaced a smart quote
2025-06-01 14:18:54 +00:00
krikera
89dc07acb5 chore: fix smart quote in comment used by update_lints script 2025-06-01 19:20:33 +05:30
llogiq
466e0fb154
Do not count deprecated lints in lint total (#14948)
In order to be consistent with our documentation, deprecated lints
should not be counted when displaying the total number of lints on the
[web site](https://rust-lang.github.io/rust-clippy/master/index.html).

For example, as of 2025-06-01, there are 784 non-deprecated lints which
are referred to as "over 750 lints" in the documentation, but the web
site displays "Total number: 799". When one new lint will be added,
there will be a discrepancy ("over 750 lints" vs. "Total number: 800")
if this is not fixed.

changelog: none

r? @llogiq
2025-06-01 13:00:06 +00:00
Timo
3f48a2b01e
Use interned symbols instead of strings in more places (#14855)
changelog: none
2025-06-01 12:02:36 +00:00