Commit graph

13582 commits

Author SHA1 Message Date
Ada Alakbarova
e6f3cb00a7
move char_lit_as_u8 into the if
allows reusing `cast_from_expr` and `cast_to`
2025-08-13 16:44:32 +02:00
Ada Alakbarova
8725fac6f3
misc: use Ty::is_unit 2025-08-12 19:36:03 +02:00
Ada Alakbarova
af2dd2d3bc
fix unnecessary_semicolon: don't lint on stmts with attrs 2025-08-12 19:12:47 +02:00
Alejandra González
1f9a6ad00e
Correct needless_borrow_for_generic_args doc comment (#15440)
I think the comment is meant to refer to `needless_borrow_count`.

changelog: none
2025-08-11 14:30:14 +00:00
Timo
14dfc03597
feat: introduce path_to_local_with_projections (#15396)
As suggested in
https://github.com/rust-lang/rust-clippy/pull/15268#discussion_r2249249661

WIP because:
- [x] what should be done with the now-error-pattern-less
`tests/ui/double_ended_iterator_last_unfixable.rs`?
- [x] is the change in behaviour of `double_ended_iterator_last` okay in
general?
- cc @samueltardieu because this changes the code you added in
https://github.com/rust-lang/rust-clippy/pull/14140

changelog: none

r? @y21
2025-08-10 10:33:05 +00:00
Samuel Tardieu
e6b63d15fa
fix &str type check in from_str_radix_10 (#15410)
minor fix in `from_str_radix_10` lint, `is_type_diagnostic_item` only
checks `Adt`, use `.is_str()` instead

changelog: [`from_str_radix_10`]: properly lint references to `&str` as
well
2025-08-09 22:30:18 +00:00
llogiq
f3ced4d1c1
expect_fun_call: move helper functions out of the main one (#15446)
just a clean-up

changelog: none
2025-08-09 21:47:37 +00: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
dswij
386372a0e4
[[infinite_loop] fix infinite loop false positive (#15157)
changelog: [infinite_loop]: Improve handling of infinite loops in async
blocks

Fix rust-lang/rust-clippy#14000

This PR refines the [infinite_loop] lint to avoid false positives when
infinite loops occur inside async blocks that are not awaited (such as
those that are spawned or assigned to variables for later use). The lint
will now only trigger when the async block containing the loop is
directly awaited.
2025-08-09 15:08:54 +00:00
Jason Newcomb
ea7ebaa825
Do not attempt to compute size of a type with escaping lifetimes (#15434)
A type with escaping bound vars cannot be wrapped in a dummy binder
during size computation.

Fixes rust-lang/rust-clippy#15429

changelog: [`zero_sized_hashmap_values`]: fix ICE in types with escaping
lifetimes

r? Jarcho

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

- [Beta
nomination](https://github.com/rust-lang/rust-clippy/pull/15434#issuecomment-3164866684)
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-08-09 14:09:43 +00:00
Ada Alakbarova
d5f2b66bd8
expect_fun_call: move helper functions out of the main one
allows removing the `#[allow(clippy::too_many_lines)]`
2025-08-09 11:50:00 +02:00
Samuel Moelius
7057cd8f4f Correct needless_borrow_for_generic_args doc comment 2025-08-08 11:06:39 -04:00
Ada Alakbarova
82c1ce77ed
misc: use let-chains 2025-08-08 16:56:39 +02:00
Samuel Tardieu
22088843b4
move crosspointer_transmute from complexity to suspicious (#15403)
changelog: [`crosspointer_transmute`]: move from `complexity` to
`suspicious`

this looks to me like an obvious miscategorisation -- and there was
already [a proposal to move the
lint](https://github.com/rust-lang/rust-clippy/issues/6626#issuecomment-1279775089)
2025-08-08 11:14:15 +00:00
Ada Alakbarova
ac9361e18a
eta_reduction: don't refer to ADT constructors as "function"s 2025-08-08 11:00:49 +02:00
Chengxu Bian
c945393f67 fix inf loop 2025-08-07 22:17:37 -04:00
Ada Alakbarova
7aa75635c8
move crosspointer_transmute from complexity to suspicious 2025-08-07 23:44:33 +02:00
Alejandra González
32a216ecab
Reuse previous Vec allocation in loop (#15428)
Minor optimization to avoid deallocating/reallocating a new `Vec` in the
top `check_doc` loop.

changelog: none

r? blyxyas
2025-08-07 18:21:20 +00:00
Samuel Tardieu
c752fb2802
Do not attempt to compute size of a type with escaping lifetimes
A type with escaping bound vars cannot be wrapped in a dummy binder
during size computation.
2025-08-07 18:29:10 +02:00
Philipp Krones
d5f9f7576c
Bump Clippy version -> 0.1.91 2025-08-07 16:48:16 +02:00
Philipp Krones
f2b7e9ff52
Merge remote-tracking branch 'upstream/master' into rustup 2025-08-07 16:47:42 +02:00
Samuel Tardieu
cece1b95de
Reuse previous Vec allocation in loop 2025-08-07 10:12:07 +02:00
Samuel Tardieu
8602faa6ff
Optimize needless_bool lint
Two optimizations have been done when checking for the context in which
to apply the lint:

- Checking for the mere presence of comments does not require building a
  `String` with the comment to then check if it is empty and discard it.
- Checking for the presence of comment can be done after we have checked
  that we do have a `if` construct that we intend to lint instead of for
  every expression.
2025-08-06 19:49:22 +02:00
Alejandra González
a4d43215b8
Optimize incompatible_msrv lint (#15422)
This limits repeated lookups in pre-checks (to determine if a MSRV
should be checked), especially when those require locking up an
interner:

- The `core` crate is looked up once when creating the lint, instead of
comparing the crate name with `sym::core` at every check.
- `span.ctxt().outer_expn_data()` is lookup up only once.

changelog: none
r? blyxyas
2025-08-06 16:25:34 +00:00
Samuel Tardieu
26911aa32c
Optimize incompatible_msrv lint
This limits repeated lookups in pre-checks (to determine if a MSRV
should be checked), especially when those require locking up
an interner:

- The `core` crate is looked up once when creating the lint, instead of
  comparing the crate name with `sym::core` at every check.
- `span.ctxt().outer_expn_data()` is lookup up only once.
2025-08-06 16:30:31 +02:00
llogiq
d98d7c0ee8
Fix suggestion for collapsible_if and collapsible_else_if when the inner if is enclosed in parentheses (#15304)
changelog: [`collapsible_else_if`]: fix suggestion when inner `if` as
wrapped in parentheses
changelog: [`collapsible_if`]: fix suggestion when inner `if` as wrapped
in parentheses

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

I'm sure this is a bit dirty, but don't currently see a better way.
2025-08-06 12:45:27 +00:00
Alejandra González
03ae8b0464
Do not lint for wildcard_imports in external macro (#15413)
Fixes rust-lang/rust-clippy#15412

changelog: [`wildcard_imports`]: do not lint code coming from an
external macro
2025-08-05 22:32:08 +00:00
Zihan
7a113811fa
fix &str type check in from_str_radix_10
changelog: none

Signed-off-by: Zihan <zihanli0822@gmail.com>
2025-08-05 09:50:17 -04:00
Samuel Tardieu
8396d73798
Fix unnecessary_sort_by lint method consistency in message and suggestion (#15416)
The `unnecessary_sort_by` lint displays different method names in
message and suggestion, which is a bit confusing.

Also got a question about `UNNECESSARY_SORT_BY` lint definition. Should
we extend its message to also cover *_unstable_* methods?

changelog: [`unnecessary-sort-by`]: sort method consistency in message
and suggestion
2025-08-05 12:50:25 +00:00
Huterenok
6249f33ca1 fix: unnecessary_sort_by lint method consistency in message and suggestion 2025-08-05 15:23:10 +03:00
Samuel Tardieu
cdee4f8e1d
Move cognitive_complexity lint from nursery to restriction 2025-08-05 13:52:58 +02:00
Samuel Tardieu
6c7fa3b2cb
Do not lint for wildcard_imports in external macro 2025-08-05 11:29:18 +02:00
Alejandra González
264bc97b26
Split possible_missing_else from suspicious_else_formatting (#15317)
This has always been one lint (added in rust-lang/rust-clippy#720), but
the two cases are also quite distinct.

changelog: Split `possible_missing_else` from
`suspicious_else_formatting`

<!-- TRIAGEBOT_START -->

<!-- TRIAGEBOT_SUMMARY_START -->

### Summary Notes

-
[Feature-freeze](https://github.com/rust-lang/rust-clippy/pull/15317#issuecomment-3094592022)
by [github-actions[bot]](https://github.com/github-actions[bot])

*Managed by `@rustbot`—see
[help](https://forge.rust-lang.org/triagebot/note.html) for details*

<!-- TRIAGEBOT_SUMMARY_END -->
<!-- TRIAGEBOT_END -->
2025-08-04 22:57:06 +00:00
Fayti1703
5b22c0c1ed Remove rogue comma from infallible_try_from lint message 2025-08-04 16:38:31 +02:00
Philipp Krones
7a179313b9
Changelog for Clippy 1.89 🌽 (#15375)
Violets are red,
Roses are blue,
As August winds whisper,
Take a chance, then rest too.

<hr>

Appreciate it as always @xFrednet

<img width="601" height="744" alt="image"
src="https://github.com/user-attachments/assets/a0e4af41-da97-4565-881b-549ed51d7fc5"
/>

<hr>

Cats for the next release can be traditionally nominated in the comments
:D
Please be more active and cat-minded 😻

changelog: none

r? flip1995
2025-08-04 10:55:20 +00:00
Stuart Cook
ed363ac523 Rollup merge of #144694 - compiler-errors:with-self-ty, r=SparrowLii
Distinguish prepending and replacing self ty in predicates

There are two kinds of functions called `with_self_ty`:
1. Prepends the `Self` type onto an `ExistentialPredicate` which lacks it in its internal representation.
2. Replaces the `Self` type of an existing predicate, either for diagnostics purposes or in the new trait solver when normalizing that self type.

This PR distinguishes these two because I often want to only grep for one of them. Namely, let's call it `with_replaced_self_ty` when all we're doing is replacing the self type.
2025-08-04 14:58:09 +10:00
Ada Alakbarova
1fc5e81436
clean-up semicolon_inside_block
match on `StmtKind` directly

use a let-chain

break up match for a nicer let-chain

shorten `get_line`

move `expr` check down in the inside case as well

for consistency

use `shrink_to_hi`

Apply suggestion

Co-authored-by: Samuel Tardieu <sam@rfc1149.net>
2025-08-04 00:53:27 +02:00
Ada Alakbarova
02ebef4c6a
don't allocate a Vec in an Iterator::chain 2025-08-03 17:13:54 +02:00
Jason Newcomb
88bcf1ca19
fix option-if-let-else lint (#15394)
some simple twists
Fixes rust-lang/rust-clippy#15002
Fixes rust-lang/rust-clippy#15379

changelog: [`option_if_let_else`]: Don't remove raw pointer derefs in
suggestions
changelog: [`option_if_let_else`]: Don't suggest passing argless
functions to `Result::map_or_else`
2025-08-03 06:55:48 +00:00
Jason Newcomb
fa09b86bfc
Simplify boolean expression in manual_assert (#15368)
Fixes rust-lang/rust-clippy#15359

changelog: [`manual_assert`]: simplify boolean expression
2025-08-03 05:41:51 +00:00
Zihan
8f6b43dd65
fix: option_if_let_else don't suggest argless function for Result::map_or_else
closes rust-clippy/issues/15002

Signed-off-by: Zihan <zihanli0822@gmail.com>
2025-08-02 16:58:18 -04:00
Zihan
b8c16e47f4
fix: option_if_let_else keep deref op if the inner expr is a raw pointer
closes rust-clippy/issues/15379

Signed-off-by: Zihan <zihanli0822@gmail.com>
2025-08-02 13:07:11 -04:00
Timo
e8185ec091
Extend implicit_clone to handle to_string calls (#14177)
Put another way, merge `string_to_string` into `implicit_clone`, as
suggested here:
https://github.com/rust-lang/rust-clippy/issues/14173#issuecomment-2645846915

Note: [I
wrote](b8913894a1)
this comment:
6cdb7f68c3/clippy_lints/src/methods/implicit_clone.rs (L43-L45)

Here is the context for why I wrote it:
https://github.com/rust-lang/rust-clippy/pull/7978#discussion_r769128853

Regardless, it's probably time for the comment to go away. Extending
`implicit_clone` to handle `to_string` calls yields many hits within
Clippy's codebase.

changelog: extend `implicit_clone` to handle `to_string` calls
2025-08-02 11:41:00 +00:00
Samuel Tardieu
e42586d495
fix: let_with_type_underscore don't eat closing paren in let (i): _ = 0; (#15386)
Apparently, one can surround a pattern with an arbitrary number of
parens, and the resulting `Pat` won't include the span of those parens.
And the previous approach extended the to-be-deleted span all the way to
the end of `Pat`'s span, so it included the closing paren.

I think the new approach is more robust anyway, since all we care to
remove (besides the `_`) is the `:`, so we search just for that.

~This does leave one extra whitespace in one of the test cases, but I'd
say let rustfmt handle that.~ fixed in the third commit

changelog: [`let_with_type_underscore`]: don't eat closing paren in `let
(i): _ = 0;`

fixes https://github.com/rust-lang/rust-clippy/issues/15377
2025-08-02 07:53:32 +00:00
Ada Alakbarova
0f98da7c5c
fix: let_with_type_underscore don't eat closing paren in let (i): _ = 0;
add failing tests

fix

also remove whitespace before `:`
2025-08-02 09:48:12 +02:00
blyxyas
01d960f645 Optimize broken_links by 99.77% 2025-08-02 01:59:48 +02: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
Alexey Semenyuk
9f7a8f8f9e Changelog for Clippy 1.89 2025-07-31 20:38:41 +05: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