Commit Graph

22881 Commits

Author SHA1 Message Date
Ada Alakbarova c11bc75fb0 changelog: link to the correct PR 2025-06-25 01:00:34 +02:00
Philipp Krones ad6e19a269 Changelog for Clippy 1.88 🏄 (#15095)
Violets are red,
Roses are blue,
Summer’s a feeling,
And we’re feeling it too.

<hr>

> (Please ping me when June made it as the cat of the release. I want to
send it to her owner :D)

@xFrednet voila:

![image](https://github.com/user-attachments/assets/7908abd0-76a5-4a64-a553-9c443d4c8b37)

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-06-24 16:15:22 +00:00
Alexey Semenyuk 2e63c7c684 Changelog for Clippy 1.88 2025-06-23 22:26:52 +05:00
Timo 76118ec84e Add missing space when expanding a struct-like variant (#15096)
In `wildcard_enum_match_arm`, expanding a variant with struct-like
fields was missing a space between the variant name and the opening
bracket.

Also, add a test for tuple-like variants with only one field, as those
are expanded as `VariantName(_)` instead of `VariantName(..)`.

changelog: none
2025-06-21 17:22:37 +00:00
Samuel Tardieu db539d051d Add missing space when expanding a struct-like variant
In `wildcard_enum_match_arm`, expanding a variant with struct-like
fields was missing a space between the variant name and the opening
bracket.

Also, add a test for tuple-like variants with only one field, as those
are expanded as `VariantName(_)` instead of `VariantName(..)`.
2025-06-21 19:00:38 +02:00
Samuel Tardieu a421ffbadb Fix wildcard_enum_match_arm suggests wrongly with raw identifiers (#15093)
Closes rust-lang/rust-clippy#15091

The lack of ability to escape raw identifiers is a known issue of
Clippy. In this case, it can be avoided by snippet from the code.

changelog: [`wildcard_enum_match_arm`] fix wrong suggestions with raw
identifiers
2025-06-21 16:52:03 +00:00
Timo 6330f9119b Emit lint about redundant closure on the closure node itself (#14791)
Fixes rust-lang/rust-clippy#14789

changelog: [`redundant_closure`],
[`redundant_closure_for_method_calls`]: allow lint to be allowed or
expected on the closure expression itself
2025-06-21 15:20:48 +00:00
Samuel Tardieu c0dd2d5a38 Emit lint about redundant closure on the closure node itself 2025-06-21 16:21:40 +02:00
Samuel Tardieu 07cc166acf Add MSRV test for unnecessary_debug_formatting with OsStr (#15001)
`unnecessary_debug_formatting` suggests display() respected for
MSRV but lacking of tests. This adds tests to check MSRV for OsStr.

changelog: none
2025-06-21 12:28:03 +00:00
Samuel Tardieu 7c828e63ba or_fun_call: lint more methods (#15071)
Extend `or_fun_call` lint with new checks for Option::get_or_insert,
Result::map_or.

changelog: [`or_fun_call`]: lint more methods
2025-06-21 09:21:42 +00:00
donkomura e0cb4ced0a Check the MSRV for unnecessary_debug_formatting
`unnecessary_debug_formatting` suggests display() respected for
MSRV but lacking of tests. This adds tests to check MSRV for OsStr.

changelog: none
2025-06-21 15:03:37 +09:00
yanglsh e50ef68f0c fix: wildcard_enum_match_arm suggests wrongly with raw identifiers 2025-06-21 13:46:43 +08:00
Timo 4ead403c91 Fix typo in tests/ui/missing_const_for_fn/const_trait.rs (#15090)
I think the comment is meant to refer to
[clippy_utils::qualify_min_const_fn](https://github.com/rust-lang/rust-clippy/blob/master/clippy_utils/src/qualify_min_const_fn.rs).

changelog: none
2025-06-20 23:27:52 +00:00
Samuel Moelius 1e30fa253b Fix typo in tests/ui/missing_const_for_fn/const_trait.rs 2025-06-20 19:17:35 -04:00
Timo 35026c7ea8 Fix false positive of borrow_deref_ref (#14967)
If a reborrow is itself borrowed mutably, do not propose to replace it
by the original reference.

Fixes: rust-lang/rust-clippy#14934

changelog: [`borrow_deref_ref`]: do not propose replacing a reborrow by
the original reference if the reborrow is itself mutably borrowed
2025-06-20 22:11:49 +00:00
Jason Newcomb 37cb83488a Sugg: do not parenthesize a double unary operator (#14983)
For example, adding `*` in front of `*expression` is best shown as
`**expression` rather than `*(*expression)`.

This is not perfect, as it checks whether the operator is already a
prefix of the expression, but it is better than it was before. For
example, `&`+`&mut x` will get `&&mut x` but `&mut `+`&x` will get `&mut
(&x)` as it did before this change.

changelog: none
2025-06-20 22:00:40 +00:00
Timo 98555244f0 [PERF] Don't spawn so many compilers (3/2) (19m -> 250k) (#15030)
Optimize `needless_doctest_main`, make it short-circuit, make sure that
we don't spin up a new compiler on EVERY code block.

---

The old implementation was creating a new compiler, new parser, new
thread, new SessionGlobals, new everything for each code block. No
matter if they actually didn't even contain `fn main()` or anything
relevant.

On callgrind, seems that we're reducing about a 6.7242% de cycle count
(which turns out to be a 38 million instruction difference, great!).
Benchmarked in `bumpalo-3.16.0`. Also on bumpalo we spawn 78 less
threads. This moves `SessionGlobals::new` from the top time-consuming
function by itself in some benchmarks, into one not even in the top 500.

Also, populate the test files.

changelog:[`needless_doctest_main`]: Avoid spawning so many threads in
unnecessary circumstances
2025-06-20 21:58:45 +00:00
Jason Newcomb 0601337a25 Fix manual_ok_err suggests wrongly with references (#15053)
Closes rust-lang/rust-clippy#15051

changelog: [`manual_ok_err`] fix wrong suggestions with references
2025-06-20 21:50:49 +00:00
Jason Newcomb 6064822acb Fix branches_sharing_code suggests misleadingly when in assignment (#15076)
The lint will note `the end suggestion probably needs some adjustments
to use the expression result correctly` when the expr's is not unit. So
I extend this note to also appear when the expr is in an assignment.

changelog: [`branches_sharing_code`] fix misleading suggestions when in
assignment
2025-06-20 21:48:57 +00:00
klensy ea72620f62 lint Option::get_or_insert and Result::map_or too 2025-06-20 23:59:36 +03:00
blyxyas 3745a3f7ab Even more optimizing documentation lints? (3/2)
Avoid creating so many SessionGlobals

Improve filtering and account for spacing

Actually return early
2025-06-20 12:07:35 +02:00
Alejandra González 2c1c746ebd New lint: manual_is_multiple_of (#14292)
~~I've added a `min_divisor` configuration option, default to 4, to not
trigger on smaller divisibility operations. I would prefer not to lint
`if a & 1 == 0` as `if a.is_multiple_of(2)` by default because the
former is very idiomatic in systems (and embedded) programming.~~

~~A `min_and_mask_size` option, defaulting to 3, sets the default bits
to be and-masked before this lint triggers; that would be `n` in `v &
((1 << n) - 1) == 0`. The form `v % 10 == 0` is always linted.~~

~~This PR will stay in draft mode until the next rustup which will mark
`unsigned_is_multiple_of` stable for Rust 1.87.0, and the feature flags
will be removed.~~

What should its category be? I've used "complexity", but "pedantic"
might be suitable as well.

Close rust-lang/rust-clippy#14289
changelog: [`manual_is_multiple_of`]: new lint
r? ghost
2025-06-20 09:43:53 +00:00
Samuel Tardieu 6ffff5f009 New lint: manual_is_multiple_of 2025-06-20 09:42:28 +02:00
Samuel Tardieu f25fb1adf9 Use .is_multiple_of() in Clippy tests sources
This prevents triggering the new `manual_is_multiple_of` lint on
unrelated lint tests.
2025-06-20 09:42:27 +02:00
Samuel Tardieu 0fdd0b928e Add integer_const() and is_zero_integer_const() utility functions 2025-06-20 09:42:27 +02:00
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
Samuel Tardieu db32d3980b Fix typo (#15081)
Add missing word (attribute) after the `#[expect]` attribute.

changelog: [`allow_attributes`]: Fix typo in documentation
2025-06-19 19:05:12 +00: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
Everett Pompeii 9c8f3e9b11 Fix typo
Add missing word (attribute) after the `#[expect]` attribute.
2025-06-19 10:26:08 -05: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
Alex Macleod 10780e9122 Prepare to split clippy_lints (#14684)
Based on rust-lang/rust-clippy#14633

The end goal here is to split `clippy_lints` into several independent
crates and have the driver call out to each of them to register lints.
`clippy_lints` takes way too long to compile right now.

r? @flip1995

changelog: none
2025-06-19 11:30:32 +00: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
yanglsh 77ef3d7e42 fix: branches_sharing_code suggests misleadingly when in assignment 2025-06-18 21:06:04 +08:00
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 de4f8e2bc6 fix: manual_ok_err suggests wrongly with references 2025-06-14 15:49:34 +08:00