Commit graph

10064 commits

Author SHA1 Message Date
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
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
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
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
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
yanglsh
77ef3d7e42 fix: branches_sharing_code suggests misleadingly when in assignment 2025-06-18 21:06:04 +08: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
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
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
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
Samuel Tardieu
2037075b38
Sugg: do not parenthesize a double unary operator
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.
2025-06-05 23:27:35 +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