Commit Graph

13297 Commits

Author SHA1 Message Date
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 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
yanglsh e50ef68f0c fix: wildcard_enum_match_arm suggests wrongly with raw identifiers 2025-06-21 13:46:43 +08: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
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
Samuel Tardieu 6ffff5f009 New lint: manual_is_multiple_of 2025-06-20 09:42:28 +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
Max Siling 4aa93a1129 Fix clippy::question_mark on let-else with cfg 2025-06-19 21:55:35 +03: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
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
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 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
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 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 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
Samuel Tardieu 322e1393a4 Fix false positive of borrow_deref_ref
If a reborrow is itself borrowed mutably, do not propose to replace it
by the original reference.
2025-06-12 19:14:35 +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