Commit graph

23997 commits

Author SHA1 Message Date
GiGaGon
2fe16a574f
Fix spacing typo in new inefficient_to_string info 2025-10-15 12:06:20 -07:00
Jason Newcomb
8116b2354a
Dereference argument of manual_div_ceil() if needed (#15706)
Fixes rust-lang/rust-clippy#15705

changelog: [`manual_div_ceil`]: dereference argument when needed

r? Alexendoo
2025-10-15 02:22:39 +00:00
Jason Newcomb
ec8e8fde91
refactor(non_canonical_impls): lint starting from impls (#15749)
Based on
https://github.com/rust-lang/rust-clippy/pull/15520#discussion_r2372599748,
with the following changes/additions:
- No longer use the `Trait` enum for quickly filtering out irrelevant
impls -- instead, check the `trait_of` basically right away:
    1. pre-fetch `DefId`s of the relevant traits into the lint pass
2. reuse `cx.tcx.impl_trait_ref`'s output for the the `DefId` of the
trait being implemented
    3. compare those `DefId`s, which should be very cheap
- Next, check whether `self_ty` implements the other relevant trait.
- Pre-filter impl items in the same (lazy) iterator, but delay the
proc-macro check as much as possible

changelog: none

Not auto-assigning since @blyxyas and/or @Jarcho will be the ones
reviewing it:
r? ghost
2025-10-15 02:20:21 +00:00
Jason Newcomb
d230acd9cf
Allow explicit_write in tests (#15862)
Resolves rust-lang/rust-clippy#15780.

I didn't get any feedback on that issue. So I hope it is okay that I
charged ahead and addressed it.

changelog: Allow `explicit_write` in tests
2025-10-15 01:44:50 +00:00
Alejandra González
b26a1aaa77
[unnecessary_safety_comment] Some fixes regarding comments above attributes (#15678)
The way clippy checked for SAFETY comments above attributes was wrong:
- It wasn't considered for items
- It cause an ICE with some attributes
- When considering comments above attributes, it didn't considered
comments below them, causing some unlintable situations.

This PR tries to fix this by delegating the skipping of attributes to
the function analyzing the source code itself.

changelog: [`unnecessary_safety_comment`]: Taking into account comments
above attributes for items

Fixes rust-lang/rust-clippy#14555
Fixes rust-lang/rust-clippy#15684
Fixes rust-lang/rust-clippy#15754
2025-10-14 22:18:55 +00:00
Teodoro Freund
9cc0291582 unnecessary_safety_comment fix an ICE and
improve coverage

Considering comments above attributes for items

Fixed the ICE and safety comments between attributes

- No longer using attr.span()
- ignoring attributes manually

Improve error messages on unsafe fns
2025-10-14 22:23:53 +01:00
Jason Newcomb
eee8ef85ce
New internal lint: unusual_names (#15794)
This lint aims at detecting unusual names used in Clippy source code,
such as `appl` or `application` for a `rustc_errors::Applicability`
variable, instead of `app` and `applicability` which are commonly used
throughout Clippy.

This helps maintaining the consistency of the Clippy source code.

It is currently implemented for:

- `Applicability`: `app` or `applicability`
- `EarlyContext`/`LateContext`: `cx`
- `TyCtxt`: `tcx`

changelog: none
2025-10-14 20:32:13 +00:00
Samuel Moelius
1bd8cad5a2 Allow explicit_write in tests 2025-10-14 11:52:54 -04:00
Philipp Krones
c6f2557d26
Update actions/setup-node version (#15874)
Update actions/setup-node version.

changelog: none
2025-10-13 07:51:51 +00:00
Samuel Tardieu
a8d1258ba7
feat(multiple_inherent_impl): Add config option to target specific scope (#15843)
Add a config option `inherent-impl-lint-scope` to the lint
`multiple_inherent_impl` to target a different scope according to
people's needs. It can take three values: `module`, `file`, and `crate`
(default).

- `module` is the weakest option. It lints if there are two or more
impls in the same module.
- `file` is a bit stronger, since it lints if there are two or more
impls in the same file. So, this triggers the lint (where it did not
with module):
- `crate` is the strongest of them; it triggers as soon as there are two
or more impls anywhere in the crate. It is the current behaviour of the
lint, so it's the default option.

changelog: [`multiple_inherent_impl`] : Add config option (`module`,
`file` or `crate`) to target specific scope

fixes rust-lang/rust-clippy#14867
2025-10-13 05:07:54 +00:00
alexey semenyuk
e786e009ed actions/setup-node update 2025-10-12 21:15:33 +03:00
Paul MIALANE
9be213666e feat(multiple_inherent_impl): Add config option to target specific scope 2025-10-12 10:59:57 +02:00
Jason Newcomb
35f8bffb91
book: cleanups (#15864)
changelog: none
2025-10-11 15:58:20 +00:00
Timo
1f0b8b8629
fix(clone_on_ref_ptr): only name the generic type if possible (#15740)
Fixes https://github.com/rust-lang/rust-clippy/issues/15009

changelog: [clone_on_ref_ptr]: only name the generic type if possible
2025-10-11 14:15:19 +00:00
Alejandra González
d66e5db0f7
manual_unwrap_or: fix FP edge case (#15812)
changelog: [`manual_unwrap_or`]: fix FP edge case

Found this problem while investigating a different bug.
2025-10-11 11:15:44 +00:00
Samuel Tardieu
7c7bd6ea8a
feat(zero_repeat_side_effects): don't suggest unnecessary braces around stmts (#15826)
changelog: [`(zero_repeat_side_effects`]: don't suggest unnecessary
braces around stmts

r? @samueltardieu
2025-10-11 08:30:27 +00:00
Ada Alakbarova
6b076ca80b
feat(zero_repeat_side_effects): don't suggest unnecessary braces around stmts 2025-10-11 10:19:24 +02:00
Ada Alakbarova
bb5b5bce99
feat(zero_repeat_side_effects): put the suggestion on two lines 2025-10-11 10:19:23 +02:00
Samuel Tardieu
1ffd092a80
book: import implements_trait from clippy_utils::ty 2025-10-11 10:18:44 +02:00
Samuel Tardieu
9027625e14
book: use Type::method instead of Type.method to refer to methods 2025-10-11 10:18:43 +02:00
Samuel Tardieu
85ef0170c4
book: encourage the use of clippy_utils::sym
Also, explain how new symbols can be added to this module in order to
compare names.
2025-10-11 10:18:43 +02:00
Ada Alakbarova
3c02c0ef20
refactor(non_canonical_impls): lint starting from impls 2025-10-11 10:03:56 +02:00
Ada Alakbarova
16880f7594
check earlier for PartialEq where Rhs != Self 2025-10-11 09:41:31 +02:00
Samuel Tardieu
12e2542c55
Dereference argument of manual_div_ceil() if needed 2025-10-11 09:37:25 +02:00
Samuel Tardieu
5de7da824c
New internal lint: unusual_names
This lint aims at detecting unusual names used in Clippy source code,
such as `appl` or `application` for a `rustc_errors::Applicability`
variable, instead of `app` and `applicability` which are commonly used
throughout Clippy.

This helps maintaining the consistency of the Clippy source code.
2025-10-11 09:37:25 +02:00
Samuel Tardieu
d10ea6eab0
Cleanup: rename EarlyContext/LateContext parameters 2025-10-11 09:37:25 +02:00
Samuel Tardieu
f6665478e1
Cleanup: rename Applicability variables/parameters 2025-10-11 09:37:25 +02:00
Ada Alakbarova
097f2fd2f4
add missing test for macros
The missing external macro test for `non_canonical_clone_impl` was
caught thanks to lintcheck -- I went ahead and added all the other
combinations of the test while at it
2025-10-11 09:24:58 +02:00
Samuel Tardieu
ebbbbebf2d
Replace all item identification utils (#15682)
This introduces a new way of identifying items/paths using extension
traits with a composable set of functions rather than unique functions
for various combinations of starting points and target items. Altogether
this is a set of five traits:

* `MaybeTypeckRes`: Allows both `LateContext` and `TypeckResults` to be
used for type-dependent lookup. The implementation here will avoid ICEs
by returning `None` when debug assertions are disabled. With assertions
this will assert that we don't silently lookup anything from a different
body than the current one and that a definition actually exists.
* `HasHirId`: Simply a convenience to allow not typing `.hir_id` at call
sites.
* `MaybeQPath`: This is the old `MaybePath`. Extension functions for
type-dependent path lookups exist here. A lot of these functions aren't
used in the current PR, but what they accomplish is done in various
places I haven't cleaned up yet.
* `MaybeResPath`: Like `MaybeQPath`, but only does non-type-dependent
lookup (`QPath::Resolved`).
* `MaybeDef`: Extension functions for identifying the current definition
and accessing properties. Implemented for several types for convenience.

`MaybeDef` is implemented for `Option` to allow chaining methods
together. e.g.
`cx.ty_based_def(e).opt_parent(cx).opt_impl_ty(cx).is_diag_item(..)`
would chaining `and_then` or `if let` on every step. `MaybeQPath` and
`MaybeResPath` are also implemented for `Option` for the same reason.

`ty_based_def` is just a shorter name for `type_dependent_def`. I'm not
really attached to it, but it's nice that it's a little shorter.

changelog: none
2025-10-11 07:03:12 +00:00
Jason Newcomb
42f2ba1869
fix(zero_repeat_side_effects): don't suggest unsuggestable types (#15815)
Fixes https://github.com/rust-lang/rust-clippy/issues/14998

changelog: [`zero_repeat_side_effects`]: don't suggest unsuggestable
types
2025-10-11 04:15:13 +00:00
Jason Newcomb
6bfb524e9a Remove is_trait_item 2025-10-10 23:15:59 -04:00
Jason Newcomb
e69d88bb10 Remove is_trait_method 2025-10-10 23:15:59 -04:00
Jason Newcomb
d0be3356ba Remove is_inherent_method_call 2025-10-10 23:12:44 -04:00
Jason Newcomb
e78f86d550 Remove is_diag_item_method 2025-10-10 23:09:26 -04:00
Jason Newcomb
2e6729ea64 Remove is_diag_trait_item 2025-10-10 23:09:26 -04:00
Jason Newcomb
a6078f87db Remove path_to_local_id 2025-10-10 23:09:26 -04:00
Jason Newcomb
53675ce061 Remove path_to_local 2025-10-10 23:09:26 -04:00
Jason Newcomb
3f686a074d Remove is_res_lang_ctor 2025-10-10 23:00:17 -04:00
Jason Newcomb
3ed7aa0d5f Remove path_def_id 2025-10-10 23:00:17 -04:00
Jason Newcomb
5b659ba0b4 Remove path_res 2025-10-10 22:51:33 -04:00
Jason Newcomb
53783de8f0 Remove MaybePath 2025-10-10 22:51:33 -04:00
Jason Newcomb
e1a4c90f61 Remove get_type_diagnostic_name 2025-10-10 22:47:41 -04:00
Jason Newcomb
083b1c1059 Remove is_type_lang_item 2025-10-10 22:44:01 -04:00
Jason Newcomb
fe13e0675a Remove is_type_ref_to_diagnostic_item 2025-10-10 22:41:10 -04:00
Jason Newcomb
4914f5908f Remove is_type_diagnostic_item 2025-10-10 22:41:10 -04:00
Jason Newcomb
cb32444ee6 Remove is_path_diagnostic_item 2025-10-10 22:30:57 -04:00
Jason Newcomb
d32ef64ed5 Remove is_path_lang_item 2025-10-10 22:30:57 -04:00
Jason Newcomb
748a593a7f Add new utils for defninition identification. 2025-10-10 22:30:25 -04:00
Michael Howell
e0e5d478c1 manual_unwrap_or: fix FP edge case 2025-10-10 16:54:33 -07:00
Samuel Tardieu
70d5c8c9e4
Autolabel PR touching declared_lints.rs with needs-fcp (#15859)
changelog: none
2025-10-10 20:09:34 +00:00