Commit Graph

2318 Commits

Author SHA1 Message Date
Ada Alakbarova 5abee438bc other uses of get_diagnostic_name 2025-08-22 15:03:13 +02:00
Ada Alakbarova e243f89e3a misc: return earlier on name = None 2025-08-22 15:03:13 +02:00
Ada Alakbarova 34f96a2082 misc: pull condition into guard
`None` is the fallback case anyway
2025-08-22 15:03:13 +02:00
Ada Alakbarova e6833462eb misc: destruct args directly
avoids bounds checks
2025-08-22 15:03:13 +02:00
Ada Alakbarova abb89608af higher: use get_diagnostic_name 2025-08-22 15:03:13 +02:00
Philipp Krones 71b79ab466 Merge commit '877967959ae8da9814df4f2614971f4d784bf53f' into clippy-subtree-update 2025-08-22 14:57:22 +02:00
Philipp Krones 9de86f40d7 Dogfood fixes 2025-08-22 14:26:24 +02:00
Philipp Krones 284b596ac4 Merge remote-tracking branch 'upstream/master' into rustup 2025-08-22 14:25:23 +02:00
Alex Macleod e2a8b5b036 Lint to stable/beta lint docs page in diagnostics 2025-08-21 15:16:28 +00:00
Nicholas Nethercote c1dfeea919 Prevent impossible combinations in ast::ModKind.
`ModKind::Loaded` has an `inline` field and a `had_parse_error` field.
If the `inline` field is `Inline::Yes` then `had_parse_error` must be
`Ok(())`.

This commit moves the `had_parse_error` field into the `Inline::No`
variant. This makes it impossible to create the nonsensical combination
of `inline == Inline::Yes` and `had_parse_error = Err(_)`.
2025-08-19 21:57:31 +10:00
Nick Drozd 64d6f82825 Cut needless mut 2025-08-18 15:16:04 -04:00
dswij 0e4ce7ffff msrv: replace nested ifs with guard clauses (#15490)
reads a bit more natural imo

changelog: none
2025-08-18 16:23:22 +00:00
Alejandra González 73b5a59c22 Do not suggest to use implicit DerefMut on ManuallyDrop reached through unions (#14387)
This requires making the `deref_addrof` lint a late lint instead of an
early lint to check for types.

changelog: [`deref_addrof`]: do not suggest implicit `DerefMut` on
`ManuallyDrop` union fields

Fix rust-lang/rust-clippy#14386
2025-08-18 15:10:31 +00:00
Alejandra González 1fd9504619 similar_names stop linting for 3-char names (#15100)
fixes rust-lang/rust-clippy#14869

Added a simple check if both chars are of length 3
If they are, we skip the check for that pair.

This won't handle the 4 v 3 case.
Not sure if this was the intent of the issue.

Also saw we have some hardcoded exemptions for `set, get` and `lhs, rhs`
Tried removing them thinking they would be handled by the new condition.
But we have to keep because they allow for `bla_lhs` v `bla_rhs` to be
skipped

changelog:[`similar_names`]: Stop triggering for 3-character names
2025-08-16 16:58:06 +00:00
Abderahmane Bouziane e41fb7ca52 similar_names stop linting for 3-char names 2025-08-16 12:36:50 -04:00
bors cdcce5a137 Auto merge of #145304 - m-ou-se:simplify-panic, r=oli-obk
Revert "Partially outline code inside the panic! macro".

This reverts https://github.com/rust-lang/rust/pull/115670

Without any tests/benchmarks that show some improvement, it's hard to know whether the change had any positive effect. (And if it did, whether that effect is still achieved today.)
2025-08-16 10:15:46 +00:00
Ada Alakbarova 22bbb4eba2 use let-else to reduce nesting
..and create a nice linear structure
2025-08-14 23:17:54 +02:00
Ada Alakbarova 066bdb2155 replace with ? 2025-08-14 23:14:12 +02:00
Mara Bos f2f06654a5 Revert "Partially outline code inside the panic! macro".
Without any tests/benchmarks that show some improvement, it's hard to
know whether the change had any positive effect at all. (And if it did,
whether that effect is still achieved today.)
2025-08-12 12:52:39 +02:00
Cameron Steffen 9f98857714 Propagate TraitImplHeader to hir 2025-08-11 17:05:42 -05:00
Cameron Steffen 7fe9a40b6b Extract ast TraitImplHeader 2025-08-11 17:05:36 -05:00
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
Deadbeef 0a70523546 remove P 2025-08-09 15:47:01 +08:00
Philipp Krones eb15cf0a30 Merge commit '334fb906aef13d20050987b13448f37391bb97a2' into clippy-subtree-update 2025-08-07 17:05:15 +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
RunDevelopment 064825e734 Add suggestion to cast_sign_loss and cast_possible_wrap using the cast_{un,}signed() methods 2025-08-03 13:45:45 +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 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