Commit graph

9601 commits

Author SHA1 Message Date
Philipp Krones
0730678e26
Make annotations mandatory for internal ui tests (#14393)
Last part of https://github.com/rust-lang/rust-clippy/pull/11421.

Now all ui tests require annotations.

The change in `ui_test` is to add `ICE:` errors.

changelog: Make internals ui tests annotations mandatory

r? @flip1995
2025-03-12 11:01:24 +00:00
Guillaume Gomez
092a20ec11 Update lint_message_convention test to allow clippy "help" message 2025-03-12 11:41:26 +01:00
Guillaume Gomez
ec8c0b3755 Make annotations mandatory for internal ui tests 2025-03-12 11:32:40 +01:00
Guillaume Gomez
cfc743226e Update ui_test version to 0.29.2 2025-03-12 11:29:54 +01:00
Alex Macleod
714c64c7a1
fix: unnecessary_safety_comment FP on desugared assign (#14371)
Closes #13039

changelog: [`unnecessary_safety_comment`]: fix FP on desugared assign
2025-03-12 02:27:43 +00:00
Philipp Krones
8f280ff813
Add missing tests annotations for ui-internal (#14388)
Follow-up of https://github.com/rust-lang/rust-clippy/pull/11421.

I can't yet make the annotations mandatory because there is an issue
with `tests/ui-internal/custom_ice_message.rs`: the error message is not
emitted as JSON, meaning that we can't match it with `ui_test`. I need
to check if it's a bug in rustc or if `ui_test` needs to handle this
case somehow.

changelog: Add missing tests annotations for `ui-internal`

r? @flip1995
2025-03-11 16:10:14 +00:00
Guillaume Gomez
cb9682b628 Add missing tests annotations for ui-internal 2025-03-11 16:35:11 +01:00
Philipp Krones
a25cbd50ca
Improve needless_pass_by_value suggestion (#13880)
Fixes https://github.com/rust-lang/rust-clippy/issues/13744.

A simple check to check if the type is an `Option` allows to improve the
suggestion.

changelog: Improve `needless_pass_by_value` suggestion
2025-03-10 15:48:43 +00:00
yanglsh
97275d523c fix: unnecessary_safety_comment FP on desugared assign 2025-03-10 12:36:37 +08:00
Timo
819f3c7c67
arbitrary_source_item_ordering: Make alphabetic ordering in module item groups optional (#13718)
From feedback to the `arbitrary_source_item_ordering` lint after its
inclusion in clippy 1.82, making alphabetic ordering within module item
groups has turned out to be the most requested improvement. With this
improvement, it is possible to make the lint perform certain top-level
structural checks on modules (e.g. use statements and module inclusions
at the top), but still leaving everything else up to the developer.

Implements parts of the suggestions from #13675. A catch-all-group is
still to be implemented.

changelog: [`arbitrary_source_item_ordering`]: Make alphabetic ordering
in module item groups optional (off by default)
2025-03-09 20:25:30 +00:00
Manish Goregaokar
1b628853fa
don't trigger blocks_in_conditions when the condition contains a return (#14338)
fixes #9911

changelog: [`blocks_in_conditions`]: don't trigger the lint when the
condition contains a `return`
2025-03-09 00:07:14 +00:00
Guillaume Gomez
c8e47f9a72 Update needless_pass_by_value stderr 2025-03-08 21:14:11 +01:00
Guillaume Gomez
79013f813d Improve needless_pass_by_value suggestion 2025-03-08 21:08:04 +01:00
lapla-cogito
243e0ee274
don't trigger blocks_in_conditions when the condition contains a return 2025-03-08 16:57:06 +09:00
dswij
f83c94cb3a
fix: manual_let_else missing binding mode (#14204)
fixes #13768

The existing implemention forgets to handle the binding mode (i.e. `ref`
and `ref mut`), so I just modified it to cover these cases.

changelog: [`manual_let_else`]: fix missing binding mode
2025-03-08 05:15:11 +00:00
Catherine Flores
81643e297c
unnecessary_to_owned: don't call iter() on a temporary object (#14243)
fix #14242

changelog: [`unnecessary_to_owned`]: don't call `iter` on a temporary
object
2025-03-05 23:17:32 +00:00
lapla-cogito
06f797d3f7
don't call iter() on a temporary object in unnecessary_to_owned 2025-03-06 07:55:01 +09:00
Catherine Flores
231bf457ba
Make struct_field_names check private fields of public structs. (#14076)
Currently, If a struct is `pub` and its field is private, and
`avoid-breaking-exported-api = true` (default), then
`struct_field_names` will not lint the field, even though changing the
field’s name is not a breaking change. This is because the
breaking-exported-api condition was checking the visibility of the
struct, not its fields (perhaps because the same code was used for
enums). With this change, Clippy will check the field’s effective
visibility only.

Note: This change is large because some functions were moved into an
`impl` to be able to access more configuration. Consider viewing the
diff with whitespace ignored.

changelog: [`struct_field_names`]: also check private fields of public
structs
2025-03-05 22:38:15 +00:00
Thalia Archibald
e8cd3d4752 Use size_of from the prelude instead of imported
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the
prelude instead of importing or qualifying them.

These functions were added to all preludes in Rust 1.80.
2025-03-05 00:37:40 -08:00
llogiq
9538e5bcd0
Walk back to the root context to compute the span (#14349)
Since the error kind (`io::ErrorKind::other`) is in the root context,
the error message must be found in the root context as well to compute
the correct span to remove.

Fix #14346

changelog: [`io_error_other`]: fix non-applicable suggestion

r? @llogiq
2025-03-05 05:52:19 +00:00
Kevin Reid
2067375697 Make struct_field_names lint on private fields of public structs.
Currently, If a struct is `pub` and its field is private, and
`avoid-breaking-exported-api = true` (default), then `struct_field_names`
will not lint the field, even though changing the field’s name is not a
breaking change. This is because the breaking-exported-api condition was
checking the visibility of the struct, not its fields (perhaps because
the same code was used for enums). With this change, Clippy will check
 the field’s effective visibility only.

Note: This change is large because some functions were moved into an
`impl` to be able to access more configuration. Consider viewing the
diff with whitespace ignored.
2025-03-04 10:49:13 -08:00
Catherine Flores
2440f51696
don't trigger unnecessary_debug_formatting in tests (#14347)
close #14345

changelog: [`unnecessary_debug_formatting`]: don't lint in tests
2025-03-04 16:35:09 +00:00
Alex Macleod
dd8cf052c2
better help for mixed_case_hex_literals (#14235)
It can be error-prone for developers to manually change literals with
mixed uppercase and lowercase letters into consistently all-lowercase or
all-uppercase literals. Therefore, this lint rule should suggest
alternative literals.

changelog: [`mixed_case_hex_literals`]: add alternative suggestions
2025-03-04 14:10:44 +00:00
Samuel Tardieu
9275ae994b Walk back to the root context to compute the span
Since the error kind (`io::ErrorKind::other`) is in the root context,
the error message must be found in the root context as well to compute
the correct span to remove.
2025-03-04 12:00:38 +01:00
decryphe
5df68878bf Make alphabetic ordering in module item groups configurable (new default: off)
From feedback to this lint after its inclusion in clippy 1.82, this has
turned out to be the most requested improvement. With this improvement,
it is possible to make the lint check certain top-level structural
checks on modules (e.g. use statements and module inclusions at the top),
but still leaving everything else up to the developer.
2025-03-04 09:50:47 +01:00
lapla-cogito
e6a4cf63ad
don't trigger unnecessary_debug_formatting in tests 2025-03-04 17:46:15 +09:00
lapla-cogito
e587a5d0f0
better help for mixed_case_hex_literals 2025-03-04 17:43:14 +09: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
yanglsh
68679f295f fix: manual_let_else missing binding mode 2025-03-03 13:02:44 +08: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
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
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
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