Commit graph

7760 commits

Author SHA1 Message Date
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
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
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
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
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
Timo
59740a8eb1
Better help message for comparison_chain lint (#13762)
changelog: [`comparison_chain`]: give explicit help message showing a
clear suggestion

Close #13739
2024-12-10 21:11:42 +00:00
Timo
2a28347897
Fix: fixed multipart_suggestion in index_refutable_slice uitest (#13727)
This should address #13099 for the derivable_impls test. As this
combines everything into a single multipart_suggestion, the feedback
message is a little less "targeted" than it was before, but now it
provides a complete`--fix`able suggestion - e.g.:

```
error: this binding can be a slice pattern to avoid indexing
  --> tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.rs:5:17
   |
LL |     if let Some(slice) = slice {
   |                 ^^^^^
   |
note: the lint level is defined here
  --> tests/ui-toml/max_suggested_slice_pattern_length/index_refutable_slice.rs:1:9
   |
LL | #![deny(clippy::index_refutable_slice)]
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: replace the binding and indexed access with a slice pattern
   |
LL ~     if let Some([_, _, _, _, _, _, _, slice_7, ..]) = slice {
LL |
LL |         // This would usually not be linted but is included now due to the
LL |         // index limit in the config file
LL ~         println!("{}", slice_7);
   |
```

changelog: [index_refutable_slice]: Fixed multipart_suggestions to
provide correct rustfix-able lint
2024-12-10 19:03:59 +00:00
Scott Gerring
7d1e0da510 chore: use multipart_suggestions for match_same_arms 2024-12-09 17:46:00 +01:00
Samuel Tardieu
f51f72b400 Detect shadowing in pattern field 2024-12-08 22:45:01 +01:00
Samuel Tardieu
69411e0e76 Better help message for comparison_chain lint 2024-12-08 20:34:00 +01:00
llogiq
c4aeb32f1d
chore: use multipart_suggestions for manual_async_fn (#13788)
This addresses #13099 for the manual_async_fn test.

changelog: [manual_async_fn]: Updated manual_async_fn to use
multipart_suggestions where appropriate
2024-12-08 16:00:54 +00:00
Jason Newcomb
7f866c7cc6
New lint for as *const _ and as *mut _ pointer casts (#13251)
changelog: New lint for as *const _ and as *mut _ pointer casts

EDIT: lets go with the simpler version
2024-12-06 20:50:33 +00:00
Soveu
149671192d new lint for as *const _ and as *mut _ casting 2024-12-06 20:44:03 +01:00
Scott Gerring
dcc4025405 chore: use multipart_suggestions for str_splitn 2024-12-06 16:04:21 +01:00
Scott Gerring
c963e22f05 chore: use multipart_suggestions for manual_async_fn 2024-12-06 15:40:50 +01:00
Jason Newcomb
a5e46a6b08
update borrow_as_ptr to suggest &raw syntax (#13689)
This PR updates the `borrow_as_ptr` lint to no longer suggest `addr_of!`
and `addr_of_mut!` and instead use the preferred `&raw const` and `&raw
mut` syntax.

Not sure about two things:
1. Do I need to set or update a MSRV for the lint anywhere?
2. There is a `borrow_as_ptr_no_std` test as well as a `borrow_as_ptr`
test. They used to be more relevant as the lint needed to select `std`
or `core`, but that is gone now, so maybe the `borrow_as_ptr_no_std`
should be deleted?

changelog: update `borrow_as_ptr` to suggest `&raw` syntax
2024-12-05 10:18:19 +00:00
cyrgani
9925f999f6 update borrow_as_ptr to suggest &raw when the MSRV allows it 2024-12-05 09:48:55 +01:00
cyrgani
c8b10ac671 fix the order of emitting ref_as_ptr and borrow_as_ptr 2024-12-05 09:46:57 +01:00
Jason Newcomb
2550530266
Extend precedence for bitmasking and shift (#13743)
Now we can lint for the expressions like `_&_>>_`, `_<<_^_`, etc. And
will suggest to add parentheses like `_&(_>>_)` and `(_<<_)^_`.
I get implementation suggestions from
[https://github.com/rust-lang/rust-clippy/pull/8735#pullrequestreview-954273477](https://github.com/rust-lang/rust-clippy/pull/8735#pullrequestreview-954273477).
changelog: extended [`precedence`] to lint for bit masking and bit
shifting without parentheses
fixes #6632
2024-12-03 15:58:06 +00:00
Scott Gerring
e493664e15 index_refutable_slice: use multipart suggestions 2024-12-03 15:29:41 +01:00
Michael Howell
d3a7fb140c doc_lazy_continuation: Correctly count indent with backslashes
changelog: [`doc_lazy_continuation`]: correctly count indent with backslashes
2024-12-02 19:05:36 -07:00
Jason Newcomb
66b15ad853
doc_nested_refdefs: new lint for suspicious list syntax (#13707)
https://github.com/rust-lang/rust/issues/133150

This is more likely to be intended as an intra-doc link than it is to be
intended as a refdef. If a refdef is intended, it does not need to be
nested within a list item.

```markdown
- [`LONG_INTRA_DOC_LINK`]: this
  looks like an intra-doc link,
  but is actually a refdef.
  The first line will seem to
  disappear when rendered as HTML.
```

> - [`LONG_INTRA_DOC_LINK`]: this
>   looks like an intra-doc link,
>   but is actually a refdef.
>   The first line will seem to
>   disappear when rendered as HTML.

changelog: [`doc_nested_refdefs`]: add suspicious lint for link def at
start of list items and block quotes
2024-12-02 18:51:02 +00:00
Manish Goregaokar
df46e4cf13
add targeted help messages to zombie_processes diagnostic (#13760)
Fixes #13748

Diagnostic for that issue with this change:
```
warning: spawned process is not `wait()`ed on in all code paths
   --> x.rs:167:19
    |
167 |     let mut cmd = cmd.unwrap();
    |                   ^^^^^^^^^^^^
    |
note: no `wait()` call exists on the code path to this early return
   --> x.rs:178:47
    |
178 |             std::io::ErrorKind::BrokenPipe => return Some(0),
    |                                               ^^^^^^^^^^^^^^
note: `wait()` call exists, but it is unreachable due to the early return
   --> x.rs:185:10
    |
185 |     Some(cmd.wait().unwrap().code().unwrap()) // <-- wait()!
    |          ^^^
    = help: consider calling `.wait()` in all code paths
    = note: not doing so might leave behind zombie processes
    = note: see https://doc.rust-lang.org/stable/std/process/struct.Child.html#warning
```
Instead of saying "wait() is **never** called", it now says it's not
called by all code paths and points out the early return in particular.

changelog: none
2024-12-02 18:42:42 +00:00
Manish Goregaokar
74dd50c653
Fix lifetimes elision suggestion in where clauses (#13752)
Fix #13749

changelog: [`needless_lifetimes`]: do not suggest using `'_` in `where`
clauses
2024-12-02 18:42:13 +00:00
Urgau
c8d800e288 Drop uplifted clippy::fn_address_comparisons 2024-12-02 18:43:37 +01:00
Alejandra González
2ddfc92ea2
Add more cases to the useless_conversion lint (#13756)
The new cases are the application of `Into::into` or `From::from`
through the following functions with no effect:
- `Option::map()`
- `Result::map()` and `Result::map_err()`
- `ControlFlow::map_break()` and `ControlFlow::map_err()`
- `Iterator::map()`

changelog: [`useless_conversion`]: detect useless calls to `Into::into`
and `From::from` application through `map*` methods
2024-12-02 15:41:25 +00:00
Samuel Tardieu
ab5d55c996 Add more receivers to useless_conversion
- `ControlFlow::map_break()`
- `ControlFlow::map_continue()`
- `Iterator::map()`
2024-12-02 16:26:51 +01:00
Jacob Pratt
5e799b25b7 Rollup merge of #133589 - voidc:remove-array-len, r=boxyuwu
Remove `hir::ArrayLen`

This refactoring removes `hir::ArrayLen`, replacing it with `hir::ConstArg`. To represent inferred array lengths (previously `hir::ArrayLen::Infer`), a new variant `ConstArgKind::Infer` is added.

r? `@BoxyUwU`
2024-12-01 22:10:23 -05:00
Catherine Flores
278e316d67
Fix needless_match FP on if-lets (#13646)
Closes #13574

Make sure that `needless_match` doesn't simplify:

```
if let Some(_) = a() {
// ..
} else let Some(_) = b() {
// ..
}
```

to:

```
a()
```

changelog: [`needless_match`]: Fix false-positive on if lets
2024-12-02 02:51:48 +00:00
Fridtjof Stoldt
1f966e98db
Add new literal_string_with_formatting_args lint (#13410)
Fixes #10195.

changelog: Added new [`literal_string_with_formatting_args`] `pedantic`
lint
[#13410](https://github.com/rust-lang/rust-clippy/pull/13410)
2024-12-01 11:46:18 +00:00
Samuel Tardieu
2b0e7bb4a7 Fix lifetimes elision suggestion in where clauses 2024-11-30 21:57:16 +01:00
Samuel Tardieu
9a692ec8cd Add more cases to the useless_conversion lint
The new cases are `x.map(f)` and `x.map_err(f)` when `f` is `Into::into`
or `From::from` with the same input and output types.
2024-11-30 21:57:16 +01:00
Dominik Stolz
a6a6936019 Remove hir::ArrayLen, introduce ConstArgKind::Infer
Remove Node::ArrayLenInfer
2024-11-30 21:00:31 +01:00
Jason Newcomb
650e0c8d3d
Fix shadow_unrelated's behaviour with closures (#13677)
Fixes https://github.com/rust-lang/rust-clippy/issues/10780

We correctly no longer give a warning when a closure is passed to a
method, where one of the arguments to that method uses the variable
which would be shadowed by an argument to that closure.
Uses is defined loosely as any expression used in the calling expression
mentions the shadowee binding (except for the closure itself):

```rust
#![deny(clippy::shadow_unrelated)]
let x = Some(1);
let y = x.map(|x| x + 1);
```
will now succeed.

See https://github.com/linebender/xilem/pull/745 - without this change,
all of the `expect(shadow_unrelated)` in the repository are met; with
it, none of them are.

changelog: [`shadow_unrelated`]: Don't treat closures arguments as
unrelated when the calling function uses them
2024-11-30 17:08:08 +00:00