Commit graph

21959 commits

Author SHA1 Message Date
Tom
cc6127bce8 docs: update rationale for excessive-bools
Adds the reasoning to the docs for this rule on why enums are generally better for representing state machines than structs with  many bool fields.
2025-03-06 17:30:16 +00:00
Philipp Krones
cdc1d9d87a
Lint more cases with ptr_eq (#14339)
This PR:

- lints more case of raw pointer comparisons
- do not omit the named function to raw pointer conversion before
suggesting
- trigger the `ptr_eq` lint only if `cmp_null` doesn't trigger first, as
this is a more specialized version
- lints against `!=` in addition to `==`

The `ptr_eq` code has been moved from under `operators` to `ptr.rs`, in
order to benefit from factorization.

Fix #14337

changelog: [`ptr_eq`]: handle more cases
2025-03-04 08:15:00 +00:00
Philipp Krones
b4b7c7b057
Use the latest nightly rust to run linkcheck (#14348)
changelog: none
2025-03-04 07:55:17 +00:00
Samuel Tardieu
414136239b Use the latest nightly rust to run linkcheck 2025-03-04 08:50:26 +01:00
Alejandra González
a9c61ec1e1
needless_collect: avoid warning if non-iterator methods are used (#14147)
changelog: [`needless_collect`]: avoid warning if non-`Iterator` methods
are called on the result of `into_iter`

Fixes #13430
2025-03-02 22:40:07 +00:00
Alejandra González
aa2180f5fe
fix: map_entry suggest wrongly when key is not Copy (#14314)
Closes #13306
Closes #9925
Closes #9470
Closes #9305

Clippy gives wrong suggestions when the key is not `Copy`. As suggested
in #9925, in such cases Clippy will simply warn but no fix.

changelog: [`map_entry`]: fix wrong suggestions when key is not `Copy`
2025-03-02 20:55:17 +00:00
Samuel Tardieu
336d34481e Apply ptr_eq lint only if cmp_null is not applicable
The `cmp_null` lint is more specialized than `ptr_eq`. The former should
take precedence, unless the user allows it.
2025-03-02 16:21:12 +01:00
Samuel Tardieu
d7d0abd2ad Lint more cases of ptr::eq()
Also, do not strip conversions of a function pointer to a `*const`, as
no implicit conversion will take place.
2025-03-02 15:50:13 +01:00
Fridtjof Stoldt
62f34f2f58
fix: undocumented_unsafe_blocks FP on trait/impl items (#13888)
fixes #11709

Continuation of #12672. r? @Alexendoo if you don't mind?

changelog: [`undocumented_unsafe_blocks`] fix FP on trait/impl items
2025-03-01 15:53:45 +00:00
llogiq
35746de197
comparison_chain: stylepedantic (#14219)
The `comparison_chain` lint might suggest code which seems less natural
to beginners.

[Discussion](https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/demote.20some.20lints.20to.20.60pedantic.60)

changelog: [`comparison_chain`]: change lint category to `pedantic`
2025-03-01 13:41:44 +00:00
yanglsh
d027ca95de Add regression test for #11709 2025-03-01 20:45:46 +08:00
yanglsh
3899488e53 fix undocumented_unsafe_blocks FP in long assignment 2025-03-01 20:35:48 +08:00
yanglsh
91d20cbb82 Use inner span in undocumented_unsafe_blocks 2025-03-01 20:35:18 +08:00
J-ZhengLi
d395646a60 fix [undocumented_unsafe_blocks] FP with trait/impl items 2025-03-01 20:33:24 +08:00
Fridtjof Stoldt
1419ac2982
Suggest using #[expect] to check lint positioning (#14327)
Using `#[allow]` will also apply to child HIR nodes, while `#[expect]`
will ensure that the proper HIR node has been used for positioning the
lint.

changelog: none
2025-03-01 10:48:26 +00:00
Samuel Tardieu
e15b9a09e8 Suggest using #[expect] to check lint positioning
Using `#[allow]` will also apply to child HIR nodes, while `#[expect]`
will ensure that the proper HIR node has been used for positioning the
lint.
2025-03-01 09:34:55 +01:00
llogiq
817853044f
Extend {implicit,inverted}_saturating_sub to expressions (#14310)
changelog: [`implicit_saturating_sub`, `inverted_saturating_sub`]:
extend lints from local variables to side-effect free expressions

Noticed when #14308 introduced an implicit `saturating_sub` operation
and didn't get tagged.
2025-03-01 05:51:35 +00:00
Samuel Tardieu
029a6db879 Apply implicit_saturating_sub to Clippy sources 2025-02-28 23:50:43 +01:00
Samuel Tardieu
60e1d7ec2d Extend {implicit,inverted}_saturating_sub to expressions
Side-effect free expressions are eligible to these lints,
whereas previously only local variables were checked.
2025-02-28 23:50:43 +01:00
Timo
9f9a822509
Check for MSRV attributes in late passes using the HIR (#13821)
Closes https://github.com/rust-lang/rust-clippy/issues/13169

Late lints now use a parent iter to check for `#[clippy::msrv]`
attributes instead of keeping track with `extract_msrv_attr`. This is
required for incremental lints since they run per module instead of per
crate so don't visit all the necessary attributes

As a basic optimisation if no `#[clippy::msrv]` attributes are
discovered in early passes the HIR access is skipped completely and just
the configured MSRV is used, for most code bases this will be the case

changelog: none
2025-02-28 20:48:55 +00:00
Timo
6f66a6037e
Fix ICE in manual_map lint (#14326)
node_args doesn't work with struct literals and expr_ty must be used
instead

r? @y21

changelog: none

(No changelog, as this ICE didn't make it to the Rust repo, as it was
caught during the sync)

Fixes #14325
2025-02-28 20:19:03 +00:00
Philipp Krones
900aab72cd
Fix ICE in manual_map lint
node_args doesn't work with struct literals and expr_ty must be used instead
2025-02-28 21:14:02 +01:00
Alex Macleod
5b0004c45f Migrate clippy_lints to new MSRV API 2025-02-28 18:15:11 +00:00
Alex Macleod
0972c3b565 Check for MSRV attributes in late passes using the HIR 2025-02-28 18:09:44 +00:00
Timo
2cdb90d961
New lint: manual_midpoint (#13851)
changelog: [`manual_midpoint`]: new lint

Closes #13849
2025-02-28 16:27:34 +00:00
yanglsh
18616dcd4f fix: map_entry suggest wrongly when key is not Copy 2025-02-28 23:35:53 +08:00
Alejandra González
e1c1ac1592
configuration option to lint incompatible_msrv in test code (#14279)
fixes #14277

changelog: [`incompatible_msrv`]: add config option
[`check-incompatible-msrv-in-tests`] to enable in `#[test]` and
`#[cfg(test)]` code.
2025-02-28 12:41:46 +00:00
Samuel Tardieu
baadee8fd3 New lint: manual_midpoint 2025-02-27 22:12:16 +01:00
Samuel Tardieu
06175f43b3 Add is_float_literal utility 2025-02-27 22:10:57 +01:00
Philipp Krones
715d3f9224
Rustup (#14300)
Out of cycle sync, as it is complicated and confusing to resolve merge
conflicts on the Rust side. This needs review for
eda3e649a41e0e73cb2e3ee6b98cbf8d7c12acae and
4d8766caaf11a14194406b8997243bb626000aae as well as the comment I'll
leave below.

changelog: none
2025-02-27 21:02:32 +00:00
Philipp Krones
b3d35b1af6 Bump nightly version -> 2025-02-27 2025-02-27 21:51:42 +01:00
Philipp Krones
28555d1231 Split must_use_unit test into an unfixable part
With the attribute refactor in rustc, making this case machine applicable is not
easily possible anymore. This splits up the tests properly.
2025-02-27 21:51:42 +01:00
Philipp Krones
53a1ff70e8 Check os_str_display MSRV instead of feature
This feature was stabilized, so the FormatArgs lints should check if the MSRV of
the stabilization is met, rather than checking if the feature is enabled.
2025-02-27 21:51:42 +01:00
Philipp Krones
02e812af4d Merge remote-tracking branch 'upstream/master' into rustup 2025-02-27 21:51:42 +01:00
Catherine Flores
15180d4eb9
macro_use_import: Don't check is attribute comes from expansion (#14317)
It is not possible to write a declarative macro, that produces an
attribute w/o
an item attached to it. This means that the `check_item` will already
insert the
span in the map, if it came from an expansion. So additionally checking
if the
macro came from an expansion doesn't add anything here. So the
`check_attribute` function, and with that the problematic `attr.span()`
call can
be completely removed.

Fixes https://github.com/rust-lang/rust-clippy/issues/14303

r? @y21

cc @jdonszelmann

changelog: Fix ICE in [`macro_use_import`] lint
2025-02-27 19:51:57 +00:00
Philipp Krones
063d6aef0e
macro_use_import: Don't check is attribute comes from expansion
It is not possible to write a declarative macro, that produces an attribute w/o
an item attached to it. This means that the `check_item` will already insert the
span in the map, if it came from an expansion. So additionally checking if the
macro came from an expansion doesn't add anything here. So the
`check_attribute` function, and with that the problematic `attr.span()` call can
be completely removed.

Fixes #14303
2025-02-27 20:42:56 +01:00
Alex Macleod
4a9b8c6415
fix: map_entry FP inside closure (#14307)
Closes #11976

changelog: [`map_entry`]: fix FP inside closure
2025-02-27 14:42:00 +00:00
yanglsh
329acde93e fix: map_entry FP inside closure 2025-02-27 21:28:00 +08:00
dswij
527ab050fa
fix: Avoid ICE in doc_nested_refdefs check by checking range (#14308)
The `looks_like_refdef` function was assuming the range was valid, this
just adds a check to ensure that is the case. It also works around a
subtraction underflow due to the same invalid range.

changelog: [`doc_nested_refdefs`]: Fix #14287 by avoiding invalid ranges
2025-02-27 10:45:31 +00:00
Fridtjof Stoldt
f50266a423
Split needless_lifetime '_ suggestions into elidable_lifetime_names (#13960)
Fixes https://github.com/rust-lang/rust-clippy/issues/13514

changelog: Added [`elidable_lifetime_names`] to `pedantic` (Split off
from [`needless_lifetime`] for suggestions with `'_`)
[#13960](https://github.com/rust-lang/rust-clippy/pull/13960)

changelog: Enhancement: [`needless_lifetime`] No longer lints for
elidable lifetimes `'_`, use [`elidable_lifetime_names`] to lint these.
[#13960](https://github.com/rust-lang/rust-clippy/pull/13960)
2025-02-27 09:21:50 +00:00
Jake Shadle
e399e152e8 Fix ICE 2025-02-27 10:18:44 +01:00
Manish Goregaokar
52bf26e9ad
Remove obsolete TODO (#14304)
changelog: none
2025-02-26 22:49:03 +00:00
Samuel Tardieu
e9561289d6 Remove obsolete TODO 2025-02-26 23:36:31 +01:00
Alejandra González
b583568e72
Add unnecessary_debug_formatting lint (#13893)
Fixes #12674, i.e., adds a lint to flag `Path`s printed with `{:?}`.

Nits are welcome.

changelog: Add `unnecessary_debug_formatting` lint
2025-02-26 15:03:57 +00:00
Alex Macleod
b821f972b6
manual_strip: use existing identifier instead of placeholder (#14188)
When the manually stripped entity receives a name as the first use
through a simple `let` statement, this name can be used in the generated
`if let Some(…)` expression instead of a placeholder.

Fix #14183

changelog: [`manual_strip`]: reuse existing identifier in suggestion
when possible
2025-02-26 14:41:41 +00:00
Samuel Moelius
6af901c51e Add unnecessary_debug_formatting lint
Address review comments

Fix adjacent code

Required now that the lint is pedantic

Add inline formatting tests

Add note re formatting changes

Address `unnecessary_map_or` warnings

Address additional review comments

Typo

Update Clippy version
2025-02-26 14:25:58 +00:00
Bryce Berger
325bfef88d
configuration option to lint incompatible_msrv in test code 2025-02-25 19:54:05 -05:00
Alejandra González
162b0e8c4a
Add todo! & unimplemented! to format macros list (#14266)
For some reason, the `todo!` and `unimplemented!` macros were not
included in the list of format-supporting macros list. Since they seem
to behave exactly the same as all others like `write!` and `assert!`,
adding them now.

I wonder if we should delete the `FORMAT_MACRO_DIAG_ITEMS`, and instead
tag all macros with the `#[clippy::format_args]`?

changelog: all format-handling lints will now validate `todo!` and
`unimplemented!` macros.
2025-02-24 22:07:35 +00:00
Alejandra González
0fb004dd56
extend obfuscated_if_else to support {then(), then_some()}.unwrap_or_else() (#14165)
These method chains can be expressed concisely with `if`/`else`.

changelog: [`obfuscated_if_else`]: support `then().unwrap_or_else()` and
`then_some().unwrap_or_else()`
2025-02-24 19:27:56 +00:00
Alex Macleod
efcf1f5730 Split needless_lifetime '_ suggestions into elidable_lifetime_names 2025-02-24 14:23:33 +00:00