Commit graph

23056 commits

Author SHA1 Message Date
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
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
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
Jared Davis
2b93d2cca6 skip exit late lint pass on tests
When using the `--test` or `--all-targets` flag, the exit lint should not fail on the main function.
2025-07-07 10:38:29 -04:00
Edoardo Marangoni
f4e2b5c7f5 compiler: Parse p- specs in datalayout string, allow definition of custom default data address space 2025-07-07 09:04:53 +02:00
Alexey Semenyuk
a743efc0e5 Fix few typos 2025-07-07 11:50:03 +05:00
Jacob Pratt
c6be76206f Rollup merge of #143544 - workingjubilee:rename-bare-fn, r=fmease
compiler: rename BareFn to FnPtr

At some point "BareFn" was the chosen name for a "bare" function, without the niceties of `~fn`, `&fn`, or a few other ways of writing a function type. However, at some point the syntax for a "bare function" and any other function diverged even more. We started calling them what they are: function pointers, denoted by their own syntax.

However, we never changed the *internal* name for these, as this divergence was very gradual. Personally, I have repeatedly searched for "FnPtr" and gotten confused until I find the name is BareFn, only to forget this until the next time, since I don't routinely interact with the higher-level AST and HIR. But even tools that interact with these internal types only touch on them in a few places, making a migration easy enough. Let's use a more intuitive and obvious name, as this 12+ year old name has little to do with current Rust.
2025-07-07 03:26:09 +02:00
Jubilee Young
491c8feaab clippy: migrate BareFn -> FnPtr 2025-07-06 15:03:14 -07:00
Samuel Tardieu
d8ba94b0ae
Fix manual_is_variant_and condition generation
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.
2025-07-06 23:36:45 +02:00
llogiq
c943f4c0e9
or_fun_call: also lint and method for Option/Result (#15073)
<strike>build on top of rust-lang/rust-clippy#15071</strike>

This also adds ability to lint Option/Result::and method. Yes, this is
not `or` method, but uses the same eager/lazy linting logic. Should i
update lint description to list all checked structs/methods?

changelog: [`or_fun_call`]: lint Option/Result::and
2025-07-06 15:31:13 +00:00
llogiq
cc7b2f57e0
Properly check that an expression might be the one returned (#15115)
The `TyCtxt::hir_get_fn_id_for_return_block()` function was too broad,
as it will return positively even when given part of an expression that
can be used as a return value. A new
`potential_return_of_enclosing_body()` utility function has been made to
represent the fact that an expression might be directly returned from
its enclosing body.

changelog: [`return_and_then`]: prevent false positives in case of a
partially used expression

Fixes rust-lang/rust-clippy#15111
Fixes rust-lang/rust-clippy#14927

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

-
[Beta-nomination](https://github.com/rust-lang/rust-clippy/pull/15115#issuecomment-2996222332)
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-06 15:24:46 +00:00
llogiq
5c51a1d9d3
Handle potentially-shadowing bindings in manual_let_else (#15118)
This commit also adds more test cases, which already worked but were
mentioned in the issue.

Fixes rust-lang/rust-clippy#9939

changelog: [`manual_let_else`]: correctly handle binding subpattern with
unused name
2025-07-06 15:22:46 +00:00
llogiq
412def25d5
fix: Improve floating point lint to handle ambiguous type (#15133)
Fixes: rust-lang/rust-clippy#14897, rust-lang/rust-clippy#10015

This is not a perfect solution, but it fixes the issue. Happy to discuss
further with the clippy team.

This PR refines check_mul_add to avoid false positives on ambiguous
float types (e.g., f32 vs f64). It improves type detection and ensures
mul_add is only suggested when the type is clear.

Changes:
- Improved detection of ambiguous float types
- Refined mul_add suggestion logic
- Added tests for ambiguous cases
## Example

Before this change, expressions like:
```rust
let x = 1.0; // ambiguous type
let _ = x * 2.0 + 0.5; // could incorrectly suggest mul_add
```

----

changelog: [`suboptimal_flops`]: improve handling of ambiguous float
types in mul_add suggestions
2025-07-06 15:18:52 +00:00
llogiq
60d57851ad
Don't remove explicit cast to trait object pointer (#15145)
Fixes rust-lang/rust-clippy#15141

----

changelog: [`borrow_as_ptr`]: do not remove cast to trait object pointer
2025-07-06 15:15:35 +00:00
llogiq
cd679d6b84
FIX: NegMultiply should preserve parenthesis when method is called (#15179)
Hi,

I noticed that the lint
[neg_multiply](https://rust-lang.github.io/rust-clippy/master/index.html#neg_multiply)
generates bad code when we call a method on the expression.
Consider `((a.delta - 0.5).abs() * -1.0).total_cmp(&1.0)`. Currently
this would be changed by clippy to `-(a.delta - 0.5).abs()
.total_cmp(&1.0)` - which does not compile because we are trying to
negate an ordering enum - but what we really want is `(-(a.delta -
0.5).abs()).total_cmp(&1.0)`.

This PR fixes this.

changelog: [`neg_multiply`] does not remove parenthesis anymore if a
method is being called on the affected expression

NOTE: This is the first time I am contributing to clippy or the rust
repo in general. So I am not sure whether my approach to fixing this
issue is goo, if there are better solutions or if I missed something.

Thanks & hope you have a good day,
Dario
2025-07-06 15:14:39 +00:00
llogiq
2713c509de
fix: redundant_closure_call lint for closures with block (#15144)
Fixes rust-lang/rust-clippy#9583

When a closure with no parameters is called immediately after being
defined, clippy can now suggest replacing the entire expression with
just the closure's body.

----

changelog: [`redundant_closure_call`]: add fixes for closures with block
2025-07-06 15:10:25 +00:00
dswij
8d688c6f60
Do not remove as if it changes the type (#15182)
While `expr as T` can be removed as a statement if `expr` has no
side-effect, the `as T` part alone cannot be removed if the type of
`expr` would be ambiguous without the cast.

changelog: [`unnecessary_operation`]: do not remove casts if they are
useful to type the expression

Fixes rust-lang/rust-clippy#15173
2025-07-06 09:58:44 +00:00
Jonathan Brouwer
8aad0e6ad9 Rewrite empty attribute lint
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-06 09:51:35 +02:00
Samuel Tardieu
7c39d378e5
Propagate accept-comment-above-attributes to statements (#15213)
Turns out that things like `#[attr]return unsafe { func(); }` didn't
work because we weren't checking above attributes on statements, only on
blocks!

fixes https://github.com/rust-lang/rust-clippy/issues/13189

Useful for Rust-For-Linux

changelog:[`undocumented_unsafe_blocks`]: Make sure to propagate
`accept-comment-above-attributes` to **all** statements.
2025-07-06 07:28:40 +00:00
Alejandra González
b28049d92b
Not on vacation, again! (#15214)
As I said in my on-vacation PR (a little bit late) I'm getting
reincorporated into the review queue. Something that I'd like to do is
implement the reviewer capacity system into Clippy, but seems that it's
not supported yet. https://github.com/rust-lang/triagebot/issues/2007

r? @ghost
changelog:none
2025-07-06 00:35:46 +00:00
blyxyas
b49064e9df Not on vacation, again! 2025-07-06 02:24:22 +02:00
blyxyas
e0e881f873 Propagate accept-comment-above-attributes to statements
Turns out that things like `#[attr]return unsafe { func(); }` didn't work
because we weren't checking above attributes on statements, only on blocks!
2025-07-06 02:23:50 +02:00
Matthias Krüger
daf9adbd89 Rollup merge of #143372 - cjgillot:bare-glob-map, r=petrochenkov
Remove names_imported_by_glob_use query.

Based on https://github.com/rust-lang/rust/pull/143247
r? ``@ghost`` for perf
2025-07-05 00:12:09 +02:00
Jonathan Brouwer
9c9ee34807 Port #[non_exhaustive] to the new attribute parsing infrastructure 2025-07-04 20:30:42 +02:00
Matthias Krüger
2e9b29406a Rollup merge of #143286 - Muscraft:track-diagnostics-note, r=WaffleLapkin
Make -Ztrack-diagnostics emit like a note

[#t-compiler/diagnostics > Rendering -Ztrack-diagnostics like a note](https://rust-lang.zulipchat.com/#narrow/channel/147480-t-compiler.2Fdiagnostics/topic/Rendering.20-Ztrack-diagnostics.20like.20a.20note/with/526608647)

As discussed on the Zulip thread above, I want to make `-Ztrack-diagnostics` emit like a `note`. This is because I find its current output jarring, and the fact that it gets rendered completely left-aligned, [even in the middle of a snippet](86e05cd300/tests/ui/track-diagnostics/track6.stderr), seems like something that should be changed. Turning it into a `note` seems like the best choice, as it would align it with the rest of the output, and `note` is already used for somewhat similar things, like seeing why a lint was fired.

---

Note: turning `-Ztrack-diagnostics` into a `note` will also make `annotate-snippets` API a bit cleaner
2025-07-04 16:22:35 +02:00
Camille GILLOT
b4a0cd9995 Remove names_imported_by_glob_use query. 2025-07-04 14:01:09 +00:00
Samuel Tardieu
60a978d2e9
Simplify clippy lints page further (#15208)
Follow-up of rust-lang/rust-clippy#15140.

This time, I removed some unneeded `<span>` wrappings and some unneeded
CSS classes. As usual, no changes in the UI.

Before this PR: 1876091
With this PR: 1751097
Reduction: -6.6%

r? @samueltardieu

changelog: Reduce page size and number of DOM elements on clippy lints
page
2025-07-04 12:54:02 +00:00
Guillaume Gomez
dd1a52f8b6 Simplify clippy lints page further 2025-07-04 13:57:38 +02:00
Samuel Tardieu
da2f0ad53c
Reduce page size and number of DOM elements on clippy lints page (#15140)
This is the first pass of "reducing the size of the clippy lints page"
I'm currently going through. This first one reduces the size page but
mostly reduces the number of DOM elements.

Page size change:
* Before this PR: 1938957
* With this PR: 1876167
* Reduction: -3.2%

r? @Alexendoo

changelog: Reduce page size and number of DOM elements on clippy lints
page
2025-07-04 10:09:34 +00:00
Samuel Tardieu
876e05d307
bump termize (#15207)
Bump termize to remove one more dep with winapi
(https://github.com/JohnTitor/termize/releases/tag/v0.2.0)

changelog: none
2025-07-04 09:19:03 +00:00