Commit graph

10050 commits

Author SHA1 Message Date
Samuel Tardieu
8ec6f1a96f
Fix suggestion-cases-error of empty_line_after_outer_attr (#15078)
Fixes: rust-lang/rust-clippy#14980

changelog: Fix suggestion-cases-error of [`empty_line_after_outer_attr`]
2025-06-20 07:12:49 +00:00
relaxcn
95778b554d Fix suggestion-cases-error of empty_line_after_outer_attr 2025-06-20 07:07:51 +00:00
llogiq
62fd159a5d
Fix non_copy_const ICE (#15083)
fixes rust-lang/rust-clippy#15069

----

changelog: none
2025-06-19 20:46:45 +00:00
Samuel Tardieu
59291a75df
Fix clippy::question_mark on let-else with cfg (#15082)
Fixes rust-lang/rust-clippy#13642

changelog: Fix false positive in [`question_mark`] when else branch of
let-else contains `#[cfg]`
2025-06-19 20:34:05 +00:00
Jason Newcomb
ac8f50473c Fix non_copy_const ICE 2025-06-19 16:03:21 -04:00
Max Siling
4aa93a1129
Fix clippy::question_mark on let-else with cfg 2025-06-19 21:55:35 +03:00
Jason Newcomb
498562df52
Check MSRV before suggesting applying const to a function (#15080)
If a function environment contains trait bounds other than `Sized`,
`const` cannot be used before Rust 1.61.

changelog: [`missing_const_for_fn`]: check MSRV before emitting lint on
function containing non-`Sized` trait bounds

Fixes rust-lang/rust-clippy#15079

r? Jarcho
2025-06-19 18:34:13 +00:00
Catherine Flores
d8e99530c8
Fix exhaustive_structs FP on structs with default valued field (#15022)
Closes rust-lang/rust-clippy#14992

changelog: [`exhaustive_structs`] fix FP on structs with default valued
field
2025-06-19 13:38:28 +00:00
Samuel Tardieu
6524bf78b6
Check MSRV before suggesting applying const to a function
If a function environment contains trait bounds other than `Sized`,
`const` cannot be used before Rust 1.61.
2025-06-19 15:26:36 +02:00
Jason Newcomb
acd8810e77 Prepare to split lints into multiple crates
* Move `declare_clippy_lint` to it's own crate
* Move lint/group registration into the driver
* Make `dev update_lints` handle multiple lint crates
2025-06-18 22:37:23 -04:00
Jason Newcomb
af9d56860e
Add lint for broken doc links (#13696)
fixes https://github.com/rust-lang/rust-clippy/issues/2179

changelog: [`doc_broken_link`]: Add pedantic lint to catch broken doc
links that won't produce a link tag by rustdoc.
2025-06-16 15:19:03 +00:00
Samuel Tardieu
4d67a1c64a
Fix FP of identity_op when encountering Default::default() (#15028)
Fixes: rust-lang/rust-clippy#14932

changelog: Fix false positive of [`identity_op`] when encountering
`Default::default()`.
2025-06-15 22:16:14 +00:00
dswij
086a7c9780
Fix needless_doctest_main panic when doctest is invalid (#15052)
Closes rust-lang/rust-clippy#8244
Closes rust-lang/rust-clippy#15041

This feels like a bug with the compiler, because the panic happens when
`Diag` is getting unwinded. However, `drop()` is already called in
`.cancel()` so this should not happen.

In this PR, I find a workaround to just call `emit()`, since the
`DiagCtxt` here is just a `io::sink`, nothing will happen and the panic
just goes away.

changelog: [`needless_doctest_main`] fix panic when doctest is invalid
2025-06-14 15:58:39 +00:00
relaxcn
2dfab750e7 fix ci/cd error 2025-06-14 17:24:09 +08:00
yanglsh
7d708a45af fix: needless_doctest_main panic when doctest is invalid 2025-06-14 15:04:19 +08:00
relaxcn
bf1a276db3 make it support more cases 2025-06-14 04:58:47 +08:00
yanglsh
535b0d5708 fix: exhaustive_structs FP on structs with default valued field 2025-06-14 01:19:12 +08:00
Samuel Tardieu
506411d9d1
Fix collapsible_else_if FP on conditionally compiled stmt (#14906)
Closes rust-lang/rust-clippy#14799

changelog: [`collapsible_else_if`] fix FP on conditionally compiled stmt
2025-06-13 15:45:00 +00:00
yanglsh
fea8dd28a0 Lint more cases in collapsible_else_if 2025-06-13 22:54:59 +08:00
Philipp Krones
4ef75291b5
Rustup (#15044)
r? @ghost

changelog: none
2025-06-13 08:22:55 +00:00
Philipp Krones
85655d4a09
Merge remote-tracking branch 'upstream/master' into rustup 2025-06-13 10:17:14 +02:00
Samuel Tardieu
59d8345852
Fix suggestion-causes-error of manual_swap (#14978)
Fixes: rust-lang/rust-clippy#14931

changelog: Fix [`manual_swap`]'s suggestion-causes-error when the
variable is mutable or as loop variable.
2025-06-12 23:21:32 +00:00
Samuel Tardieu
180adb3eb2
Fix unit_arg suggests wrongly for Default::default (#14881)
Closes rust-lang/rust-clippy#14857

changelog: [`unit_arg`] fix wrong suggestion for `Default::default`
2025-06-12 23:21:07 +00:00
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
relaxcn
7cb7e28c4d Fix FP of identity_op when encountering Default::default() 2025-06-12 00:37:05 +08: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
bors
2f80ead27c Auto merge of #138677 - shepmaster:consistent-elided-lifetime-syntax, r=traviscross,jieyouxu
Add a new `mismatched-lifetime-syntaxes` lint

The lang-team [discussed this](https://hackmd.io/nf4ZUYd7Rp6rq-1svJZSaQ) and I attempted to [summarize](https://github.com/rust-lang/rust/pull/120808#issuecomment-2701863833) their decision. The summary-of-the-summary is:

- Using two different kinds of syntax for elided lifetimes is confusing. In rare cases, it may even [lead to unsound code](https://github.com/rust-lang/rust/issues/48686)! Some examples:

    ```rust
    // Lint will warn about these
    fn(v: ContainsLifetime) -> ContainsLifetime<'_>;
    fn(&'static u8) -> &u8;
    ```

- Matching up references with no lifetime syntax, references with anonymous lifetime syntax, and paths with anonymous lifetime syntax is an exception to the simplest possible rule:

    ```rust
    // Lint will not warn about these
    fn(&u8) -> &'_ u8;
    fn(&'_ u8) -> &u8;
    fn(&u8) -> ContainsLifetime<'_>;
    ```

- Having a lint for consistent syntax of elided lifetimes will make the [future goal](https://github.com/rust-lang/rust/issues/91639) of warning-by-default for paths participating in elision much simpler.

---

This new lint attempts to accomplish the goal of enforcing consistent syntax. In the process, it supersedes and replaces the existing `elided-named-lifetimes` lint, which means it starts out life as warn-by-default.
2025-06-05 19:49:30 +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
Max Claus Nunes
8964f6ed27
Add lint for broken doc links
Fix false positives on broken link detection

Refactor variable names

Fix doc comment about broken link lint

Refactor, remove not used variable

Improve broken link to catch more cases and span point to whole link

Include reason why a link is considered broken

Drop some checker because rustdoc already warn about them

Refactor to use a single enum instead of multiple bool variables

Fix lint warnings

Rename function to collect broken links

Warn directly instead of collecting all entries first

Iterate directly rather than collecting

Temporary change to confirm with code reviewer the next steps

Handle broken links as part of the fake_broken_link_callback handler

Simplify broken link detection without state machine usage

Fix typos

Add url check to reduce false positives

Drop reason enum as there is only one reason

Fix duplicated diagnostics

Fix linter
2025-06-05 15:59:21 -03: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
relaxcn
29492da34b Fix suggestion-causes-error of manual_swap 2025-06-05 02:01:51 +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
Jake Goulding
8b59e34a80 Replace elided_named_lifetimes with mismatched_lifetime_syntaxes 2025-06-04 10:40:04 -04: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