Commit graph

9481 commits

Author SHA1 Message Date
lengyijun
e582fcd75d [needless_continue]: lint if the last stmt in for/while/loop is continue, recursively
fixes: #4077
2024-12-28 09:58:06 -07: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
lapla-cogito
08d8c4a67f
don't suggest to use cloned for Cow in unnecessary_to_owned 2024-12-27 21:11:25 +09: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
1cc50519d1 Merge commit '609cd310be' into clippy-subtree-update 2024-12-26 15:15:54 +01: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
Asuna
52abb8f9f0 Add new lint unneeded_struct_pattern 2024-12-15 03:59:11 +01: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
Esteban Küber
f33deb7511 Account for /// when rendering multiline spans
Don't consider `///` and `//!` docstrings to be empty for the purposes of multiline span rendering.
2024-12-13 18:48:33 +00:00
lapla-cogito
e38fa00301
address wrong suggestions when using comparing with byte literal string in single_match lint 2024-12-14 02:09:04 +09:00
llogiq
c607408df5
Fix single_match lint being emitted when it should not (#13765)
We realized when running `clippy --fix` on rustdoc (PR comment
[here](https://github.com/rust-lang/rust/pull/133537/files#r1861377721))
that some comments were removed, which is problematic. This PR checks
that comments outside of `match` arms are taken into account before
emitting the lint.

changelog: Fix `single_match` lint being emitted when it should not
2024-12-13 16:52:31 +00:00
Guillaume Gomez
efe3fe9b8c Fix single_match lint being emitted when it should not 2024-12-13 16:49:09 +01:00
Scott Gerring
db7e453124 chore: use multipart_suggestion in significant_drop_tightening lint 2024-12-13 10:41:10 +01:00
Michael Goulet
51ff984314 Stabilize async closures 2024-12-13 00:04:56 +00:00
Esteban Küber
cc9d9ccd11 Filter empty lines, comments and delimiters from previous to last multiline span rendering 2024-12-12 23:36:27 +00:00
Esteban Küber
f4db5f7bab Tweak multispan rendering
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.
2024-12-12 23:36:27 +00:00
Eric
b8cd51313e allow needless_option_take to report for more cases
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()
2024-12-11 18:53:11 -08:00
lapla-cogito
1ace535bc2
suggest modified code for if_not_else lint 2024-12-11 18:22:48 +09:00
Jason Newcomb
c2d23ad0df
Detect shadowing in pattern field (#13797)
Fix #13795

changelog: [`shadow_same`]: detect shadowing as a pattern field
2024-12-11 02:17:28 +00:00