Commit Graph

21394 Commits

Author SHA1 Message Date
Samuel Tardieu c686ffd193 Do not propose to elide lifetimes if this causes an ambiguity
Some lifetimes in function return types are not bound to concrete
content and can be set arbitrarily. Clippy should not propose to replace
them by the default `'_` lifetime if such a lifetime cannot be
determined unambigously.
2025-01-08 12:50:00 +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
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
Samuel Tardieu 1f8ba334a5 Fix has_iter_method documentation 2024-12-23 00:42:34 +01:00
Michael Goulet 4d735d831e Begin to implement type system layer of unsafe binders 2024-12-22 21:57:57 +00:00
lapla-cogito de86302691 correct suggestion for manual_div_ceil lint 2024-12-23 01:40:51 +09:00
Scott McMurray c772140a1f Update clippy 2024-12-22 06:12:45 -08:00
y21 15ab2ff55a use the correct ParamEnv when checking future's return type in missing_errors_doc 2024-12-21 21:09:40 +01:00
llogiq b3fadd5a8e Add allow-indexing-slicing-in-tests option (#13854)
Close #13842

changelog: [`indexing_slicing`]: add allow-indexing-slicing-in-tests
option to be able ignore at test
2024-12-19 20:11:48 +00:00
Alexey Semenyuk 6f6ddd299c Add allow-indexing-slicing-in-tests option 2024-12-20 01:06:49 +05:00
bors 54a396a9bd Auto merge of #133961 - lcnr:borrowck-cleanup, r=jackh726
cleanup region handling: add `LateParamRegionKind`

The second commit is to enable a split between `BoundRegionKind` and `LateParamRegionKind`, by avoiding `BoundRegionKind` where it isn't necessary.

The third comment then adds `LateParamRegionKind` to avoid having the same late-param region for separate bound regions. This fixes #124021.

r? `@compiler-errors`
2024-12-19 08:33:20 +00:00
Manish Goregaokar a775a1b41f Use multipart suggestion in unnecessary_to_owned (#13847)
It is related to https://github.com/rust-lang/rust-clippy/issues/13099

What was done:
- removed `@no-rustfix` from `tests/ui/unnecessary_to_owned.rs`
- checked for suggestions in `src/methods/unnecessary_to_owned.rs`
(there is already one multipart_suggestion, and I don't see any other)
- ran `cargo uibless`

I am new to Rust, and this is my first PR.

changelog: none
2024-12-19 01:25:29 +00:00
Oleksandr Polieno 1e0b59d6a6 Use multipart suggestion in unnecessary_to_owned 2024-12-19 07:29:18 +07:00