Commit graph

22947 commits

Author SHA1 Message Date
Timo
936baca0cd
Consider deref'ed argument as non-temporary (#15172)
If there are more than one dereference (there is one corresponding
matched with a borrow in any case), consider that the argument might
point to a place expression, which is the safest choice.

Also, use an appropriate number of dereferences in suggestions involving
arguments using themselves multiple dereferences.

Fixes rust-lang/rust-clippy#15166

changelog: [`swap_with_temporary`]: fix false positive leading to
different semantics being suggested, and use the right number of
dereferences in suggestion

r? y21

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

-
[beta-nomination](https://github.com/rust-lang/rust-clippy/pull/15172#issuecomment-3016752569)
by [samueltardieu](https://github.com/samueltardieu)

*Managed by `@rustbot`—see
[help](https://forge.rust-lang.org/triagebot/note.html) for details*

<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
2025-06-30 18:46:11 +00:00
Samuel Tardieu
b57bf6b64d
Fix cast_possible_truncation should not suggest inside const context (#15164)
Closes rust-lang/rust-clippy#15163

This lint should not give suggestions in const context for now, since a
lot of the commonly used method of `Result` is not const.

changelog: [`cast_possible_truncation`] fix improperly give suggestions
inside const context
2025-06-29 21:53:52 +00:00
yanglsh
9cba70b283 fix: cast_possible_truncation should not suggest inside const context 2025-06-30 01:33:35 +08:00
Samuel Tardieu
1f76a23d4d
missing_panics_doc: Allow unwrap() and expect() inside const-only contexts (#15170)
changelog: [`missing_panics_doc`]: Allow unwrap() and expect()s in
const-only contexts

Fixes rust-lang/rust-clippy#15169.

As far as I can tell, this change keeps this lint in line with similar
issues and their fixes such as
https://github.com/rust-lang/rust-clippy/pull/13382 and
rust-lang/rust-clippy#10240, so I feel pretty confident that the
behavior it exhibits after this PR is correct.
2025-06-29 17:12:04 +00:00
itsjunetime
ff3c9c15b7
missing_panics_doc: Correctly distinguish maybe-const vs always-const contexts for missing_panics_doc
changelog: [`missing_panics_doc`]: Allow unwrap() and expect()s in const-only contexts
2025-06-29 10:54:13 -06:00
Samuel Tardieu
ad7de948a8
Consider deref'ed argument as non-temporary
If there are more than one dereference (there is one corresponding
matched with a borrow in any case), consider that the argument might
point to a place expression, which is the safest choice.

Also, use an appropriate number of dereferences in suggestions involving
arguments using themselves multiple dereferences.
2025-06-29 16:36:50 +02:00
dswij
428208eb9b
Fix disallowed_script_idents FP on identifiers with _ (#15123)
Closes rust-lang/rust-clippy#15116

The cause for this issue is that `_` belongs to the `Common` catagory in
unicode instead of `Latin` like other ASCII alphabets. Since ASCII
characters are always allowed, I just added an extra `is_ascii()` check
to ensure this.

changelog: [`disallowed_script_idents`] fix FP on identifiers with `_`
2025-06-28 08:48:07 +00:00
dswij
8633bcbc3c
zero_ptr: lint in const context as well (#15152)
The lint was extra restrictive, and didn't suggest using
`core::ptr::null` and `core::ptr::null_mut` in `const` contexts although
they have been const-stabilized since Rust 1.24.

changelog: [`zero_ptr`]: lint in `const` context as well

@rustbot label +I-false-negative +C-bug
2025-06-28 08:46:57 +00:00
yanglsh
7e406e276a fix: disallowed_script_idents FP on identifiers with _ 2025-06-27 22:16:58 +08:00
Samuel Tardieu
9117cb0223
zero_ptr: lint in const context as well
The lint was extra restrictive, and didn't suggest using
`core::ptr::null` and `core::ptr::null_mut` in `const` contexts although
they have been const-stabilized since Rust 1.24.
2025-06-26 23:09:37 +02:00
Samuel Tardieu
c5dbd1de07
Lint docs: Sort versions, so that stable comes first (#15149)
I expect that most people use stable Clippy. So having `master` be the
first documentation link in the list is weird. Now the versions are
sorted stable->beta->master.

changelog: none
2025-06-26 19:13:14 +00:00
Philipp Krones
22c0226aff
Lint docs: Sort versions, so that stable comes first
I expect that most people use stable Clippy. So having `master` be the first
documentation link in the list is weird. Now the versions are sorted
stable->beta->master.
2025-06-26 19:59:04 +02:00
Philipp Krones
cd15aeb70b
Ping notriddle when a clippy lint in clippy_lints/doc is modified (#15147)
Related to [this Zulip
thread](https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/Reviewing.20the.20.60doc.60.20lints/with/525943439).

@notriddle Would you want that?

changelog: none
2025-06-26 17:48:02 +00:00
Philipp Krones
c950602c01
Rustup (#15148)
r? @ghost

changelog: none
2025-06-26 17:34:27 +00:00
Philipp Krones
32fcff8aa8
Bump Clippy version -> 0.1.90 2025-06-26 19:30:02 +02:00
Philipp Krones
9b41d8fdb6
Bump nightly version -> 2025-06-26 2025-06-26 19:29:50 +02:00
Philipp Krones
90364dd178
Merge remote-tracking branch 'upstream/master' into rustup 2025-06-26 19:29:33 +02:00
Philipp Krones
8050e591b6
Update book and templates with feature freeze (#14456)
This PR announces the feature freeze period talked about in
https://github.com/rust-lang/rust-clippy/issues/14364

1. Add the page to the book
2. Modify the in-Github templates.
3. The third commit (to be squashed into the first) rolls the date
mentioned 6 weeks (so, starting on May 9th and ending on August 20th).
This gives us a comfortable buffer to make choices for this period.

We have a pending discussion on the #14364. So having some more time to
make choices is very nice. I'm also preparing a Github action for
detecting new lints and posting a comment about the feature freeze
(being worked on in another branch)

Something I'd like comment on is the date formatting. I'm not sure if
"May 9th to the first of August" is the correct way of writing this
information in a book 😅.

changelog: Announce the feature freeze from May 9th to the first of
August
2025-06-26 16:45:13 +00:00
Samuel Tardieu
4116a72a08
Ping notriddle when a clippy lint in clippy_lints/doc is modified 2025-06-26 18:45:11 +02:00
Philipp Krones
b88d162d2a
Add link to the feature freeze tracking issue to the book 2025-06-26 18:40:51 +02:00
Philipp Krones
40554ef4aa
Add beta-accepted to CHANGELOG for 1.88 (#15130)
Add beta-accepted to CHANGELOG for 1.88 since it was missed at
rust-lang/rust-clippy#5095

changelog: none

r? flip1995
2025-06-26 16:30:45 +00:00
Alexey Semenyuk
95f0991ad4 Add beta-nominated to changelog for 1.88 2025-06-25 15:38:20 +05:00
Philipp Krones
75463814c6
changelog: link to the correct PR (#15125)
changelog: none
2025-06-25 09:13:30 +00:00
bors
708ffd5ccf Auto merge of #142997 - workingjubilee:rollup-6lxec87, r=workingjubilee
Rollup of 15 pull requests

Successful merges:

 - rust-lang/rust#135731 (Implement parsing of pinned borrows)
 - rust-lang/rust#138780 (Add `#[loop_match]` for improved DFA codegen)
 - rust-lang/rust#142453 (Windows: make `read_dir` stop iterating after the first error is encountered)
 - rust-lang/rust#142633 (Error on invalid signatures for interrupt ABIs)
 - rust-lang/rust#142768 (Avoid a bitcast FFI call in transmuting)
 - rust-lang/rust#142825 (Port `#[track_caller]` to the new attribute system)
 - rust-lang/rust#142844 (Enable short-ice for Windows)
 - rust-lang/rust#142934 (Tweak `-Zmacro-stats` measurement.)
 - rust-lang/rust#142955 (Couple of test suite fixes for cg_clif)
 - rust-lang/rust#142977 (rustdoc: Don't mark `#[target_feature]` functions as ⚠)
 - rust-lang/rust#142980 (Reduce mismatched-lifetime-syntaxes suggestions to MaybeIncorrect)
 - rust-lang/rust#142982 (Corrected spelling mistake in c_str.rs)
 - rust-lang/rust#142983 (Taint body on invalid call ABI)
 - rust-lang/rust#142988 (Update wasm-component-ld to 0.5.14)
 - rust-lang/rust#142993 (Update cargo)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-25 04:05:47 +00:00
bors
4a4d67227e Auto merge of #140999 - hkBst:update-escaper, r=nnethercote
update to literal-escaper 0.0.4 for better API without `unreachable` and faster string parsing

This is the replacement for just the part of https://github.com/rust-lang/rust/pull/138163 dealing with the changed API of unescape functionality, since that got moved into its own crate.

<del>This uses an unpublished version of literal-escaper (https://github.com/rust-lang/literal-escaper/pull/8).</del>

r? `@nnethercote`
2025-06-25 01:03:30 +00:00
Ada Alakbarova
c11bc75fb0
changelog: link to the correct PR 2025-06-25 01:00:34 +02:00
Jana Dönszelmann
ae6ab44d68 fix clippy 2025-06-24 23:00:31 +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
Marijn Schouten
05b74d558f update to literal-escaper 0.0.4 for better API without unreachable and faster string parsing 2025-06-23 06:36:22 +00:00
Jonathan Brouwer
1d764e022f Port #[no_mangle] to new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-22 22:17:04 +02:00
Jonathan Brouwer
b92cccb977 Port #[must_use] to new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-22 14:51:58 +02:00
David Tolnay
953bf2be89 All HIR attributes are outer 2025-06-21 11:11:34 -07: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
Matthias Krüger
f027fc8bca Rollup merge of #142787 - samueltardieu:diag-items-for-clippy, r=Manishearth,Urgau
Add diagnostic items for Clippy

Clippy still uses some paths to access items from the standard library. Adding the missing diagnostic items allows removing the last remaining paths.

Closes rust-lang/rust-clippy#5393
2025-06-21 10:53:26 +02: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
bors
f53cd2be0d Auto merge of #142794 - tgross35:rollup-iae7okj, r=tgross35
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#142331 (Add `trim_prefix` and `trim_suffix` methods for both `slice` and `str` types.)
 - rust-lang/rust#142491 (Rework #[cold] attribute parser)
 - rust-lang/rust#142494 (Fix missing docs in `rustc_attr_parsing`)
 - rust-lang/rust#142495 (Better template for `#[repr]` attributes)
 - rust-lang/rust#142497 (Fix random failure when JS code is executed when the whole file was not read yet)
 - rust-lang/rust#142575 (Ensure copy* intrinsics also perform the static self-init checks)
 - rust-lang/rust#142650 (Refactor Translator)
 - rust-lang/rust#142713 (mbe: Refactor transcription)
 - rust-lang/rust#142755 (rustdoc: Remove `FormatRenderer::cache`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-20 23:09:48 +00: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