Commit graph

21404 commits

Author SHA1 Message Date
lapla-cogito
7aae4f462a
auto-fix for redundant_else lint 2025-01-20 08:13:01 +09: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
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
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
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
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
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
dswij
c8ba3e1d7a
use the correct ParamEnv when checking future's output type (#13863)
Fixes #13862

`missing_headers::check` is sometimes called from outside of a body
(specifically, from `check_attributes`, where the LateContext's ParamEnv
is not yet properly initialized for that item). Using that empty
ParamEnv for trait solving things from within the body can then lead to
various ICEs, like the linked issue where we have a const generic
parameter `DMA_INST` without a `ConstArgHasType` bound in the ParamEnv
so the const parameter has no type, which is normally not supposed to
happen.

We have the item's DefId so we can just get its ParamEnv/TypingEnv from
there, and using that one for trait solving should be safe.

changelog: none
2024-12-29 09:31:57 +00:00
dswij
aef47725a3
Examples fixes for regex (#13874)
Examples fixes for regex

changelog: none
2024-12-29 09:30:01 +00:00
llogiq
786f090bb9
Do not trigger trailing_empty_array in tests (#13844)
Close #13837

changelog: [`trailing_empty_array`]: do not trigger on tests
2024-12-29 00:10:58 +00:00
blyxyas
d7cc6c45c8 borrow_interior_mutable_const ICE into FN
Convert the ICE reported in #12979 into a false negative.
We prefer a false negative to a ICE (because the ICE could
still affect the user even when not activating the lint).
2024-12-28 19:42:30 +01:00
Philipp Krones
998c780126
fix arguments of ExprKind::MethodCall (#13890)
changelog: none
2024-12-28 13:47:09 +00:00
lapla-cogito
09022bbd45
fix arguments of ExprKind::MethodCall 2024-12-28 22:41:29 +09:00
Timo
a8968e5dd8
Make inconsistent_struct_constructor "all fields are shorthand" requirement configurable (#13737)
Fixes #11846.

This PR has three commits:
- The first commit adds an `initializer-suggestions` configuration to
control suggestion applicability when initializers are present. The
following are the options:
  - "none": do not suggest
- "maybe-incorrect": suggest, but do not apply suggestions with `--fix`
  - "machine-applicable": suggest and apply suggestions with `--fix`
- The second commit fixes suggestions to handle field attributes
(problem [noticed by
@samueltardieu](https://github.com/rust-lang/rust-clippy/pull/13737#discussion_r1859261645)).
- The third commit adds `initializer-suggestions = "machine-applicable"`
to Clippy's `clippy.toml` and applies the suggestions. (Nothing seems to
break.)

---

changelog: make `inconsistent_struct_constructor` "all fields are
shorthand" requirement configurable
2024-12-27 22:05:03 +00:00
Fridtjof Stoldt
363e61dcbf
remove description of known problems in match_same_arms that have already been resolved (#13873)
The "known problems" pointed out in the `match_same_arms` lint seem to
have already been resolved.

changelog: none
2024-12-27 22:03:38 +00:00
Fridtjof Stoldt
4be0e62b22
correct suggestion for manual_div_ceil lint (#13864)
fix #13843

The `manual_div_ceil` lint makes incorrect suggestion when type suffixes
need to be made explicit in the suggested code.

changelog: [`manual_div_ceil`]: suggested code now includes appropriate
type suffixes where necessary
2024-12-27 21:44:13 +00:00
Timo
553a381764
Remove obsolete comment (#13850)
`is_integer_const()` does the const folding.

changelog: none
2024-12-27 15:04:29 +00:00
Samuel Moelius
8a38bcc390 Make "all fields are shorthand" requirement configurable
Handle field attributes in suggestions

Fix adjacent code

Address review comments

https://github.com/rust-lang/rust-clippy/pull/13737#discussion_r1861352124

Address all review comments but one

This comment is not yet addressed: https://github.com/rust-lang/rust-clippy/pull/13737#discussion_r1874544907

`initializer_suggestions` -> `lint_inconsistent_struct_field_initializers`
2024-12-26 19:36:58 -05:00
Philipp Krones
609cd310be
Rustup (#13881)
r? @ghost

changelog: none
2024-12-26 13:52:31 +00:00
Philipp Krones
416f7e84c0
Bump nightly version -> 2024-12-26 2024-12-26 14:47:30 +01:00
Philipp Krones
14af404672
Merge remote-tracking branch 'upstream/master' into rustup 2024-12-26 14:46:57 +01:00
Philipp Krones
dff0294ab3
fix examples using Ty.kind() in the book (#13875)
`Ty.kind()` is a method.

changelog: none
2024-12-26 12:31:32 +00:00
lapla-cogito
b28bfbceeb
fix examples using Ty.kind() 2024-12-25 13:59:48 +09:00
llogiq
85b609419b
auto-fix if_not_else (#13809)
fix #13411

The `if_not_else` lint can be fixed automatically, but the issue above
reports that there is no implementation to do so. Therefore, this PR
implements it.

----

changelog: [`if_not_else`]: make suggestions for modified code
2024-12-24 21:45:42 +00:00
alexey semenyuk
be09596df9
Examples fixes for regex 2024-12-24 18:36:10 +05:00
lapla-cogito
887aa269b6
add more tests 2024-12-24 21:10:43 +09:00
lapla-cogito
71f1a8702d
remove known problems section from match_same_arms 2024-12-24 18:44:34 +09:00
bors
b5fe6ec47b Auto merge of #134625 - compiler-errors:unsafe-binders-ty, r=oli-obk
Begin to implement type system layer of unsafe binders

Mostly TODOs, but there's a lot of match arms that are basically just noops so I wanted to split these out before I put up the MIR lowering/projection part of this logic.

r? oli-obk

Tracking:

- https://github.com/rust-lang/rust/issues/130516
2024-12-24 00:51:51 +00:00
Alejandra González
988042e0b2
chore: multipart suggestions for let_unit_value lint (#13754)
This should address #13099 for the let_unit test.

changelog: [let_unit]: Updated let_unit to use multipart_suggestions
where appropriate
2024-12-23 14:50:01 +00:00
Timo
592fd34c1b
Fix has_iter_method documentation (#13867)
changelog: none
2024-12-23 02:21:16 +00:00