Commit graph

5092 commits

Author SHA1 Message Date
Steven Casper
7c5b1887c2 Bless all let_underscore tests 2022-11-04 21:21:55 -07:00
Steven Casper
398f9468df bless 2022-11-04 21:09:26 -07:00
Steven Casper
6dcade0692 Implement let_underscore_future 2022-10-31 12:50:59 -07:00
bors
37d338c1ef Auto merge of #9506 - blyxyas:master, r=giraffate
Add lint for confusing use of `^` instead of `.pow`

fixes #4205
Adds a lint named [`confusing_xor_and_pow`], it warns the user when `a ^ b` is used as the `.pow()` function, it doesn't warn for Hex, Binary... etc.

---

changelog: New lint: [`confusing_xor_and_pow`]
2022-10-31 00:28:59 +00:00
bors
00610b30f9 Auto merge of #9747 - kraktus:option_if_let_else, r=Manishearth
[`option_if_let_else`] do not lint if any arm has guard

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

changelog: [`option_if_let_else`] do not lint if any arm has guard
2022-10-30 22:46:41 +00:00
bors
10e07cc484 Auto merge of #9755 - Alexendoo:restriction-cli-warn, r=Manishearth
Warn when `clippy::restriction` is enabled via the command line

Currently it catches `#![warn(clippy::restriction)]`, it'll now catch `-W clippy::restriction` from the CLI. Also tweaks the message slightly

changelog: [`blanket_clippy_restriction_lints`]: Warn when `clippy::restriction` is enabled via the command line
2022-10-30 22:06:46 +00:00
Alex Macleod
b16a534618 Warn when clippy::restriction is enabled via the command line 2022-10-30 21:15:46 +00:00
kraktus
00cf07b521 [option_if_let_else] do not lint if any arm has guard 2022-10-29 16:44:12 +02:00
Alex Macleod
ad5dfcd123 Fix bool_to_int_with_if false positive with if let 2022-10-29 12:15:51 +00:00
bors
8e19251366 Auto merge of #9738 - kraktus:bool_to_int_with_if, r=xFrednet
[`bool_to_int_with_if`] do not lint in const context

changelog: [`bool_to_int_with_if`] do not lint in const context

fix https://github.com/rust-lang/rust-clippy/issues/9737
2022-10-29 09:29:09 +00:00
bors
fdaa425b34 Auto merge of #9648 - llogiq:fix-undocumented-unsafe-blocks, r=Jarcho
fix `undocumented-unsafe-blocks` false positive

This fixes #9142 by iterating over the parent nodes as long as within a block, expression, statement, local, const or static.

---

changelog: none
2022-10-29 01:35:49 +00:00
bors
0ab512c568 Auto merge of #9711 - smoelius:issue-9710, r=Jarcho
Fix `needless_borrow` false positive #9710

Fixes #9710

changelog: fix `needless_borrow` false positive #9710
2022-10-29 00:56:17 +00:00
Andre Bogus
e19fe89091 fix undocumented-unsafe-blocks false positive 2022-10-28 22:09:36 +02:00
Andre Bogus
7e68c718c0 fix the string-extend-chars suggestion on slice
This adds the missing `&` to the suggestion if the target is a
`str` slice (e.g. extending with `"foo"[..].chars()`).
2022-10-28 17:35:44 +02:00
Samuel Moelius
c42626f969 Fix #9710 2022-10-28 08:53:06 -04:00
kraktus
fa6850d888 [bool_to_int_with_if] do not lint in const context 2022-10-28 14:45:51 +02:00
bors
33137dd612 Auto merge of #9733 - nbdd0121:master, r=dswij
Ensure new_ret_no_self is not fired if impl Trait<Self> is returned.

Fix #7344: ensure new_ret_no_self is not fired if `impl Trait<Self>` is returned.

changelog: [`new_ret_no_self`]: No longer lints when `impl Trait<Self>` is returned
2022-10-28 06:26:49 +00:00
bors
43268141da Auto merge of #9726 - kraktus:fix_use_self, r=Alexendoo
[`use_self`] fix suggestion when full path to struct was given

Previously the following wrong suggestion was given

```rust
impl Error for std::fmt::Error {
    fn custom<T: std::fmt::Display>(_msg: T) -> Self {
-        std::fmt::Error // Should lint
+        Self::Error // Should lint
    }
}
```

Also remove known problem line related to #4140 since it's been closed, and refactor the lint

changelog: [`use_self`] fix suggestion when full path to struct was given
2022-10-27 22:08:07 +00:00
Gary Guo
92a119bc83 Add unit tests for issue 7344 2022-10-27 18:50:42 +01:00
bors
f5d225de37 Auto merge of #9722 - ebobrow:question-mark, r=Manishearth
`question_mark` don't lint on `if let Err` with `else`

cc #9518

AFAICT the only time this would be a valid suggestion is the rather esoteric

```rust
let _ = if let Err(e) = x {
    return Err(e);
} else {
    // no side effects
    x.unwrap()
}
```

which doesn't seem worth checking to me. Please correct me if I'm missing something.

changelog: [`question_mark`] don't lint on `if let Err` with `else`
2022-10-27 13:01:33 +00:00
Samuel Moelius
83771c5242 Fix needless_borrow false positive 2022-10-26 19:34:53 -04:00
kraktus
1909a6af1a [use_self] fix suggestion when full path to struct was given
Previously the following wrong suggestion was given

