Commit graph

5054 commits

Author SHA1 Message Date
est31
a1db9311dc Make an attempt of creating suggestions
They aren't perfect but better than nothing
2022-10-24 22:05:39 +02:00
est31
5da7a176b7 Don't suggest let else in match if the else arm explicitly mentions non obvious paths 2022-10-24 22:05:39 +02:00
est31
c5a7696231 Support tuples 2022-10-24 22:05:39 +02:00
est31
2e01e6b4c2 Also support linting for match 2022-10-24 22:05:39 +02:00
est31
f827be92fc Add lint to tell about let else pattern 2022-10-24 22:05:39 +02:00
bors
191c9839f0 Auto merge of #9690 - royrustdev:boxed_void, r=flip1995
add `from_raw_with_void_ptr` lint

This PR `fixes #9679`

- \[x] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[x] Added lint documentation
- \[x] Run `cargo dev fmt`

---

changelog:  [`from_raw_with_void_ptr`]: added new lint
2022-10-23 17:17:32 +00:00
royrustdev
b083a39190 add boxed_void lint 2022-10-23 22:43:41 +05:30
bors
628a79d6b6 Auto merge of #9368 - nahuakang:improve-equatable-if-let, r=flip1995
Improvement for  `equatable_if_let`

fixes #9221

This PR makes sure that enums or structs not implementing `PartialEq` trait but still using the `if let` patterns can be linted to be rewritten with `matches!`.

If you added a new lint, here's a checklist for things that will be
checked during review or continuous integration.

- \[ ] Followed [lint naming conventions][lint_naming]
- \[x] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[ ] Executed `cargo dev update_lints`
- \[ ] Added lint documentation
- \[x] Run `cargo dev fmt`

---

changelog: Improve [`equatable_if_let`] with additional `matches!` suggestions.
2022-10-23 15:31:46 +00:00
bors
b97d29acb7 Auto merge of #9689 - koka831:fix/or_fun_call_map_or, r=flip1995
fix: support `map_or` for `or_fun_call` lint

fixes https://github.com/rust-lang/rust-clippy/issues/8993

The methods defined in `KNOW_TYPES`, except for `map_or`, accepts only one argument, so the matching `if let [arg] = args` works only for these methods.
This PR adds `rest_arg` argument to `check_general_case` method and handling of cases with two arguments to support `map_or`.

changelog: `or_fun_call` support `map_or`

* add `rest_arg` to pass second argument from `map_or(U, F)`
* extract some procedures into closure
2022-10-23 14:23:08 +00:00
koka
a41cb7adbe
fix: support map_or for or_fun_call lint
* add `rest_arg` to pass second argument from `map_or(U, F)`
* extract some procedures into closure

refac: rename rest_arg/second_arg

refac: organize function argument order

* put `second_arg` next to `arg` argument
2022-10-23 23:20:20 +09:00
bors
3f4287ceae Auto merge of #9697 - Alexendoo:let-underscore-uplift, r=flip1995
Mark `let_underscore_lock` and `let_underscore_drop` as uplifted

Here I've renamed both the uplifted lints, however rustc's `let_underscore_lock` is slightly less capable than the clippy lint as it doesn't catch `parking_lot` types or `Result<Guard, ..>`, should we still remove it? The `Result` change looks like it was unintentional to me so that could probably be fixed upstream

changelog: Uplift [`let_underscore_drop`] to rustc https://github.com/rust-lang/rust/pull/97739
changelog: Remove overlap between rustc's `let_underscore_lock` and Clippy's [`let_underscore_lock`]

r? `@flip1995`
2022-10-23 14:11:38 +00:00
Alex Macleod
9306540f61 Remove overlap between rustc and clippy let_underscore_lock lint 2022-10-23 14:06:59 +00:00
Alex Macleod
ff893366c1 Mark let_underscore_drop as uplifted 2022-10-23 14:06:51 +00:00
bors
8e03f91036 Auto merge of #9654 - alex-semenyuk:enable_test, r=Alexendoo
Enable test no_std_main_recursion

Verified that test actually works on windows
changelog: none
2022-10-23 13:35:20 +00:00
bors
4f142aa105 Auto merge of #9622 - llogiq:box-dyn-default, r=Alexendoo
fix `box-default` ignoring trait objects' types

This avoids removing the turbofish when the `Box` type is a `dyn` or `impl _`.

This fixes #9621.

---

