Commit graph

21786 commits

Author SHA1 Message Date
Samuel Tardieu
c9315bc395 Use diagnostic item instead of path for core::fmt::Debug
This removes the last call to `LateContext::match_def_path()` in
Clippy's code. The `LateContext::match_def_path()` in the compiler
sources was only kept for Clippy's usage.
2025-01-05 22:13:42 +01:00
Alexey Semenyuk
ca55534c92 Do not trigger clippy::missing_const_for_fn triggering for tests 2025-01-06 02:07:16 +05:00
lapla-cogito
39269aaaae
auto-fix slow_vector_initialization 2025-01-05 21:53:12 +09:00
Fridtjof Stoldt
ad69c65906
Only emit useless_vec suggestion if the macro does not contain code comments (#13911)
Fixes #13692.

If the `vec!` macro call contains comments, we should not provide
suggestions and let users handle it however they see fit.

changelog: Only emit `useless_vec` suggestion if the macro does not
contain code comments
2025-01-04 23:33:30 +00:00
Samuel Tardieu
12d3137560 CI: be compatible with both Rustup pre-1.28.0 and 1.28.0
`rustup show active-toolchain` will no longer install the default
toolchain starting from Rustup 1.28.0, and `rustup toolchain install`
without extra arguments is not supported in Rustup pre-1.28.0.
2025-01-04 23:12:32 +01:00
Alejandra González
54f88c3c75
[needless_continue]: lint if the last stmt in loop is continue recurisvely (#13891)
fixes: #4077

Continuation of #11546. r? @y21 if you don't mind?

changelog: [`needless_continue`] lint if the last stmt in loop is
`continue` recurisvely
2025-01-04 21:52:42 +00:00
Fridtjof Stoldt
622382b6c6
Fix year in CHANGELOG.md
copy-pasta got the better of me xD 🍝

Co-authored-by: Samuel Tardieu <sam@rfc1149.net>
2025-01-04 22:28:51 +01:00
Jubilee
5262111eba Rollup merge of #135046 - RalfJung:rustc_box_intrinsic, r=compiler-errors
turn rustc_box into an intrinsic

I am not entirely sure why this was made a special magic attribute, but an intrinsic seems like a more natural way to add magic expressions to the language.
2025-01-04 07:57:33 -08:00
Ralf Jung
f416f266b0 turn hir::ItemKind::Fn into a named-field variant 2025-01-04 11:35:31 +01:00
Guillaume Gomez
b76e0426a1 Add regression test for useless_vec with code comments 2025-01-03 22:55:25 +01:00
Guillaume Gomez
1b85ae3a60 Only emit useless_vec suggestion if the macro does not contain code comments 2025-01-03 22:55:25 +01:00
xFrednet
4e4a2d022b
Changelog for Clippy 1.84 🧨 2025-01-03 19:40:39 +01:00
xFrednet
4736004c2c
Update version attribute for 1.84 clippy lints 2025-01-03 19:39:32 +01:00
alexey semenyuk
05cb1ce0ef Fix not found links at Book 2025-01-03 20:46:44 +05:00
Ralf Jung
ad36f2b053 turn rustc_box into an intrinsic 2025-01-03 12:01:31 +01:00
Alejandra González
7a01033797
Make CI a little bit safer (#13933)
This PR fixes two vulnerabilities in our CI, found with
[zizmor](https://github.com/woodruffw/zizmor). One could be exploited by
someone with tag-pushing permissions to execute arbitrary code in our CI
(see`deploy.yml`). The second vulnerability would expose our tokens to a
supply chain attack via a `build.rs` in one of the dependencies (See the
rest of the files, and https://github.com/actions/checkout/issues/485)

Pre-reviewed by @flip1995 in our DMs.

changelog:none
2025-01-03 00:06:49 +00:00
blyxyas
7ac151508e Make CI a little bit safer 2025-01-03 00:44:35 +01:00
Samuel Tardieu
9c46e1173f Remove unneeded parentheses in unnecessary_map_or lint output
When the expression is transformed into an equality, parentheses are
needed only if the resulting equality is used:

- as a receiver in a method call
- as part of a binary or unary expression
- as part of a cast

In other cases, which will be the majority, no parentheses are required.
This makes the lint suggestions cleaner.
2025-01-03 00:32:46 +01:00
Manish Goregaokar
631d9a2c5c
Add lint for calling Iterator::last() on DoubleEndedIterator (#13922)
I [recently realized that `.last()` might not call `next_back()` when it
is
available](https://qsantos.fr/2025/01/01/rust-gotcha-last-on-doubleendediterator/).
Although the implementor could make sure to implement `last()` to do so,
this is not what will happen by default. As a result, I think it is
useful to add a lint to promote using `.next_back()` over `.last()` on
`DoubleEndedIterator`.

If this is merged, we might want to close #1822.

changelog: [`double_ended_iterator_last`]: Add lint for calling
`Iterator::last()` on `DoubleEndedIterator`
2025-01-02 18:30:38 +00:00
alexey semenyuk
a7c2e4d750 Fix link to release tags 2025-01-02 22:41:44 +05:00
yanglsh
f18399fb69 Emit redundant if when duplicated in needless_continue 2025-01-02 07:45:16 -07:00
Quentin Santos
d67c00f723 Dogfood double_ended_iterator_last 2025-01-01 22:19:16 +01:00
Quentin Santos
0d213aa09a Revert "Dogfood double_ended_iterator_last"
This reverts commit 09c5d34f98.
2025-01-01 22:16:33 +01:00
Quentin Santos
7331cc0f81 Only complain about default Iterator::last() 2025-01-01 22:16:07 +01:00
Quentin Santos
27acfd8a5b Prefer if chain to let-else 2025-01-01 20:33:58 +01:00
Alejandra González
034f3d224c
Improve slow_vector_initialization suggestion (#13912)
close #13781

The `slow_vector_initialization` lint currently only suggests using the
`vec!` macro with size, but it does not suggest removing the `resize`
method call.

changelog: [`slow_vector_initialization`]: improve
`slow_vector_initialization` suggestion
2025-01-01 19:21:01 +00:00
Quentin Santos
09c5d34f98 Dogfood double_ended_iterator_last 2025-01-01 19:47:22 +01:00
Quentin Santos
458c955ae3 Fix conflicts with double_ended_iterator_last 2025-01-01 18:58:53 +01:00
Quentin Santos
707653f268 Add lint for calling last() on DoubleEndedIterator 2025-01-01 18:47:23 +01:00
Alejandra González
33a6590ce1
Check if deref target implements is_empty for len_zero lint (#13871)
In this case, the lint can be triggered as well as `is_empty()` will be
found on the target type.
One such case was found in Clippy sources (first commit)

changelog: [`len_zero`]: trigger if deref target implements `is_empty()`

Close #13861
2025-01-01 15:09:26 +00:00
Samuel Tardieu
4c9c2cca2b Check if deref target implements is_empty for len_zero lint
In this case, the lint can be triggered as well as `is_empty()` will be
found on the target type.
2025-01-01 14:14:39 +01:00
Max Niederman
54e5116b44 cover guard patterns in clippy lints 2024-12-31 17:59:34 -08:00
Matthias Krüger
8275f42350 add more test coverage for #11230
Closes #11230

changelog: nonew.
2024-12-31 17:02:29 +01:00
A_A
3bc089e9fe refactor manual_is_ascii_check to remove unused parameter 2024-12-31 14:18:43 +01:00
dswij
c52740c87b
add test for ICE (#13914)
`asked to assemble constituent types of unexpected type: Binder(Foo,
[])`

Fixes #10972

changelog: none
2024-12-31 12:51:00 +00:00
A_A
2a4dadd985 fix type suggestion for manual_is_ascii_check (#13913) 2024-12-31 13:48:08 +01:00
Matthias Krüger
1e0b782a63 add test for ICE
`asked to assemble constituent types of unexpected type: Binder(Foo, [])`

Fixes #10972
2024-12-31 12:00:19 +01:00
lapla-cogito
4899333886
better suggestion for slow_vector_initialization 2024-12-31 16:07:06 +09:00
Manish Goregaokar
7a834b5d3a
Use the full lifetime name in suggestions (#13907)
Using `lifetime.ident.name` in suggestions will not output the raw
modifier. For example, `'r#struct` will be rendered as `'struct` which
would be incorrect.

Fix #13899

changelog: [`needless_arbitrary_self_type`]: use the raw lifetime name
in suggestions
2024-12-30 17:57:59 +00:00
Timo
2aea7a080d
Fix parentheses when replacing matches!(…, None) with .is_none() (#13906)
Proper parentheses need to be added to some expressions in receiver
position.

Fix #13902

changelog: [`redundant_pattern_matching`]: use proper parentheses when
suggesting replacing `matches!(…, None)` by `.is_none()`
2024-12-30 14:06:30 +00:00
Timo
be49f8613a
Move more def paths into clippy_utils::paths (#13903)
I discovered that there were paths declared in `clippy_utils::paths` in
https://github.com/rust-lang/rust-clippy/pull/13829 so moving a few
remaining hardcoded ones in one place.

changelog: Move more def paths into `clippy_utils::paths`

r? @y21
2024-12-30 13:50:09 +00:00
Guillaume Gomez
b515064fd2 Correctly handle char paths 2024-12-30 12:28:47 +01:00
Samuel Tardieu
a657fcc89a Use the full lifetime name in suggestions
Using `lifetime.ident.name` in suggestions will not output the raw
modifier. For example, `'r#struct` will be rendered as `'struct` which
would be incorrect.
2024-12-30 00:07:18 +01:00
Samuel Tardieu
e4b11a7266 Fix parentheses when replacing matches!(…, None) with .is_none() 2024-12-29 23:25:59 +01:00
Samuel Tardieu
a9fe04335a Do not remove identity mapping if mandatory mutability would be lost
Removing `.map(identity)` may result in invalid code if the receiver of
`map()` is an immutable binding, and the result of `map()` is used as
the receiver of a method call expecting a mutable reference.
2024-12-29 23:01:14 +01:00
Guillaume Gomez
34b1765e65 Move more def paths into clippy_utils::paths 2024-12-29 20:39:43 +01:00
Alejandra González
b57d98b00e
Do not remove required parentheses in borrow_as_ptr suggestion (#13884)
Also, simplify boolean shortcut expression, and ensure that
applicability is properly applied, as it was ignored and
`MachineApplicable` was always used.

changelog: [`borrow_as_ptr`]: do not remove required parentheses in
autofix suggestion

Close #13882
2024-12-29 16:29:53 +00:00
Fridtjof Stoldt
f5f1abd8fb
borrow_interior_mutable_const ICE into FN (#13877)
This PR just makes sure that we exit the function before getting an ICE
and adds a regression test. Related to #12979. We would need to keep
researching the issue, but as the ICEing code isn't that complicated,
getting a hotfix into nightly is urgent.

changelog:[`borrow_interior_mutable_const`] Fix ICE #12979
2024-12-29 15:52:35 +00:00
Samuel Tardieu
eef47fc0b7 Do not remove required parentheses in borrow_as_ptr suggestion
Also, simplify boolean expression, and ensure that proper applicability
is used.
2024-12-29 16:50:05 +01:00
Samuel Moelius
a7adb8217e Move format_push_string and format_collect to pedantic 2024-12-29 07:44:06 -05:00