Commit graph

10011 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
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
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
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
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
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
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
Samuel Tardieu
1652187a03
new restriction lint: pointer_format (#14792)
I read a blog post about kernel security, and how various features might
get lost while porting to Rust. In kernel C, they have some guardrails
against divulging pointers. An easy way to replicate that in Rust is a
lint for pointer formatting. So that's what this lint does.

---

changelog: new [`pointer_format`] lint
2025-06-01 09:48:27 +00:00
Samuel Tardieu
43b7d87be1
missing_const_for_fn: consider constness of instance
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`.
2025-05-31 22:22:41 +02:00
Philipp Krones
384b53eee2 Merge remote-tracking branch 'upstream/master' into rustup 2025-05-31 14:09:03 +02:00
llogiq
2948678647
Fix dbg_macro fail to handle async coroutine desugar (#14937)
Closes rust-lang/rust-clippy#14914

----

changelog: [`dbg_macro`]: fix mishandling of async coroutine desugar
2025-05-31 08:47:19 +00:00
yanglsh
76316488e8 fix: dbg_macro fail to handle async coroutine desugar 2025-05-31 15:44:36 +08:00
a-yossy
bb19ae5e2b [explicit_deref_methods]: do not lint on method chains 2025-05-30 23:53:23 +09:00
Andre Bogus
e64dd8ed96 new restriction lint: pointer_format 2025-05-30 09:15:53 +02:00
Samuel Tardieu
3c8bfd144b
zombie_processes: do not complain about early early returns
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.
2025-05-28 20:40:05 +02:00
Jason Newcomb
beaf15532a
while_let_loop: Include let assignment in suggestion (#14756)
Placeholders are still given for the content of the whole block.
However, if the result of the original `if let` or `match` expression
was assigned, the assignment is reflected in the suggestion.

No-op assignments (`let x = x;`) are skipped though, unless they contain
an explicit type which might help the compiler (`let x: u32 = x;` is
kept).

Closes rust-lang/rust-clippy#362

changelog: [`while_let_loop`]: include `let` assignment in suggestion
2025-05-28 16:26:14 +00:00
Alejandra González
3a1159ed9f
needless_return: look inside else if parts as well (#14798)
`if` expressions don't necessarily contain a block in the `else` part in
the presence of an `else if`. The `else` part, if present, must be
handled as a regular expression, not necessarily as a block expression.

Found while applying Clippy to triagebot and looking at the result. This
also found an issue in Clippy itself.

changelog: [`needless_return`]: look inside `else if` parts as well
2025-05-28 15:42:03 +00:00
Alex Macleod
4f3d529c88 Remove incremental test, disable incremental for cargo tests 2025-05-28 15:17:32 +00:00
beetrees
1d903b6d10 Stabilise repr128 2025-05-28 15:14:34 +01:00
yanglsh
1c070ca1c8 fix: branches_sharing_code suggests wrongly when dealing with macros 2025-05-28 21:04:22 +08:00