Commit graph

23089 commits

Author SHA1 Message Date
yanglsh
222ebd0535 fix: search_is_some suggests wrongly inside macro 2025-07-14 22:38:04 +08:00
Jason Newcomb
1c64211aee
Fix manual is multiple of (#15205)
Fix several issues with `manual_is_multiple_of`

- `&a % &b == 0` compiles, but requires dereferencing `b` when replacing
with `a.is_multiple_of(b)`.
- In `a % b == 0`, if type of `a` is not certain, `a.is_multiple_of(b)`
might not be typable.
- In `a % b == 0`, `a` and `b` must be unsigned integers, not any
arbitrary types implementing `Rem` and outputing an integer.

Those fixes have required increasing the precision of type certainty
determination in the two first patches.

Fixes rust-lang/rust-clippy#15203
Fixes rust-lang/rust-clippy#15204

changelog: [`manual_is_multiple_of`]: fix various false positive
2025-07-14 08:33:27 +00:00
Samuel Tardieu
ba947c5728
Fix manual_assert suggests wrongly for macros (#15264)
Closes rust-lang/rust-clippy#15227

changelog: [`manual_assert`] fix wrong suggestions for macros
2025-07-14 07:55:25 +00:00
Jason Newcomb
d9acd919ad
fix false negative of expect_used (#15253)
Fixes: rust-lang/rust-clippy#15247

changelog: Fix the false negative of [`expect_used`] when metting
`Option::ok().expect`.
2025-07-14 07:52:48 +00:00
Jason Newcomb
43f18915e9
Fix manual_abs_diff suggests wrongly behind refs (#15265)
Closes rust-lang/rust-clippy#15254

changelog: [`manual_abs_diff`] fix wrong suggestions behind refs
2025-07-14 07:33:52 +00:00
yanglsh
901ab5b8bd fix: manual_assert suggests wrongly for macros 2025-07-14 00:19:05 +08:00
Alejandra González
6f2567d16d
Update manual_is_variant_and documentation to include equality comparison (#15239)
Update `manual_is_variant_and` documentation to include equality
comparison patterns

This commit updates the documentation for the `manual_is_variant_and`
lint to include all linted cases. Previously, the documentation only
mentioned the `.map(f).unwrap_or_default()` pattern, but the lint also
catches equality comparison patterns like `option.map(f) == Some(true)`
and `result.map(f) == Ok(true)`.

changelog: [`manual_is_variant_and`]: Update documentation to include
equality comparison patterns

fixes rust-lang/rust-clippy#15217
2025-07-13 15:24:29 +00:00
Krishna Ketan Rai
b4fc33ae8b Lint: Improve manual_is_variant_and to support equality comparison
- Add equality pattern support to manual_is_variant_and
- Update documentation and Clippy manual
2025-07-13 19:51:45 +05:30
yanglsh
9d964048ec fix: manual_abs_diff suggests wrongly behind refs 2025-07-13 21:23:51 +08:00
Alejandra González
7e2d26f4b2
Fix approx_const for some new cases (#15236)
Fix some cases for `approx_const`:
- When the literal has more digits than significant ones, the string
comparison wasn't working
- When numbers are formatted in a non trivial way (with leading `0`s or
using `_`) the lint now finds those cases

changelog: [`approx_const`]: Fix when used over overly precise literals
and non trivially formatted numerals

Fixes rust-lang/rust-clippy#15194
2025-07-12 13:57:16 +00:00
Timo
3c3ee9bddb
{flat_,}map_identity: recognize |[x, y]| [x, y] as an identity function as well (#15229)
changelog: [`map_identity`,`flat_map_identity`]: also recognize `|[x,
y]| [x, y]`

fixes rust-lang/rust-clippy#15198
2025-07-12 13:10:23 +00:00
Ada Alakbarova
e610584a9a
{flat_,}map_identity: also recognize |[x, y]| [x, y] 2025-07-12 14:02:41 +02:00
dswij
3d7188d06d
Add uninlined_format_args example for {:?} (#15228)
Before this, you had to guess how to fix a `{:?}` formatting argument. I
have happened to guess `{:?var}` in the past, got frustrated, and
disabled the lint. This additional example would have saved me a bit of
trouble.

changelog: [`uninlined_format_args`]: added an example of how to fix a
`{:?}` parameter.
2025-07-12 06:20:15 +00:00
Teodoro Freund
093b6e5de9 Fix approx_const for some new cases
Improved naming and comment
2025-07-12 07:16:23 +01:00
relaxcn
1d1b97d514 fix false negative of expect_used 2025-07-12 01:44:55 +08:00
Samuel Tardieu
e2270bb9e5
Reduce clippy lints page size (#15235)
Follow-up of https://github.com/rust-lang/rust-clippy/pull/15208.

Removed some unneeded wrappings and shortened some CSS class name.

The diff is big because of one indent level getting removed. :-/

Before this PR: 1751301
With this PR: 1663634
Reduction: -5%

r? @samueltardieu

changelog: Reduce page size and number of DOM elements on clippy lints
page
2025-07-11 05:36:30 +00:00
Samuel Tardieu
488f4dd04d
fix legacy_numeric_constants suggestion when call is wrapped in parens (#15191)
Fixes rust-lang/rust-clippy#15008

changelog: [`legacy_numeric_constants`]: fix suggestion when call is
inside parentheses like `(i32::max_value())`
2025-07-11 05:28:23 +00:00
Alejandra González
b5e701efc5
arithmetic_side_effects: don't warn on NonZeroU*.get() - 1 (#15238)
changelog: [`arithmetic_side_effects`]: don't warn on `NonZeroU*.get() -
1`

fixes rust-lang/rust-clippy#15225
2025-07-10 22:57:30 +00:00
Ada Alakbarova
a745e2cae3
fix(arithmetic_side_effects): don't warn on NonZeroU*.get() - 1 2025-07-11 00:40:38 +02:00
llogiq
df5a0ee919
or_fun_call: lint method calls inside map_or first arg (#15074)
<strike>blocked on rust-lang/rust-clippy#15073</strike>

Lint method calls inside `map_or` too, so for this, lint will be showed:
```rust
Some(4).map_or("asd".to_string().len() as i32, f);
```
previously it worked only for:
```rust
Some(4).map_or(slow_fun(), f);
```

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=bfcda42a6af446e69bc883a8b45eb13c

Sorry for multiple `or_fun_call` PRs.

changelog: [`or_fun_call`]: lint method calls inside map_or first arg
2025-07-10 21:27:09 +00:00
llogiq
4dcaa80651
Fix few typos (#15218)
Fix few typos

changelog: none
2025-07-10 21:25:45 +00:00
Alejandra González
e29e3539f0
Cleanup feature_freeze workflow (#15231)
Delete the step and the conditional that checks `changes != '[]'`
(`github.event.pull_request.changed_file`s returns the number of files
changed in the pull request - not the list of changed files)
Escape newlines in the comment body safely
Use Bearer instead of deprecated token

changelog: none
2025-07-10 19:41:23 +00:00
Samuel Tardieu
9457d640b7 refactor legacy_numeric_constants to use multipart suggestion
This removes the need for using source snippets in the replacement.
2025-07-10 12:01:48 -07:00
Samuel Tardieu
37ddd9f32d refactor legacy_numeric_constants to check calls instead of paths
This also moves the lint to be posted on the call.
2025-07-10 12:01:48 -07:00
Dan Johnson
88ee494b38 cleanup legacy_numeric_constants
Removes an unnecessary use of `span_lint_hir_and_then()` where
`span_lint_and_then()` would do.
2025-07-10 12:01:03 -07:00
Samuel Tardieu
ae6416aa86 add extra legacy_numeric_constants test cases 2025-07-10 11:56:54 -07:00
Dan Johnson
e30313cc6b fix legacy_numeric_constants suggestion when call is wrapped in parens 2025-07-10 11:56:23 -07:00
alexey semenyuk
823ee8af4e Cleanup feature_freeze 2025-07-10 23:12:02 +05:00
Philipp Krones
cdbbf3afda
Rustup (#15243)
r? @ghost

changelog: none
2025-07-10 18:06:14 +00:00
Philipp Krones
b9af6670d8
Bump nightly version -> 2025-07-10 2025-07-10 20:01:15 +02:00
Philipp Krones
9e0f749e08
Merge remote-tracking branch 'upstream/master' into rustup 2025-07-10 20:01:08 +02:00
yukang
0a64bfd685 Remove uncessary parens in closure body with unused lint 2025-07-10 09:25:56 +08:00
llogiq
49ca220ca0
Fix multiple problems in #15063 (#15070)
Closes rust-lang/rust-clippy#15063

----

changelog: [`op_ref`]: fix wrongly showed macro definition in
suggestions
changelog: [`needless_bool_assign`]: fix missing curlies when on else if
2025-07-09 21:55:36 +00:00
Timo
012e5f538b
Fix manual_is_variant_and condition generation (#15206)
When comparing `x.map(func) == Some(bool_lit)`, the value of `bool_lit`
was ignored, despite the fact that its value should determine the value
of the proposed expression.

`func` can be either a closure or a path. For the latter, η-expansion
will be used if needed to invert the result of the function call.

changelog: [`manual_is_variant_and`]: fix inverted suggestions that
could lead to code with different semantics

Fixes rust-lang/rust-clippy#15202

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

-
[Beta-nomination](https://github.com/rust-lang/rust-clippy/pull/15206#issuecomment-3034006613)
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-07-09 21:04:18 +00:00
Jason Newcomb
a24fb386b1
Do not remove method call if type is adjusted (#15181)
Propose to replace `x.map_or(false, |y| y == z)` by `x == Some(z)` only
if `x` is not adjusted. Otherwise, the type of `x` in the comparaison
may not be the expected one, as it may be the product of an auto-deref.

changelog: [`unnecessary_map_or`]: do not propose to replace the
`map_or` call by a comparaison if types wouldn't be correct

Fixes rust-lang/rust-clippy#15180
2025-07-09 15:04:39 +00:00
Guillaume Gomez
b1d176235b Reduce clippy lints page size 2025-07-09 15:27:09 +02:00
Aljoscha Meyer
6b6f35ec65 Add uninlined_format_args example: :? formatting 2025-07-09 14:48:59 +02:00
Philipp Krones
dcc790620a
triagebot: enable issue transfer (#14874)
I think it's pretty common for a lint to be proposed for clippy only for
consensus to be it belongs in rustc, and additionally sometimes bugs get
filed here when the fault is actually with rustc.

https://forge.rust-lang.org/triagebot/transfer.html#issue-transfer

changelog: none
2025-07-09 08:35:20 +00:00
Philipp Krones
2ed97eb466
Create summary comment for lintcheck runs (#14816)
Previously https://github.com/rust-lang/triagebot/pull/1985

After a lintcheck run a comment will be created in the PR thread with an
overview of the changes, example here
https://github.com/Alexendoo/rust-clippy/pull/18#issuecomment-2880441316
(plus the normal GHA debugging experience)

It will only comment if there are some changes, if there's already an
existing comment it will be updated for each run

Similar to
https://github.com/rust-lang/team/blob/master/.github/workflows/dry-run.yml

The PR number is supplied by the lintcheck run, so technically someone
could forge it to be annoying and edit the summaries in other threads,
but that is pretty low impact and easy to deal with. There is a
`pull_requests` field on the event but as @Kobzol [pointed out to
me](https://github.com/rust-lang/triagebot/pull/1985#issuecomment-2869157116)
it's not populated for PRs from forks

r? @flip1995

changelog: none
2025-07-09 08:29:50 +00:00
llogiq
d964e55de2
skip exit late lint pass on tests (#15222)
changelog: [`exit`]: When using the `--test` or `--all-targets` flag,
the exit lint should not fail on the main function.

Fixes rust-lang/rust-clippy#13518

With help from @sesgoe
2025-07-08 12:46:36 +00:00
Esteban Küber
5228e28469 Account for const stability in clippy when checking constness 2025-07-07 23:07:32 +00:00
Esteban Küber
d6f7aad00e Make Default const and add some const Default impls
Full list of `impl const Default` types:

- ()
- bool
- char
- Cell
- std::ascii::Char
- usize
- u8
- u16
- u32
- u64
- u128
- i8
- i16
- i32
- i64
- i128
- f16
- f32
- f64
- f128
- std::marker::PhantomData<T>
- Option<T>
- std::iter::Empty<T>
- std::ptr::Alignment
- &[T]
- &mut [T]
- &str
- &mut str
- String
- Vec<T>
2025-07-07 22:09:37 +00:00
Jared Davis
81dd4e61ed use preinterned symbol
fixes https://github.com/rust-lang/rust-clippy/actions/runs/16126736130/job/45505355614?pr=15222#logs
2025-07-07 16:17:19 -04:00
Jared Davis
9580d61dc5 remove no longer used import 2025-07-07 16:05:03 -04:00
Jared Davis
1c7fb0ff91 do not completely suppress warning with test code 2025-07-07 15:59:38 -04:00
Jared Davis
52aa3839f2
Merge pull request #1 from sesgoe/ses/update-clippy-fix-13518
fix: check against 'main' function name instead of entrypoint function
2025-07-07 15:56:30 -04:00
Ses Goe
5853e6fa7e
chore: add tests to check against the --test compile flag 2025-07-07 15:11:30 -04:00
Ses Goe
c000a0136c
fix: check against 'main' function name instead of entrypoint function
update docs to be a bit more clear
2025-07-07 15:11:30 -04:00
bors
9ac09016b0 Auto merge of #143182 - xdoardo:more-addrspace, r=workingjubilee
Allow custom default address spaces and parse `p-` specifications in the datalayout string

Some targets, such as CHERI, use as default an address space different from the "normal" default address space `0` (in the case of CHERI, [200 is used](https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-877.pdf)). Currently, `rustc` does not allow to specify custom address spaces and does not take into consideration [`p-` specifications in the datalayout string](https://llvm.org/docs/LangRef.html#langref-datalayout).

This patch tries to mitigate these problems by allowing targets to define a custom default address space (while keeping the default value to address space `0`) and adding the code to parse the `p-` specifications in `rustc_abi`. The main changes are that `TargetDataLayout` now uses functions to refer to pointer-related informations, instead of having specific fields for the size and alignment of pointers in the default address space; furthermore, the two `pointer_size` and `pointer_align` fields in `TargetDataLayout` are replaced with an `FxHashMap` that holds info for all the possible address spaces, as parsed by the `p-` specifications.

The potential performance drawbacks of not having ad-hoc fields for the default address space will be tested in this PR's CI run.

r? workingjubilee
2025-07-07 17:28:14 +00:00
Jared Davis
1f36d4df93 run cargo dev fmt on changes 2025-07-07 11:08:45 -04:00