Commit graph

5112 commits

Author SHA1 Message Date
Nadir Fejzic
b485832b16 style: remove dbg! call 2022-11-10 15:46:56 +01:00
Nadir Fejzic
3b4e42b91b test: add tests for 'unchecked_duration_subtraction' lint 2022-11-10 15:46:41 +01:00
bors
432baf7026 Auto merge of #9813 - Jarcho:issue_9811, r=xFrednet
Fix `explicit_auto_deref` fp

fixes #9763
fixes #9811

changelog: `explicit_auto_deref`: Don't lint when the target type is a projection with generic arguments
2022-11-09 14:06:42 +00:00
bors
b9ca3195ab Auto merge of #9791 - smoelius:issues-9739-9782, r=Jarcho
Address issues 9739 and 9782

This PR fixes #9739 in the manner I suggested in https://github.com/rust-lang/rust-clippy/issues/9739#issuecomment-1296802376.

This PR also fixes the compilation failures in #9782 (but doesn't address `@e00E's` other objections).

Fixes #9739

r? `@Jarcho`

changelog: Fix two `needless_borrow` false positives, one involving borrows in `if`-`else`s, the other involving qualified function calls
2022-11-08 14:15:40 +00:00
bors
4abe815729 Auto merge of #9765 - koka831:feat/manual_is_ascii_check, r=xFrednet
Add `manual_is_ascii_check` lint

Addresses https://github.com/rust-lang/rust-clippy/issues/9290

This PR adds new lint `manual_is_ascii_check`, which detects comparison with ascii ranges using `matches!` macros.

As I mentioned as following in the Issue;
> Yes, that's true. we'll start small and then grow it.
> So I'll try to handle matches! macro with single range as suggested above.

However during writing first version, I was thinking that the changes to support alphabetic and digits will be small patch, so I made a single PR in hope review cost can be reduced.

changelog: add new lint [`manual_is_ascii_check`]

r? `@xFrednet`
2022-11-08 09:20:52 +00:00
Jason Newcomb
5b1e445b9a Don't lint explicit_auto_deref when the target type is a projection containing a generic argument 2022-11-07 14:39:45 -05:00
Jason Newcomb
8bfc8bc5e0 Lint needless_collect on non-std collection types 2022-11-07 14:14:04 -05:00
bors
213003b887 Auto merge of #9705 - jntrnr:disable_needless_collect, r=Manishearth
Move needless_collect to nursery

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

changelog: [`needless_collect`]: Move `needless_collect` to nursery (Now allow-by-default)

After chatting with a few folks, it seems like `needless_collect` is giving false positives pretty regularly (https://github.com/rust-lang/rust-clippy/issues?q=is%3Aissue+is%3Aopen+needless_collect). We're big supporters of clippy in Nushell, and it's one of the passes we require for CI, but we've had to disable this particular lint. Perhaps it should be moved to the nursery until it's improved?

(apologies if this isn't the right approach to disabling a lint by default. I tried to follow the idea I saw other PRs doing in the past)
2022-11-07 17:08:10 +00:00
koka
e4540ad65f
feat: implement manual_is_ascii_check lint
modify

fix: allow unused in test code

fix: types in doc comment

Update clippy_lints/src/manual_is_ascii_check.rs

Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com>

Update clippy_lints/src/manual_is_ascii_check.rs

Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com>

Update clippy_lints/src/manual_is_ascii_check.rs

Co-authored-by: Fridtjof Stoldt <xFrednet@gmail.com>

fix ui test result

fix: unnecessary format!

chore: apply feedbacks

* check msrvs also for const fn
* check applicability manually
* modify documents
2022-11-07 16:39:36 +09:00
bors
d15e5e6ad6 Auto merge of #9760 - SquareMan:let_underscore_future, r=llogiq
Add new lint [`let_underscore_future`]

This closes #9721
---

changelog: add new lint [`let_underscore_future`]
2022-11-05 21:34:24 +00:00
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
Samuel Moelius
50f63a0f24 Address issues 9739 and 9782 2022-11-04 11:19:45 +00:00
koka
05006e58c0
fix turbofish in suggest message 2022-11-03 23:53:29 +09:00
bors
8d7f638816 Auto merge of #9773 - Alexendoo:ice-9746, r=Manishearth
Fix ICE in `redundant_allocation`

changelog: Fix ICE in `redundant_allocation`

Closes #9746, the original issue was fixed already, this gets the one in https://github.com/rust-lang/rust-clippy/issues/9746#issuecomment-1297132880
2022-11-02 22:05:20 +00:00
Alex Macleod
517605e1fd Fix ICE in redundant_allocation 2022-11-02 13:30:58 +00:00
Lukas Markeffsky
d35b7de1d5 shrink missing_{safety,errors,panics}_doc spans 2022-11-02 12:47:46 +01:00
bors
7600535511 Auto merge of #9743 - smoelius:improve-needless-lifetimes, r=Alexendoo
Improve `needless_lifetimes`

This PR makes the following improvements to `needless_lifetimes`.

* It fixes the following false negative, where `foo` is flagged but `bar` is not:
  ```rust
    fn foo<'a>(x: &'a u8, y: &'_ u8) {}

    fn bar<'a>(x: &'a u8, y: &'_ u8, z: &'_ u8) {}
  ```
* It flags more cases, generally. Previously, `needless_borrow` required *all* lifetimes to be used only once. With the changes, individual lifetimes are flagged for being used only once, even if not all lifetimes are.
* Finally, it tries to produce more clear error messages.

changelog: fix `needless_lifetimes` false negative involving functions with multiple unnamed lifetimes
changelog: in `needless_lifetimes`, flag individual lifetimes used only once, rather than require all lifetimes to be used only once
changelog: in `needless_lifetimes`, emit "replace with `'_`" warnings only when applicable, and point to a generic argument
2022-11-01 00:25:30 +00: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
Samuel Moelius
2c44398487 Adress review comments 2022-10-30 06:47:35 -04: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
Samuel Moelius
10b7fabbf3 Fix adjacent code 2022-10-28 13:18:07 -04:00
Samuel Moelius
e9216d836c Improve needless_lifetimes 2022-10-28 13:17:36 -04: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