Commit Graph

2639 Commits

Author SHA1 Message Date
Samuel Tardieu ac86fd103d Add BinaryHeap::pop_if() to manual_pop_if (#16734)
Detects manual implementations of the newly implemented
[`BinaryHeap::pop_if()`](https://github.com/rust-lang/rust/issues/151828)
in `manual_pop_if`.

I wasn't sure about how best to handle checking for the nightly feature.
Could we let people compiling with nightly know that the feature is
available even if they don't have it enabled?

changelog: [`manual_pop_if`]: detect manual implementations of
`BinaryHeap::pop_if()`
2026-03-22 15:49:42 +00:00
Max Heller 9bf6fafdbf Add BinaryHeap::pop_if() to manual_pop_if 2026-03-22 11:22:16 -04:00
Philipp Krones e191c9429e Bump nightly version -> 2026-03-21 2026-03-21 13:40:35 +01:00
Philipp Krones 1e283ba0ce Merge remote-tracking branch 'upstream/master' into rustup 2026-03-21 13:40:20 +01:00
Teodoro Freund c455f7ce52 Refactors to unnecessary_{option,result}_map_or_else:
- When checking if a function is an identity function, try to use existing functionalities.
- Some cases are no longer supported, but they were buggy
2026-03-15 09:20:27 +00:00
linshuy2 e9d76c811a fix: match_same_arms FP with associated consts 2026-03-10 17:13:35 +00:00
Guillaume Gomez ab867a90e1 Remove usage of TyCtxt::node_span_lint in clippy 2026-03-09 22:50:10 +01:00
Alejandra González bc2a571167 Do not materialize snippets when it is not needed to (#16666)
It is not necessary to materialize snippets into `String` objects just
to check if they contain comments for example.

changelog: none

r? @blyxyas
(for perf measurements)
2026-03-09 10:58:41 +00:00
Samuel Tardieu 201759058d Fix ICE when using the min_generic_const_args incomplete feature 2026-03-08 11:53:45 +01:00
Samuel Tardieu 1ecc9d7e04 Fix ICE in match_same_arms
The wrong `TypeckResults` was used in the fallback equality function
passed by the `match_same_arms` and `filter_map` lints. Previously,
those fallback functions had no way of using the proper `TypeckResults`.
Those (one per expression being compared) are now passed to the
registered fallback function.
2026-03-07 20:13:56 +01:00
Josh Stone c260a1fb50 Update cfg(bootstrap) 2026-03-07 10:42:02 -08:00
bors 1fc8c3bd9a Auto merge of #153507 - JonathanBrouwer:rollup-ki59UTE, r=JonathanBrouwer
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#153466 (`rust-analyzer` subtree update)
 - rust-lang/rust#151280 (Fix incorrect trailing comma suggested in no_accessible_fields)
 - rust-lang/rust#152593 (Box in `ValTreeKind::Branch(Box<[I::Const]>)` changed to `List`)
 - rust-lang/rust#153174 (std: add wasm64 to sync::Once and thread_parking atomics cfg guards)
 - rust-lang/rust#153485 (libcore float tests: replace macro shadowing by const-compatible macro)
 - rust-lang/rust#153495 (Fix ICE in `offset_of!` error recovery)
 - rust-lang/rust#152040 (Do not emit ConstEvaluatable goals if type-const)
 - rust-lang/rust#152741 (Suppress invalid suggestions in destructuring assignment)
 - rust-lang/rust#153189 (refactor: move `check_align` to `parse_alignment`)
 - rust-lang/rust#153230 (Roll rustfmt reviewers for in-tree rustfmt)
 - rust-lang/rust#153445 (Consider try blocks as block-like for overflowed expr)
 - rust-lang/rust#153452 (Cleanup unused diagnostic emission methods)
 - rust-lang/rust#153476 (bootstrap.py: fix typo "parallle")
 - rust-lang/rust#153483 (Preserve parentheses around `Fn` trait bounds in pretty printer)
2026-03-06 19:09:12 +00:00
Guillaume Gomez ae25efb4ac Fix panic by setting the span before it is actually needed 2026-03-06 16:38:53 +01:00
Guillaume Gomez dbb159a432 Remove usage of LintContext::span_lint in clippy 2026-03-05 23:53:53 +01:00
Samuel Tardieu b5f63104b2 Do not materialize snippets when it is not needed to
It is not necessary to materialize snippets into `String` objects just
to check if they contain comments for example.
2026-03-05 23:19:49 +01:00
Paolo Borelli 25171f23ae add manual_pop_if lint
Add a lint to detect when the recently added Vec::pop_if,
VecDeque::pop_front_if, and VecDeque::pop_back_if are manually
implemented.

changelog: add [`manual_pop_if`] lint
2026-03-05 19:06:40 +01:00
Philipp Krones b4d2445432 Merge commit 'e645f93552c3926a0bb481a777df120b7bce986f' 2026-03-05 17:18:20 +01:00
Philipp Krones dfcb117050 Bump Clippy version -> 0.1.96 2026-03-05 16:59:28 +01:00
Philipp Krones 02aece114b Bump nightly version -> 2026-03-05 2026-03-05 16:59:20 +01:00
Philipp Krones eb386eca43 Merge remote-tracking branch 'upstream/master' into rustup 2026-03-05 16:59:08 +01:00
Samuel Tardieu 4ff2a24441 Fix ICE in swap_binop()
Make `swap_binop()` a method of `HirEqInterExpr`, and use the proper
typeck to check the type of an expression.
2026-03-03 23:24:00 +01:00
Jonathan Brouwer a2b29fbb12 Rollup merge of #152943 - CoCo-Japan-pan:impl-restriction-parse, r=Urgau,jhpratt
Parse `impl` restrictions

This PR implements the parsing logic for `impl` restrictions (e.g., `pub impl(crate) trait Foo {}`) as proposed in [RFC 3323](https://rust-lang.github.io/rfcs/3323-restrictions.html).
As the first step of the RFC implementation, this PR focuses strictly on the parsing phase. The new syntax is guarded by the `#![feature(impl_restriction)]` feature gate.
This implementation basically follows the pattern used in rust-lang/rust#141754.

r? @jhpratt
2026-03-03 13:08:43 +01:00
dswij e492d02285 fix: handle core panics in all format lints (#16597)
Fixes rust-lang/rust-clippy#16411

`core::panic` was missing in the formatting arg lints

changelog: fix all format-related lints to handle `core::panic!` macro
2026-03-01 14:58:48 +00:00
bors 67e87a4614 Auto merge of #153050 - JayanAXHF:refactor/change-is-type-const, r=BoxyUwU
refactor(mgca): Change `DefKind::Const` and `DefKind::AssocConst` to have a `is_type_const` flag



Addresses rust-lang/rust#152940 

- Changed `DefKind::Const` and `DefKind::AssocConst` to have a `is_type_const` flag.
- changed `is_type_const` query to check for this flag
- removed `is_rhs_type_const` query

r? @BoxyUwU
2026-02-28 18:27:06 +00:00
JayanAXHF 900bfa15eb refactor(mgca): Change DefKind::Const and DefKind::AssocConst to have a is_type_const flag
* refactor: add `is_type_const` flag to `DefKind::Const` and `AssocConst`
* refactor(cleanup) remove the `rhs_is_type_const` query
* style: fix formatting
* refactor: refactor stuff in librustdoc for new Const and AssocConst
* refactor: refactor clippy for the changes
* chore: formatting
* fix: fix test
* fix: fix suggestions
* Update context.rs

Co-authored-by: Boxy <rust@boxyuwu.dev>
* changed AssocKind::Const to store data about being a type const
2026-02-28 17:27:46 +00:00
Jonathan Brouwer ddb5607de0 Rollup merge of #152730 - BennoLossin:field-projections-lang-item, r=oli-obk
add field representing types

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152730)*

> [!NOTE]
> This is a rewrite of #146307 by using a lang item instead of a custom `TyKind`. We still need a `hir::TyKind::FieldOf` variant, because resolving the field name cannot be done before HIR construction. The advantage of doing it this way is that we don't need to make any changes to types after HIR (including symbol mangling). At the very beginning of this feature implementation, I tried to do it using a lang item, but then quickly abandoned the approach, because at that time I was still intending to support nested fields.

Here is a [range-diff](https://triagebot.infra.rust-lang.org/gh-range-diff/rust-lang/rust/605f49b27444a738ea4032cb77e3bdc4eb811bab..d15f5052095b3549111854a2555dd7026b0a729e/605f49b27444a738ea4032cb77e3bdc4eb811bab..f5f42d1e03495dbaa23671c46b15fccddeb3492f) between the two PRs

---

# Add Field Representing Types (FRTs)

This PR implements the first step of the field projection lang experiment (Tracking Issue: rust-lang/rust#145383). Field representing types (FRTs) are a new kind of type. They can be named through the use of the `field_of!` macro with the first argument being the type and the second the name of the field (or variant and field in the case of an enum). No nested fields are supported.

FRTs natively implement the `Field` trait that's also added in this PR. It exposes information about the field such as the type of the field, the type of the base (i.e. the type that contains the field) and the offset within that base type. Only fields of non-packed structs are supported, fields of enums an unions have unique types for each field, but those do not implement the `Field` trait.

This PR was created in collaboration with @dingxiangfei2009, it wouldn't have been possible without him, so huge thanks for mentoring me!

I updated my library solution for field projections to use the FRTs from `core` instead of creating my own using the hash of the name of the field. See the [Rust-for-Linux/field-projection `lang-experiment` branch](https://github.com/Rust-for-Linux/field-projection/tree/lang-experiment).

## API added to `core::field`

```rust
pub unsafe trait Field {
    type Base;

    type Type;

    const OFFSET: usize;
}

pub macro field_of($Container:ty, $($fields:expr)+ $(,)?);
```

Along with a perma-unstable type that the compiler uses in the expansion of the macro:

```rust
#[unstable(feature = "field_representing_type_raw", issue = "none")]
pub struct FieldRepresentingType<T: ?Sized, const VARIANT: u32, const FIELD: u32> {
    _phantom: PhantomData<T>,
}
```

## Explanation of Field Representing Types (FRTs)

FRTs are used for compile-time & trait-level reflection for fields of structs & tuples. Each struct & tuple has a unique compiler-generated type nameable through the `field_of!` macro. This type natively contains information about the field such as the outermost container, type of the field and its offset. Users may implement additional traits on these types in order to record custom information (for example a crate may define a [`PinnableField` trait](https://github.com/Rust-for-Linux/field-projection/blob/lang-experiment/src/marker.rs#L9-L23) that records whether the field is structurally pinned).

They are the foundation of field projections, a general operation that's generic over the fields of a struct. This genericism needs to be expressible in the trait system. FRTs make this possible, since an operation generic over fields can just be a function with a generic parameter `F: Field`.

> [!NOTE]
> The approach of field projections has changed considerably since this PR was opened. In the end we might not need FRTs, so this API is highly experimental.

FRTs should act as though they were defined as `struct MyStruct_my_field<StructGenerics>;` next to the struct. So it should be local to the crate defining the struct so that one can implement any trait for the FRT from that crate. The `Field` traits should be implemented by the compiler & populated with correct information (`unsafe` code needs to be able to rely on them being correct).

## TODOs

There are some `FIXME(FRTs)` scattered around the code:
- Diagnostics for `field_of!` can be improved
  - `tests/ui/field_representing_types/nonexistent.rs`
  - `tests/ui/field_representing_types/non-struct.rs`
  - `tests/ui/field_representing_types/offset.rs`
  - `tests/ui/field_representing_types/not-field-if-packed.rs`
  - `tests/ui/field_representing_types/invalid.rs`
- Simple type alias already seem to work, but might need some extra work in `compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs`

r? @oli-obk
2026-02-28 12:52:52 +01:00
CoCo-Japan-pan 3ebcade8ff Add eq_impl_restriction to clippy_utils 2026-02-28 13:59:37 +09:00
Benno Lossin 05f6bc9041 add field representing types 2026-02-27 15:54:20 +01:00
Ada Alakbarova c91298aaa0 refactor(clippy_utils::mir::visit_local_usage): use const generics
encodes the direct relationship between the lengths of `locals` and the
returned list, making the code more type-safe
2026-02-25 22:07:46 +01:00
Ada Alakbarova c311ea2c1c refactor: simplify clippy_utils::mir::is_local_assignment using Body::stmt_at 2026-02-25 16:26:32 +01:00
Philipp Krones 088022c7d4 Merge commit 'df995ede1b3e61f0e87081d9548e6cd2a3ec9095' into clippy-subtree-update 2026-02-24 12:00:51 +01:00
Jason Newcomb afece5ddf1 Do not suggest removing reborrow of a captured upvar (#16622)
changelog: [`borrow_deref_ref`]: do not suggest removing an explicit
reborrow when it targets an upvar captured by a closure

Fixes rust-lang/rust-clippy#16556

r? Jarcho
2026-02-23 15:32:13 +00:00
Samuel Tardieu 12abbc0676 Do not suggest removing reborrow of a captured upvar 2026-02-23 15:55:05 +01:00
Jason Newcomb 0776e01ff4 fix(needless_maybe_sized): don't lint in proc-macro-generated code (#15629)
Fixes https://github.com/rust-lang/rust-clippy/issues/13360

changelog: [`needless_maybe_sized`]: don't lint in proc-macro-generated
code
2026-02-23 01:09:15 +00:00
llogiq 9a1cabf77e Fix panic/assert message detection in edition 2015/2018 (#16473)
changelog: fix FP: [`assertions_on_result_states`],
[`missing_assert_message`] on edition 2015 and 2018

Fixes https://github.com/rust-lang/rust-clippy/issues/13490
2026-02-22 14:20:10 +00:00
llogiq 6211fa92e8 The path from a type to itself is Self (#16362)
changelog: [`redundant_closure_for_method_calls`]: fix ICE when
computing the path from a type to itself

Fixes rust-lang/rust-clippy#16360
2026-02-22 14:18:59 +00:00
llogiq ad08bd62dd Enhance collapsible_match to cover if-elses (#16560)
Closes rust-lang/rust-clippy#16558

changelog: [`collapsible_match`] extend to cover if-elses
2026-02-22 13:07:10 +00:00
Nicholas Nethercote 180e4a7155 Remove impl IntoQueryParam<P> for &'a P.
`IntoQueryParam` is a trait that lets query callers be a bit sloppy with
the passed-in key.
- Types similar to `DefId` will be auto-converted to `DefId`. Likewise
  for `LocalDefId`.
- Reference types will be auto-derefed.

The auto-conversion is genuinely useful; the auto-derefing much less so.
In practice it's only used for passing `&DefId` to queries that accept
`DefId`, which is an anti-pattern because `DefId` is marked with
`#[rustc_pass_by_value]`.

This commit removes the auto-deref impl and makes the necessary sigil
adjustments. (I generally avoid using `*` to deref manually at call
sites, preferring to deref via `&` in patterns or via `*` in match
expressions. Mostly because that way a single deref often covers
multiple call sites.)
2026-02-22 17:58:54 +11:00
Samuel Tardieu d074e48dcb feat(clone_on_ref_ptr): don't add a & to the receiver if it's a reference (#15742)
Fixes https://github.com/rust-lang/rust-clippy/issues/15741

changelog: [clone_on_ref_ptr]: don't add a `&` to the receiver if it's a
reference
2026-02-21 22:47:41 +00:00
llogiq 94337ce1d8 DRY: make all span_lint_* use span_lint{_hir,}_and_then (#16587)
This removes code duplication. Also, this limits the number of places to
update when rustc lint code interface is modified to two places.

changelog: none
2026-02-21 22:21:38 +00:00
Samuel Tardieu 2f6e9e4d55 Add Sugg::strip_paren() 2026-02-21 22:35:51 +01:00
Samuel Tardieu 296fe3a74a Make unchecked_time_subtraction to better handle Duration literals (#16528)
Closes rust-lang/rust-clippy#16499

changelog: [`unchecked_time_subtraction`] extend to better handle
`Duration` literals
2026-02-21 18:14:14 +00:00
linshuy2 ef1ee71666 Enhance unchecked_time_subtraction to better handle Duration literals 2026-02-21 18:04:19 +00:00
Jason Newcomb 349e809e6f Handle Result<T, !> and ControlFlow<!, T> as T wrt #[must_use] (#16353)
There is a proposal to change the behaviour of rustc's `must_use` lint
to consider `Result<T, U>` and `ControlFlow<U, T>` as `T` when `U` is
uninhabited. See <https://github.com/rust-lang/rust/pull/148214>.

This might make the user adding extra `#[must_use]` attributes to
functions returning `Result<T, !>` or `ControlFlow<!, T>`, which would
trigger the `double_must_use` lint in Clippy without the current change.

changelog: [`double_muse_use`, `drop_non_drop`,
`let_underscore_must_use`]: consider `Result<T, U>` and `ControlFlow<U,
T>` as `T` wrt the `#[must_use]` attribute if `U` is uninhabited.
2026-02-21 17:57:22 +00:00
Samuel Tardieu 5137bb3ceb Handle Result<T, !> and ControlFlow<!, T> as T wrt #[must_use]
There is a proposal to change the behaviour of rustc's `must_use` lint
to consider `Result<T, U>` and `ControlFlow<U, T>` as `T` when `U` is
uninhabited. See <https://github.com/rust-lang/rust/pull/148214>.

This might make the user adding extra `#[must_use]` attributes to
functions returning `Result<T, !>` or `ControlFlow<!, T>`, which would
trigger the `double_must_use` lint in Clippy without the current change.
2026-02-21 15:48:33 +01:00
bors bd73fa0d17 Auto merge of #152624 - camsteffen:symbols-audit, r=petrochenkov
Audit Symbols

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152624)*

Remove unused symbols and hoist some symbols to Clippy.
2026-02-21 06:44:20 +00:00
Jason Newcomb 70647514ff Add new disallowed_fields lint (#16218)
Fixes https://github.com/rust-lang/rust-clippy/issues/9278.

This is something that we need for `cg_gcc` (cc @antoyo). It's almost
the same as https://github.com/rust-lang/rust-clippy/pull/6674 (which I
used as base).

changelog: Add new `disallowed_fields` lint

r? @samueltardieu
2026-02-20 13:19:36 +00:00
Jana Dönszelmann 87b3f55b16 fix src/tools 2026-02-20 10:35:52 +01:00
Yuri Astrakhan a81565667c fix: handle core panics in all format lints
`core::panic` was missing in the formatting arg lints
2026-02-20 04:00:45 -05:00
Cameron Steffen 17a6d61dc9 Audit Symbols 2026-02-19 19:27:33 -06:00