Commit graph

21243 commits

Author SHA1 Message Date
lapla-cogito
1ace535bc2
suggest modified code for if_not_else lint 2024-12-11 18:22:48 +09:00
lapla-cogito
d5059d8c1d
remove unnecessary notations 2024-12-10 00:00:51 +09: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
llogiq
ec37eb6039
Move top-level files to mod.rs when applicable (#13732)
There are two modules in `clippy_utils` that are currently in the form
of:

```
src/
  | ast_utils/
  | ty/
  |
  | ast_utils.rs
  | ty.rs
```

This PR moves the top-level modules to become `mod.rs`, within their
respective folders.

```
src/
  | ast_utils/
  |   | mod.rs
  |
  | ty/
  |   | mod.rs
```

This reduces clutter in the `src` folder, and makes it easier to find
related files in certain editors.[^0] This also appears to be the
standard used in other crates in this repository, though I looked very
briefly.

I do realize that this is a style / opinionated change, so I'll close it
if it receives much push-back. :)

[^0]: I use VSCode, which groups all folders together and all files
separately. This means that `ty.rs` is quite "far" away from the `ty/`
folder, which makes it move difficult to navigate between the two.

```
changelog: none
```

- \[x] `cargo test` passes locally
- \[x] Run `cargo dev fmt`
2024-12-08 10:43:15 +00:00
Catherine Flores
d1e1aff8c8
Update known problems for default_numeric_fallback (#13794)
The existing known problem is not actually true, and the many false
positives and false negatives should be mentioned.

Allowing the lint on a single statement:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=328de43690af13ed126f7c00c15cd695

changelog: [`default_numeric_fallback`]: update known problems docs
2024-12-08 07:12:15 +00:00
nora
0a99eec958
Update known problems for default_numeric_fallback
The existing known problem is not actually true, and the many false positives and false negatives should be mentioned.
2024-12-07 13:35:05 +01: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
Jason Newcomb
5198941bb7
chore: use multipart_suggestions for str_splitn (#13789)
This addresses #13099 for the manual_split_once test, using the
str_splitn lint.

changelog: [str_splitn]: Updated str_splitn to use multipart_suggestions
where appropriate
2024-12-06 19:44:38 +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
Alejandra González
f83a227d39
Fix various typos (#13785)
I ran [Typos](https://github.com/crate-ci/typos) on the project and
fixed all of the easy spelling mistakes! I made sure to avoid UI tests,
since those changes are more challenging to review due to the changes in
`.stderr` files.

```
changelog: Fixed several typos.
```

- \[x] `cargo test` passes locally
- \[x] Run `cargo dev fmt`
2024-12-05 21:56:21 +00:00
BD103
4907940a55 fix: various typos 2024-12-05 11:11:15 -05: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
Jason Newcomb
19426bfdfb
doc_lazy_continuation: Correctly count indent with backslashes (#13742)
changelog: [`doc_lazy_continuation`]: correctly count indent with
backslashes

Fixes #13705
2024-12-03 15:53:46 +00: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
Alejandra González
646d72a01d
Correct report_elidable_impl_lifetimes comment following #13752 (#13771)
Tiny change to make `report_elidable_impl_lifetimes`'s doc comment
consistent with #13752. (cc: @samueltardieu)

---

changelog: none
2024-12-02 20:04:47 +00:00
Samuel Moelius
4a342df09b Correct report_elidable_impl_lifetimes comment following #13752 2024-12-02 14:26:31 -05: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
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
Jason Newcomb
0a07dc5d8c
typing_env_env_for_derived_eq -> typing_env_for_derived_eq (#13769)
I'm assuming the duplicated `env` was a typo. Apologies if I've made a
mistake. (cc: @lcnr)

---

changelog: none
2024-12-02 15:30:30 +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
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
Samuel Moelius
92badb3d19 typing_env_env_for_derived_eq -> typing_env_for_derived_eq 2024-12-01 11:07:56 -05:00
Timo
0a1ba2ca07
Mention string_slice in indexing_slicing documentation (#13763)
Close #13703

changelog: none
2024-12-01 15:34:22 +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
Samuel Tardieu
ce9c4f8dd1 Mention string_slice in indexing_slicing documentation 2024-11-30 21:57:16 +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
Natsume-Neko
120b84125e Modified the tests so that if we place wrong parentheses we will get a different result 2024-11-30 14:26:47 +08:00
y21
1329547367 add targetted help messages to zombie_processes diagnostic 2024-11-30 00:38:13 +00:00
BD103
21115b3024 refactor(utils): move top-level files to mod.rs when applicable 2024-11-29 18:22:13 -05:00
Philipp Krones
af1f78af05
Update backport, release and sync documentation (#13700)
This updates the documentation after #13694. It is not based on that PR
chain and can be merged independently, but should be merged after that
PR.

This is partly pulled from #12762, but removing the Josh parts.

This includes instructions on how to publish `clippy_utils`.

Closes https://github.com/rust-lang/rust-clippy/issues/13556 (yes, this
is the final PR 🙂)

r? @blyxyas

changelog: `clippy_utils` is now published to crates.io
2024-11-29 09:27:21 +00:00
Philipp Krones
f5f2c51e70
Update backport, release and sync documentation 2024-11-29 10:16:46 +01:00
Philipp Krones
ff4a26d442
Rustup (#13746)
r? @ghost

changelog: none
2024-11-28 18:03:28 +00:00
Philipp Krones
5fb924f334
Bump Clippy version -> 0.1.85 2024-11-28 18:57:52 +01:00
Philipp Krones
3c9daca1d1
Bump nightly version -> 2024-11-28 2024-11-28 18:57:00 +01:00
Philipp Krones
b24360aa87
Merge remote-tracking branch 'upstream/master' into rustup 2024-11-28 18:56:49 +01:00
Fridtjof Stoldt
5dc5842573
Changelog for Clippy 1.83 🤖 (#13716)
This is in honor of `@bors` who is no longer used in this repo. I've
been saving this poem for a special PR, but it just seems fitting to use
it now:

Bors the bot,
Handsome and strong!
Will you go with me,
To prom?

---

### The cat of this release is Abu nominated by @jdonszelmann :

<img height=700
src="https://github.com/user-attachments/assets/414f24a1-8bbf-4fed-bcbc-acc5ca6a1353"
alt="The cats of this Clippy release" />

Cats for the next release can be nominated in the comments :D

---

changelog: none
2024-11-28 12:39:57 +00:00
Natsume-Neko
66e212b544 Extend precedence for bitmasking and shift
Changelog: extended [`precedence`] to lint for bitmasking and bit shifting without parentheses
2024-11-28 16:52:11 +08:00
Michael Howell
8dd45f18b3 doc_nested_refdefs: apply suggestions
Co-Authored-By: Jason Newcomb <jsnewcomb@pm.me>
2024-11-27 13:51:31 -07:00
Michael Howell
44feca7f3f doc_nested_refdefs: new lint for suspicious refdef syntax
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 or quote.

```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.
```
2024-11-27 13:42:04 -07:00
Jason Newcomb
b4163f08c7
[bad_bit_mask] Fix FP on proc macros (#13736)
`clap-3.1.6` was not compiling on the rustc-perf benchmarks because of
this lint. Also, the user could not allow the lint on the macro itself
because it was checking Exprs, not whatever the input of `bitflags!` is.

```
error: &-masking with zero
   --> src/build/arg_settings.rs:197:1
    |
            (#[allow] here)
197 | / bitflags! {
198 | |     struct Flags: u32 {
199 | |         const REQUIRED         ...
200 | |         const MULTIPLE_OCC     ...
...   |
226 | |     }
227 | | }
    | |_^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#bad_bit_mask
    = note: this error originates in the macro `__impl_bitflags` which comes from the expansion of the macro `bitflags` (in Nightly builds, run with -Z macro-backtrace for more info)
```

changelog:  [`bad_bit_mask`]: Fix FP on procedural macros
2024-11-27 20:31:29 +00:00
Timo
67657da671
Handle repetition of associated constant constraint as well (#13723)
changelog: [`trait_duplication_in_bounds`]: trigger on duplicate const
associated constraint as well

~~The first commit is part of #13722 which must be merged first.~~
2024-11-27 20:23:54 +00:00