Commit graph

22838 commits

Author SHA1 Message Date
klensy
9ed1843653 dogfood clippy::or_fun_call 2025-06-17 15:42:54 +03:00
Samuel Tardieu
19c1c70905
Add allow-invalid configuration option for disallowed_* to the documentation (#14845)
Close rust-lang/rust-clippy#14836

changelog: none
2025-06-17 09:05:05 +00:00
Timo
b765acb49d
docs: add link to span_lint in diagnostics.rs. (#15065)
Some of the docs in `clippy_utils/src/diagnostics.rs` were missing links
to `span_lint`.

changelog: none
2025-06-16 21:52:28 +00:00
Chris Bloodsworth
75762c41d4 docs: add link to span_lint in diagnostics.rs.
changelog: None
2025-06-16 17:36:02 -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
97815d0cda
docs: make unbuffered_bytes docs more consistent (#15019)
changelog: None
2025-06-14 18:05:34 +00:00
dswij
49d0f86a73
Remove unneeded lifetime (#15040)
changelog: none
2025-06-14 17:40:22 +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
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
ee80deb723 Apply collapsible_else_if to Clippy itself 2025-06-13 22:55:06 +08: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
19c2f0332c
Bump nightly version -> 2025-06-13 2025-06-13 10:17:27 +02:00
Philipp Krones
85655d4a09
Merge remote-tracking branch 'upstream/master' into rustup 2025-06-13 10:17:14 +02:00
Samuel Tardieu
6662aedb86
[PERF] Optimize 3rd heaviest func, (81b -> 10m) (#15043)
So this is funny, the query `tcx.module_children` was top 3 in most
time consuming functions in Clippy, it was being called 24384 times in
tokio. "Unacceptable!" I thought. Digging a bit around, turns out that
`clippy::strlen_on_c_strings` was calling for `get_def_path` via
`match_libc_symbol`. This query pretty-prints things and performs some
analysis.

Yes, we were running early lint checks to see if symbols were from
`libc`.
I don't really trust callgrind when it says I've turn 81 billion
instructions
into like 10 million. So I benchmarked this the good ol' "compiling 20
times
without incr" method and it went from 0.31s-0.45s to 0.25s
constistently.

(Profiled, and "benchmarked") on tokio.

What I can get behind is via `strlen_on_c_strings` changing from 31
million instructions into 76k. 🎉 🥳

changelog: [`strlen_on_c_strings`]: Optimize it by 99.75%
2025-06-13 06:09:14 +00:00
blyxyas
6cd55b966f Optimize by 99.75% strlen_on_c_strings, 8.5% globally
So this is funny, the query `tcx.module_children` was top 3 in most
time consuming functions in Clippy, it was being called 24384 times in
tokio. "Unacceptable!" I thought. Digging a bit around, turns out that
`clippy::strlen_on_c_strings` was calling for `get_def_path` via
`match_libc_symbol`. This query pretty-prints things and performs some
analysis.

Yes, we were running early lint checks to see if symbols were from `libc`.
I don't really trust callgrind when it says I've turn 81 billion instructions
into like 10 million. So I benchmarked this the good ol' "compiling 20 times
without incr" method and it went from 0.31s-0.45s to 0.25s constistently.

(Profiled, and "benchmarked") on tokio.
2025-06-13 02:08:35 +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
Samuel Tardieu
0d21f087df
Remove unneeded lifetime 2025-06-12 22:27:22 +02: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
Boot0x7c00
4389e177eb optimize codes 2025-06-09 03:05:28 +00:00
nekename
982abc48b3
docs: make unbuffered_bytes docs more consistent 2025-06-08 18:37:39 +01: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
Guillaume Gomez
507183d438 Rollup merge of #141603 - nnethercote:reduce-P, r=fee1-dead
Reduce `ast::ptr::P` to a typedef of `Box`

As per the MCP at https://github.com/rust-lang/compiler-team/issues/878.

r? `@fee1-dead`
2025-06-06 23:53:16 +02: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
Matthias Krüger
2c951058d4 Rollup merge of #142012 - oli-obk:no-optional-spans, r=fee1-dead
Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of None

Turns out many locations actually have a span available that we could use, so I used it
2025-06-06 00:58:44 +02: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