changelog: none
2022-10-23 11:15:19 +00:00
Alex Macleod
815876d93f Move MSRV tests into the lint specific test files 2022-10-21 21:35:39 +00:00
bors
b72e451310 Auto merge of #9684 - kraktus:ref_option_ref, r=xFrednet
`ref_option_ref` do not lint when inner reference is mutable

changelog: FP: [`ref_option_ref`]: No longer lints if the inner reference is mutable

fix https://github.com/rust-lang/rust-clippy/issues/9682
2022-10-21 20:19:30 +00:00
kraktus
487c6fc9ad [collapsible_match] specify field name when destructuring structs 2022-10-21 14:51:13 +02:00
kraktus
615b7617ed ref_option_ref do not lint when inner reference is mutable
As it makes the `Option` Non Copy
2022-10-21 13:48:41 +02:00
bors
4612fdfa7b Auto merge of #9670 - Alexendoo:missing-trait-methods, r=Jarcho
Add `missing_trait_methods` lint

Closes #9661

changelog: new lint: [`missing_trait_methods`]
2022-10-20 15:05:06 +00:00
Philipp Krones
fb8ecb9832
Merge remote-tracking branch 'upstream/master' into rustup 2022-10-20 16:39:27 +02:00
Alex Macleod
b6a860e0ed Add missing_trait_methods lint 2022-10-20 11:02:48 +00:00
bors
502e87c379 Auto merge of #9637 - Alexendoo:unused-format-specs, r=xFrednet
Add `unused_format_specs` lint

Currently catches two cases:

An empty precision specifier:

```rust
// the same as {}
println!("{:.}", x);
```

And using formatting specs on `format_args!()`:

```rust
// prints `x.`, not `x    .`
println("{:5}.", format_args!("x"));
```

changelog: new lint: [`unused_format_specs`]
2022-10-17 11:51:32 +00:00
Alex Macleod
136c2cdb91 Add unused_format_specs lint 2022-10-17 11:36:05 +00:00
bors
4eaf543b69 Auto merge of #9609 - kraktus:hexa_f32, r=giraffate
[`unnecessary_cast`] Do not lint negative hexadecimal literals when cast as floats

fix https://github.com/rust-lang/rust-clippy/issues/9603

changelog: [`unnecessary_cast`] Do not lint negative hexadecimal literals when cast as floats
2022-10-17 00:46:36 +00:00
bors
34142fdef1 Auto merge of #9652 - kraktus:octo_89, r=xFrednet
[`zero_prefixed_literal`] Do not advise to use octal form if not possible

fix https://github.com/rust-lang/rust-clippy/issues/9651

changelog: [`zero_prefixed_literal`] Do not advise to use octal form if not possible
2022-10-16 21:18:54 +00:00
bors
d917590af6 Auto merge of #9658 - TennyZhuang:partial-pub-fields, r=llogiq
Add new lint `partial_pub_fields`

Signed-off-by: TennyZhuang <zty0826@gmail.com>

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: `partial_pub_fields`: new lint to disallow partial fields of a struct be pub

Resolve #9604
2022-10-16 14:06:56 +00:00
TennyZhuang
abd5db3321 add many tests
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-16 16:59:04 +08:00
TennyZhuang
7ac97b69fc Add new lint partial_pub_fields
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-16 16:03:50 +08:00
bors
eba5ff9d05 Auto merge of #9636 - kraktus:numeric-fallback, r=dswij
[`default_numeric_fallback`] do not lint on constants

fix https://github.com/rust-lang/rust-clippy/issues/9632

changelog:[`default_numeric_fallback`] do not lint on constants
2022-10-16 05:32:19 +00:00
Andre Bogus
f8ae2f5807 fix box-default linting no_std non-boxes 2022-10-15 23:19:43 +02:00
alex-semenyuk
1450710f12 Enable test no_std_main_recursion 2022-10-15 23:52:40 +03:00
kraktus
2e3342af4a [zero_prefixed_literal] Do not advise to use octal form if not possible 2022-10-15 15:10:50 +02:00
bors
50f192f86a Auto merge of #9649 - Alexendoo:from-over-into-suggestion, r=llogiq
Add a suggestion and a note about orphan rules for `from_over_into`

Adds a machine applicable suggestion to convert the `Into` impl into a `From` one to `from_over_into`

Also adds a note explaining that `impl From<Local> for Foreign` is fine if the `Into` type is foreign

Closes #7444
Addresses half of #9638

