2273 Commits

Author SHA1 Message Date
Ada Alakbarova
04606e27dc
introduce path_to_local_with_projections
combine two similar arms

use in `eager_transmute`

use in `double_ended_iterator_last`

use different numbers in the new test case to avoid possible confusion

move the other "unfixable" case as well; it shouldn't lint anyway, so
having it in the main test file is fine
2025-08-09 20:27:30 +02:00
Philipp Krones
d5f9f7576c
Bump Clippy version -> 0.1.91 2025-08-07 16:48:16 +02:00
Philipp Krones
2893dc8019
Bump nightly version -> 2025-08-07 2025-08-07 16:47:57 +02:00
Philipp Krones
f2b7e9ff52
Merge remote-tracking branch 'upstream/master' into rustup 2025-08-07 16:47:42 +02:00
Ada Alakbarova
2d8d45e201
use ? for brevity 2025-08-03 17:16:28 +02:00
Ada Alakbarova
3b907eada7
use parens for clearer formatting
the first and second lines now each represent one approach to getting a
`source`
2025-08-03 17:16:28 +02:00
Timo
ffcd12946e
{flat_,}map_identity: recognize (tuple) struct de- and restructuring (#15261)
Follow-up of rust-lang/rust-clippy#15229, as described in
https://github.com/rust-lang/rust-clippy/pull/15229#issuecomment-3050279790
-- it turned out to be not that difficult after all!

changelog: [`map_identity`,`flat_map_identity`]: also recognize (tuple)
struct de- and resctructuring

r? @y21
2025-08-02 11:37:12 +00:00
dswij
94b703588e
Do not specialize for if_chain any longer (#15362)
Now that `if let` chains have been introduced, the `if_chain` external
crate is no longer necessary. Dropping special support for it also
alleviates the need to keep the crate as a dependency in tests.

This is a cleanup PR.

changelog: none
2025-08-01 15:52:00 +00:00
Ada Alakbarova
eea4d6dc3c
{flat_,}map_identity: recognize (tuple) struct de- and restructuring
base check

same fields different struct

reordered fields

different paths to the same struct

same for tuple structs

style: use `zip`-the-function all over the place

makes the code a bit more concise by removing the need for explicit
`.iter()`

style: move precondition checking to the match guard

the match arms above put the "sanity" checks in the guard, and call only
`check_pat` in the body. With this commit, the (tuple) struct cases
follow that convention as well. Well, almost -- I think the ident check
belongs to the second category of checks, so I put it in the body as
well

misc: use `None` in the pattern directly

this'll probably be marginally faster thanks to the equality check being
now structural

move the tests to the right file
2025-08-01 11:24:44 +02:00
Jana Dönszelmann
0f810ac2c3 Rollup merge of #144726 - jdonszelmann:move-attr-data-structures, r=lcnr
merge rustc_attr_data_structures into rustc_hir

this move was discussed on zulip: [#t-compiler > attribute parsing rework @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/attribute.20parsing.20rework/near/528530091)

Many PRs in the attribute rework depend on this move.
2025-07-31 17:19:40 +02:00
Jana Dönszelmann
d6a9497ccc Rollup merge of #144712 - nnethercote:dedup-num-types, r=fmease
Deduplicate `IntTy`/`UintTy`/`FloatTy`.

There are identical definitions in `rustc_type_ir` and `rustc_ast`. This commit removes them and places a single definition in `rustc_ast_ir`. This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but means a bunch of silly conversion functions can be removed.

r? `@fmease`
2025-07-31 17:19:39 +02:00
Jana Dönszelmann
05e3a7a499 remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
Nicholas Nethercote
618a90d1b0 Deduplicate IntTy/UintTy/FloatTy.
There are identical definitions in `rustc_type_ir` and `rustc_ast`. This
commit removes them and places a single definition in `rustc_ast_ir`.
This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but
means a bunch of silly conversion functions can be removed.

The one annoying wrinkle is that the old version had differences in
their `Debug` impls, e.g. one printed `u32` while the other printed
`U32`. Some compiler error messages rely on the former (yuk), and some
clippy output depends on the latter. So the commit also changes clippy
to not rely on `Debug` and just implement what it needs itself.
2025-07-31 19:56:11 +10:00
Nicholas Nethercote
c78d589243 Remove TyCtxt::get_attrs_unchecked.
It's identical to `TyCtxt::get_all_attrs` except it takes `DefId`
instead of `impl Into<DefIf>`.
2025-07-31 15:17:20 +10:00
Jason Newcomb
3c54672d1a
Optimize some usages of !! and -- in suggestions (#15366)
When an expression is made of a `!` or `-` unary operator which does not
change the type of the expression, use a new variant in `Sugg` to denote
it. This allows replacing an extra application of the same operator by
the removal of the original operator instead.

Some suggestions will now be shown as `x` instead of `!!x`. Right now,
no suggestion seems to produce `--x`.

changelog: none
2025-07-30 17:35:10 +00:00
Alejandra González
445d41909e
Fix iter_on_single_items FP on function pointers and let stmts (#15013)
Closes rust-lang/rust-clippy#14981

changelog: [`iter_on_single_items`] fix FP on function pointers and let
stmts
2025-07-30 16:42:12 +00:00
Samuel Tardieu
642bec7617
Optimize some usages of double unary operators in suggestions
When an expression is made of a `!` or `-` unary operator which does not
change the type of the expression, use a new variant in `Sugg` to denote
it. This allows replacing an extra application of the same operator by
the removal of the original operator instead.

Also, when adding a unary operator to a suggestion, do not enclose the
operator argument in parentheses if it starts with a unary operator
itself unless it is a binary operation (including `as`), because in this
case parentheses are required to not bind the lhs only.

Some suggestions will now be shown as `x` instead of `!!x`. Right now,
no suggestion seems to produce `--x`.
2025-07-30 00:34:26 +02:00
Alejandra González
b7cc5c45bd
Fix search_is_some suggests wrongly inside macro (#15135)
Closes rust-lang/rust-clippy#15102

changelog: [`search_is_some`] fix wrong suggestions inside macro
2025-07-29 16:31:55 +00:00
Samuel Tardieu
4f1044a5a6
Do not specialize for if_chain any longer
Now that `if let` chains have been introduced, the `if_chain` external
crate is no longer necessary. Dropping special support for it also
alleviates the need to keep the crate as a dependency in tests.
2025-07-28 17:26:38 +02:00
Cameron Steffen
86ff11e729 Rename impl_of_method -> impl_of_assoc 2025-07-28 09:54:53 -05:00
Cameron Steffen
b0740198ae Rename trait_of_item -> trait_of_assoc 2025-07-28 09:53:50 -05:00
dswij
f4f579f4ac
Fix match_single_binding wrongly handles scope (#15060)
Closes rust-lang/rust-clippy#15018
Closes rust-lang/rust-clippy#15269

Continuation of rust-lang/rust-clippy#15017

changelog: [`match_single_binding`] fix wrong handling of scope
2025-07-28 12:10:42 +00:00
Philipp Krones
5c7418b38a Merge commit '1db89a1b1ca87f24bf22d0bad21d14b2d81b3e99' into clippy-subtree-update 2025-07-25 15:54:22 +02:00
Philipp Krones
31baffd6ee
Bump nightly version -> 2025-07-25 2025-07-25 15:08:44 +02:00
Philipp Krones
c98e60a56e
Merge remote-tracking branch 'upstream/master' into rustup 2025-07-25 15:04:01 +02:00
Alejandra González
98205e60cc
Fix if_then_some_else_none FP when require type coercion (#15267)
Closes rust-lang/rust-clippy#15257

changelog: [`if_then_some_else_none`] fix FP when require type coercion
2025-07-24 23:50:14 +00:00
Alex Macleod
b2c8c02a02
Fix unused_async FP on function with todo! (#15308)
Closes rust-lang/rust-clippy#15305

changelog: [`unused_async`] fix FP on function with `todo!`
2025-07-23 13:43:55 +00:00
yanglsh
6a8780473e fix: unused_async FP on function with todo! 2025-07-22 23:25:31 +08:00
Krishna Ketan Rai
92111dcc67 Fix false positive in useless_attribute with redundant_imports
The useless_attribute lint was incorrectly flagging #[expect(redundant_imports)]
as useless when applied to macro re-exports. This occurred because the lint
didn't recognize 'redundant_imports' as a valid rustc lint name.

This commit:
- Adds 'redundant_imports' to the list of known rustc lints in sym.rs
- Updates the useless_attribute lint to properly handle this case
- Adds a regression test to prevent future false positives
2025-07-21 17:13:43 +05:30
yanglsh
1b883197d7 fix: if_then_some_else_none FP when require type coercion 2025-07-20 13:52:18 +08:00
Camille GILLOT
e81009d303 Include ErrorGuaranteed in StableSince::Err. 2025-07-17 23:27:19 +00:00
yanglsh
48df86f37d fix: match_single_binding suggests wrongly inside binary expr 2025-07-17 20:54:42 +08:00
Deadbeef
19f8c5004e parse const trait Trait 2025-07-17 18:06:26 +08:00
Nicholas Nethercote
b7caf7593e Improve path segment joining.
There are many places that join path segments with `::` to produce a
string. A lot of these use `join("::")`. Many in rustdoc use
`join_with_double_colon`, and a few use `.joined("..")`. One in Clippy
uses `itertools::join`. A couple of them look for `kw::PathRoot` in the
first segment, which can be important.

This commit introduces `rustc_ast::join_path_{syms,ident}` to do the
joining for everyone. `rustc_ast` is as good a location for these as
any, being the earliest-running of the several crates with a `Path`
type. Two functions are needed because `Ident` printing is more complex
than simple `Symbol` printing.

The commit also removes `join_with_double_colon`, and
`estimate_item_path_byte_length` with it.

There are still a handful of places that join strings with "::" that are
unchanged. They are not that important: some of them are in tests, and
some of them first split a path around "::" and then rejoin with "::".

This fixes one test case where `{{root}}` shows up in an error message.
2025-07-17 08:37:19 +10:00
Alex Macleod
fc441986b4
Use Ty::is_fn instead of manually matching on TyKind (#15089)
just makes the code a bit more concise

changelog: none
2025-07-15 14:12:13 +00:00
yanglsh
ba6485d61c fix: match_single_binding wrongly handles scope 2025-07-15 21:48:27 +08:00
bors
f4b827abeb Auto merge of #143745 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update

r? `@Manishearth`

Cargo.lock update due to `ui_test` bump and restructure.
2025-07-14 19:53:18 +00:00
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
bors
cffeac7212 Auto merge of #143779 - JonathanBrouwer:automatically_derived_parser, r=oli-obk
Port `#[automatically_derived]` to the new attribute parsing infrastructure

Ports `#[automatically_derived]` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971351163

r? `@oli-obk`
cc `@jdonszelmann`
2025-07-14 04:29:53 +00:00
Camille GILLOT
8510965e6b Retire hir::*ItemRef. 2025-07-13 13:50:01 +00:00
bors
519ad87c75 Auto merge of #143213 - dianne:lower-cond-tweaks, r=cjgillot
de-duplicate condition scoping logic between AST→HIR lowering and `ScopeTree` construction

There was some overlap between `rustc_ast_lowering::LoweringContext::lower_cond` and `rustc_hir_analysis::check::region::resolve_expr`, so I've removed the former and migrated its logic to the latter, with some simplifications.

Consequences:
- For `while` and `if` expressions' `let`-chains, this changes the `HirId`s for the `&&`s to properly correspond to their AST nodes. This is how guards were handled already.
- This makes match guards share previously-duplicated logic with `if`/`while` expressions. This will also be used by guard pattern[^1] guards.
- Aside from legacy syntax extensions (e.g. some builtin macros) that directly feed AST to the compiler, it's currently impossible to put attributes directly on `&&` operators in `let` chains[^2]. Nonetheless, attributes on `&&` operators in `let` chains in `if`/`while` expression conditions are no longer silently ignored and will be lowered.
- This no longer wraps conditions in `DropTemps`, so the HIR and THIR will be slightly smaller.
- `DesugaringKind::CondTemporary` is now gone. It's no longer applied to any spans, and all uses of it were dead since they were made to account for `if` and `while` being desugared to `match` on a boolean scrutinee.
- Should be a marginal perf improvement beyond that due to leveraging [`ScopeTree` construction](5e749eb66f/compiler/rustc_hir_analysis/src/check/region.rs (L312-L355))'s clever handling of `&&` and `||`:
  - This removes some unnecessary terminating scopes that were placed around top-level `&&` and `||` operators in conditions. When lowered to MIR, logical operator chains don't create intermediate boolean temporaries, so there's no temporary to drop. The linked snippet handles wrapping the operands in terminating scopes as necessary, in case they create temporaries.
  - The linked snippet takes care of letting `let` temporaries live and terminating other operands, so we don't need separate traversals of `&&` chains for that.

[^1]: rust-lang/rust#129967
[^2]: Case-by-case, here's my justification: `#[attr] e1 && e2` applies the attribute to `e1`. In `#[attr] (e1 && e2)` , the attribute is on the parentheses in the AST, plus it'd fail to parse if `e1` or `e2` contains a `let`. In `#[attr] expands_to_let_chain!()`, the attribute would already be ignored (rust-lang/rust#63221) and it'd fail to parse anyway; even if the expansion site is a condition, the expansion wouldn't be parsed with `Restrictions::ALLOW_LET`. If it *was* allowed, the notion of a "reparse context" from https://github.com/rust-lang/rust/issues/61733#issuecomment-509626449 would be necessary in order to make `let`-chains left-associative; multiple places in the compiler assume they are.
2025-07-13 04:20:07 +00:00
Jonathan Brouwer
3187aa751a Fix clippy & rustdoc-json
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-12 17:48:52 +02:00
Ada Alakbarova
e610584a9a
{flat_,}map_identity: also recognize |[x, y]| [x, y] 2025-07-12 14:02:41 +02:00
Ada Alakbarova
415438718c
Use Ty::is_fn instead of manually matching on TyKind 2025-07-12 13:34:32 +02:00
Matthias Krüger
a1844ec6c0 Rollup merge of #143708 - epage:pretty, r=compiler-errors
fix: Include frontmatter in -Zunpretty output

In the implementation (rust-lang/rust#140035), this was left as an open question for
the tracking issue (rust-lang/rust#136889).  My assumption is that this should be
carried over.

The test was carried over from rust-lang/rust#137193 which was superseded by rust-lang/rust#140035.

Thankfully, either way, `-Zunpretty` is unstable and we can always
change it even if we stabilize frontmatter.
2025-07-11 07:35:21 +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
Philipp Krones
4e614bf683 Merge commit 'cdbbf3afda0b1bf51568b368f629b1d828507f98' into clippy-subtree-update 2025-07-10 20:25:36 +02: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