```rust
impl Error for std::fmt::Error {
    fn custom<T: std::fmt::Display>(_msg: T) -> Self {
-        std::fmt::Error // Should lint
+        Self::Error // Should lint
    }
}
```

Also remove known problem line related to #4140 since it's been closed, and refactor the lint
2022-10-26 18:30:32 +02:00
Rageking8
770362a691 fix dupe word typos 2022-10-26 12:24:37 +08:00
Elliot Bobrow
98250af4a3 question_mark don't lint on if let Err with else 2022-10-25 21:16:28 -07:00
bors
7182a6ba0d Auto merge of #9681 - koka831:feat/add-seek-from-current-lint, r=giraffate
feat: add new lint `seek_from_current`

changelog: `seek_from_current`: new lint to suggest using `stream_position` instead of seek from current position with `SeekFrom::Current(0)`

addresses https://github.com/rust-lang/rust-clippy/issues/7886.

This PR is related to https://github.com/rust-lang/rust-clippy/pull/9667, so I will update `methods/mod.rs` if it get conflicted.
2022-10-26 00:07:16 +00:00
Alex
32ded57779
Just lint changes 2022-10-25 20:30:37 +02:00
bors
de87e83d88 Auto merge of #9700 - andreubotella:from-raw-with-void-non-box, r=flip1995
Update `from_raw_with_void_ptr` to support types other than `Box`

This PR updates the `from_raw_with_void_ptr` lint, which covered
`Box::from_raw`, to also cover the `from_raw` static method of the
`Rc`, `Arc`, `alloc::rc::Weak` and `alloc::sync::Weak` types.

It also improves the description and error messages of this lint.

---

changelog: [`from_raw_with_void_ptr`]: Now works with the `Rc`, `Arc`, `alloc::rc::Weak` and `alloc::sync::Weak` types.
2022-10-25 07:45:32 +00:00
koka
6efb3a2b9a
feat: add new lint seek_from_current
addresses https://github.com/rust-lang/rust-clippy/issues/7886
added `seek_from_current` complexity lint.
it checks use of `Seek#seek` with `SeekFrom::Current(0)` and
suggests `Seek#stream_position` method

fix: add msrv

fix: register LintInfo

fix: remove unnecessary files

fix: add test for msrv

fix: remove

fix

fix: remove docs
2022-10-25 12:26:06 +09:00
bors
6f16596b6a Auto merge of #9704 - kraktus:fix_use_self, r=giraffate
[`use_self`] fix FP when trait impl defined in macro

changelog: [`use_self`] fix FP when trait impl defined in macro
2022-10-25 00:29:03 +00:00
bors
039af9c9e7 Auto merge of #9667 - dorublanzeanu:master, r=giraffate
add new lint `seek_to_start_instead_of_rewind `

changelog: `seek_to_start_instead_of_rewind`: new lint to suggest using `rewind` instead of `seek` to start

Resolve #8600
2022-10-25 00:14:59 +00:00
est31
dcde480a66 Also consider match guards for divergence check
Plus, add some tests for the divergence check.
2022-10-24 22:05:39 +02:00
est31
748169deaa Don't fire the lint if there is a type annotation
Sometimes type annotations are needed for type inferrence to work,
or because of coercions. We don't know this, and we also don't
want users to possibly repeat the entire pattern.
2022-10-24 22:05:39 +02:00
oxalica
01e651f2fe Don't lint if the let is already a let-else
We cannot apply the lint for 3-branches like in the added example.
2022-10-24 22:05:39 +02:00
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
Doru-Florin Blanzeanu
b9b9d6a751
Change lint name to seek_to_start_instead_of_rewind
- This name makes more sense and highlights the issue

Signed-off-by: Doru-Florin Blanzeanu <blanzeanu.doru@protonmail.com>
2022-10-24 16:31:45 +00:00
kraktus
e86e810889 [use_self] fix FP when trait impl defined in macro
Found when working on `lintcheck --fix`
2022-10-24 18:30:16 +02:00
Doru-Florin Blanzeanu
b48a4668f4
Add msrv check for rewind_instead_of_seek_to_start lint
Signed-off-by: Doru-Florin Blanzeanu <blanzeanu.doru@protonmail.com>
2022-10-24 11:00:56 +00:00
Doru-Florin Blanzeanu
8d6ce3177b
Add new lint rewind_instead_of_seek_to_start
Signed-off-by: Doru-Florin Blanzeanu <blanzeanu.doru@protonmail.com>
2022-10-24 10:43:48 +00:00
Andreu Botella
e49cde7500 Update from_raw_with_void_ptr to support types other than Box
This PR updates the `from_raw_with_void_ptr` lint, which covered
`Box::from_raw`, to also cover the `from_raw` static method of the
`Rc`, `Arc`, `alloc::rc::Weak` and `alloc::sync::Weak` types.

It also improves the description and error messages of this lint.

---

changelog: [`from_raw_with_void_ptr`]: Now works with the `Rc`, `Arc`, `alloc::rc::Weak` and `alloc::sync::Weak` types.
2022-10-24 10:51:50 +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