Commit graph

9288 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
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
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
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
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
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
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
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
14af404672
Merge remote-tracking branch 'upstream/master' into rustup 2024-12-26 14:46:57 +01: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
lapla-cogito
887aa269b6
add more tests 2024-12-24 21:10:43 +09: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
lapla-cogito
de86302691
correct suggestion for manual_div_ceil lint 2024-12-23 01:40:51 +09: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
Oleksandr Polieno
1e0b59d6a6 Use multipart suggestion in unnecessary_to_owned 2024-12-19 07:29:18 +07:00
Alejandra González
9f4941a873
chore: starting to fix unnecessary_iter_cloned (#13848)
This will address https://github.com/rust-lang/rust-clippy/issues/13099
for the unnecessary_iter_cloned test.

changelog: [unnecessary_iter_cloned]: unnecessary_iter_cloned
manual_assert to use multipart_suggestions where appropriate
2024-12-17 23:48:16 +00:00
Philipp Krones
f8da18cdef
Do not mark attributes with unknown namespace as useless (#13766)
Fixes #13764

changelog: [`useless_attribute`]: do not trigger on attributes with
unknown namespace
2024-12-17 21:37:10 +00:00
Scott Gerring
8fe39b276f Change unnecessary_iter_cloned to use multipart_suggestion 2024-12-17 18:14:34 +01:00
Jason Newcomb
0f9cc8d58b
Don't trigger filter_map_identity with an iterator from an empty array (#13826)
fix #12653

changelog: [`filter_map_identity`]: don't lint for creating an iterator
from an empty array
2024-12-17 13:34:04 +00:00
Alexey Semenyuk
a5d5edc581 Do not trigger trailing_empty_array in tests 2024-12-17 14:16:48 +05:00
Philipp Krones
77c9dddecb
Correctly handle string indices in literal_string_with_formatting_arg (#13841)
Fixes https://github.com/rust-lang/rust-clippy/issues/13838.

r? @klensy

changelog: Correctly handle string indices in
`literal_string_with_formatting_arg`
2024-12-16 16:22:27 +00:00
Guillaume Gomez
ad695da7d2 Correctly handle string indices in literal_string_with_formatting_arg 2024-12-16 17:06:22 +01:00
llogiq
063c5c1743
correct suggestion for unnecessary_sort_by in no_std (#13836)
fix #11524

In a `no_std` environment, we can use `core::cmp::Reverse` instead of
`std::cmp::Reverse`.

----

changelog: [`unnecessary_sort_by`]: correct suggestion in `no_std`
2024-12-16 15:48:56 +00:00
lapla-cogito
1a23b5b517
correct suggestion for unnecessary_sort_by in no_std 2024-12-16 18:07:47 +09:00
llogiq
968669b00a
Do not suggest using Error in no_std before Rust 1.81 (#13834)
changelog: [`result_unit_err`]: do not suggest using `Error` in `no_std`
mode before Rust 1.81

Fix #9767
2024-12-16 05:15:20 +00:00
Alex Macleod
8da8da8428
Initial impl of repr_packed_without_abi (#13398)
Fixes #13375

I've added the lint next to the other attribute-related ones. Not sure
if this is the correct place, since while we are looking after the
`packed`-attribute (there is nothing we can do about types defined
elsewhere), we are more concerned about the type's representation set by
the attribute (instead of "duplicate attributes" and such).

The lint simply looks at the attributes themselves without concern for
the item-kind, since items where `repr` is not allowed end up in a
compile-error anyway.

I'm somewhat concerned about the level of noise this lint would cause
if/when it goes into stable, although it does _not_ come up in
`lintcheck`.

```
changelog: [`repr_packed_without_abi`]: Initial implementation
```
2024-12-16 02:17:59 +00:00
Samuel Tardieu
4c0177cbbc Do not suggest using Error in no_std before Rust 1.81 2024-12-16 00:40:50 +01:00
Lukas Lueg
7a80f7b790 Initial impl repr_packed_without_abi
Fixes #13375
2024-12-15 20:36:47 +01:00
Alejandra González
b8e569e9c0
chore: use multipart_suggestions for match_same_arms (#13803)
This addresses https://github.com/rust-lang/rust-clippy/issues/13099 for
the match_same_arms lint.

changelog: [match_same_arms]: Updated match_same_arms to use
multipart_suggestions where appropriate
2024-12-15 17:35:47 +00:00
llogiq
f1f1165053
fix must_use_unit suggestion when there're multiple attributes (#13830)
fix #12320

When there're multiple attributes, clippy suggests leaving an extra
comma and it makes an error.

changelog: [`must_use_unit`]: No longer make incorrect suggestions when
multiple attributes present.
2024-12-15 17:04:27 +00:00
Philipp Krones
12edfb82e5 Merge remote-tracking branch 'upstream/master' into rustup 2024-12-15 16:48:56 +01:00
lapla-cogito
e7c27c6774
correct suggestion for must_use_unit when there are multiple attributes 2024-12-15 20:28:38 +09:00
bors
4cddd0e935 Auto merge of #134258 - bjorn3:no_public_specialization, r=petrochenkov
Remove support for specializing ToString outside the standard library

This is the only trait specializable outside of the standard library. Before stabilizing specialization we will probably want to remove support for this. It was originally made specializable to allow a more efficient ToString in libproc_macro back when this way the only way to get any data out of a TokenStream. We now support getting individual tokens, so proc macros no longer need to call it as often.
2024-12-15 04:45:24 +00:00
Catherine Flores
62407104fb
allow needless_option_take to report for more cases (#13684)
changelog:
```
changelog: [`needless_option_take`]: now lints for all temporary expressions of type  Option<T>.
```

fixes #13671

In general, needless_option_take should report whenever take() is called
on a temporary value, not just when the temporary value is created by
as_ref().

Also, we stop emitting machine applicable fixes in these cases, since
sometimes the intention of the user is to actually clear the original
option, in cases such as `option.as_mut().take()`.
2024-12-14 19:50:55 +00:00
bjorn3
bc410fc9f5 Stop handling specialization in clippy's to_string_trait_impl lint
ToString can no longer be specialized, so no need to account for it in
to_string_trait_impl either.
2024-12-14 18:04:00 +00:00
Fridtjof Stoldt
5ac1805e76
chore: use multipart_suggestion in significant_drop_tightening lint (#13823)
This addresses https://github.com/rust-lang/rust-clippy/issues/13099 for
the significant_drop_tightening lint.

changelog: none
2024-12-14 14:46:25 +00:00
lapla-cogito
bd078ad1b5
don't lint for creating an iterator from an empty array in filter_map_identity lint 2024-12-14 22:49:49 +09:00
Matthias Krüger
503f2bc3aa Rollup merge of #134181 - estebank:trim-render, r=oli-obk
Tweak multispan rendering to reduce output length

Consider comments and bare delimiters the same as an "empty line" for purposes of hiding rendered code output of long multispans. This results in more aggressive shortening of rendered output without losing too much context, specially in `*.stderr` tests that have "hidden" comments. We do that check not only on the first 4 lines of the multispan, but now also on the previous to last line as well.
2024-12-14 03:54:31 +01:00