changelog: [`from_over_into`] Add a suggestion and a note about orphan rules
2022-10-15 08:37:11 +00:00
Alex Macleod
4b8df8dc92 Add a suggestion and a note about orphan rules for from_over_into 2022-10-14 22:50:23 +00:00
Jason Newcomb
344b7bca86 Don't lint ptr_arg when used as an incompatible trait object 2022-10-14 13:21:59 -04:00
bors
4e89ffa656 Auto merge of #9640 - Alexendoo:edition-revisions, r=llogiq
Fix edition revision ui tests

#9605 had me wondering how the edition revision tests were working for `manual_assert` but not for `@nyurik,` but it turns out `manual_assert`'s tests weren't working either. I checked how `rust-lang/rust` does it and apparently it comes down to whitespace, `//[rev] edition:X` works 😬

Removes the revisions from `match_wild_err_arm` as I couldn't find any edition dependant behaviour there

r? `@llogiq`

changelog: none
2022-10-13 12:18:20 +00:00
bors
fe3200c038 Auto merge of #9584 - royrustdev:implicit_saturating_sub, r=llogiq
add tests in `implicit_saturating_sub` lint

This adds more tests to the `implicit_saturating_sub` lint to rule out certain false positives that have appeared in the past.

Now with those false positives out of the equation, we can move the lint to `style`.

---

changelog: promote [`implicit-saturating-sub`] to the `style` category
2022-10-13 12:04:23 +00:00
Alex Macleod
124caeb9a2 Fix edition revision ui tests 2022-10-13 11:40:13 +00:00
bors
42bdfa23d3 Auto merge of #9590 - nyurik:fix-parens, r=Alexendoo
Fix to_string_in_format_args in parens

Fix suggestions like

```
print!("error: something failed at {}", (Location::caller().to_string()));
```

where the parenthesis enclose some portion of the value.

Fixes #9540

changelog: [`to_string_in_format_args`]: fix incorrect fix when value is enclosed in parenthesis
2022-10-12 22:53:48 +00:00
Yuri Astrakhan
7717904043 Fix to_string_in_format_args in parens
Fix suggestions like

```
print!("error: something failed at {}", (Location::caller().to_string()));
```

where the parenthesis enclose some portion of the value.
2022-10-12 18:47:49 -04:00
kraktus
e51e9308d5 default_numeric_fallback do not lint on constants 2022-10-12 22:34:32 +02:00
bors
45dd9f31f3 Auto merge of #9627 - Jarcho:ice-9625, r=xFrednet
Use the correct type when comparing nested constants.

fixes #9625

changelog: `manual_range_contains`: fix ICE when the values are behind a reference
2022-10-12 18:49:34 +00:00
bors
b8a9a507bf Auto merge of #9617 - llogiq:cast-nan-to-int, r=Alexendoo
add `cast-nan-to-int` lint

This fixes #371.

r? `@Alexendoo`

---

changelog: add [`cast-nan-to-int`] lint
2022-10-12 11:48:30 +00:00
Andre Bogus
e4c80f2bba add cast-nan-to-int lint 2022-10-12 13:29:27 +02:00
royrustdev
ac6d2ba11e add tests in implicit_saturating_sub lint 2022-10-12 09:28:17 +05:30
Yuri Astrakhan
74ba7e1b99 Handle panic! inline_format-arg before ed2021 2022-10-11 21:27:41 -04:00
bors
8e87d39f99 Auto merge of #9572 - Nilstrieb:as-ptr-cast-mut, r=dswij
Add `as_ptr_cast_mut` lint

This lint detects calls to a `&self`-taking `as_ptr` method, where the result is then immediately cast to a `*mut T`. Code like this is probably invalid, as that pointer will not have write permissions, and `*mut T` is usually used to write through.

Examples of broken code with this pattern:
https://miri.saethlin.dev/ub?crate=lol_alloc&version=0.1.3
https://miri.saethlin.dev/ub?crate=sophon-wasm&version=0.19.0
https://miri.saethlin.dev/ub?crate=polars-core&version=0.24.2
https://miri.saethlin.dev/ub?crate=ach-cell&version=0.1.17

changelog: Add [`as_ptr_cast_mut`]
2022-10-11 08:08:17 +00:00
Jason Newcomb
0cc749296f Use the correct type when comparing nested constants. 2022-10-10 15:33:49 -04:00
Andre Bogus
bd61fdbd5f fix box-default ignoring trait objects' types 2022-10-10 21:11:37 +02:00