Commit graph

8438 commits

Author SHA1 Message Date
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
Samuel Moelius
c0d928561c Change two <= to == for clarity 2022-10-31 20:12:37 -04: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
Alex ✨ Cosmic Princess ✨
151395d74e
Update clippy_lints/src/suspicious_xor_used_as_pow.rs
Co-authored-by: NAKATA Takayuki <f.seasons017@gmail.com>
2022-10-27 21:32:36 +02:00
Gary Guo
e27e13c9ad Ensure new_ret_no_self is not fired if impl Trait<Self> is returned. 2022-10-27 18:49:07 +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
dswijj
14a34c2c61 move UNINLINED_FORMAT_ARGS to pedantic 2022-10-27 17:49:43 +08: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
64308d6292
Lints updated 2022-10-25 20:35:16 +02:00
Alex
32ded57779
Just lint changes 2022-10-25 20:30:37 +02:00
bors
5e298706f4 Auto merge of #9707 - Alexendoo:file-depinfo, r=flip1995
Track `clippy.toml` and `Cargo.toml` in `file_depinfo`

Causes cargo to re-run clippy when those paths are modified

Also tracks the path to `clippy-driver` in debug mode to remove the workarounds in `cargo dev lint` and `lintcheck` (cc `@matthiaskrgr)`

changelog: Automatically re-run Clippy if `Cargo.toml` or `clippy.toml` are modified

Fixes #2130
Fixes #8512

r? `@flip1995`
2022-10-25 12:08:46 +00:00
Alex Macleod
bd8369089c Track clippy.toml and Cargo.toml in file_depinfo
Causes cargo to re-run clippy when those paths are modified

Also tracks the path to `clippy-driver` in debug mode to remove the
workarounds in `cargo dev lint` and `lintcheck`
2022-10-25 11:32:49 +00:00
bors
9a425015c0 Auto merge of #9692 - llogiq:mutable-key-more-arcs, r=Alexendoo
make ignored internally mutable types for `mutable-key` configurable

We had some false positives where people would create their own types that had interior mutability unrelated to hash/eq. This addition lets you configure this as e.g. `arc-like-types=["bytes::Bytes"]`

This fixes #5325 by allowing users to specify the types whose innards like `Arc` should be ignored (the generic types are still checked) for the sake of detecting inner mutability.

r? `@Alexendoo`

---

changelog: Allow configuring types to ignore internal mutability in `mutable-key`
2022-10-25 11:27:33 +00: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
Andre Bogus
eba36e6d95 make arc-likes for mutable-key configurable
We had some false positives where people would create their own types
that had interior mutability unrelated to hash/eq. This addition lets
you configure this as e.g. `arc-like-types=["bytes::Bytes"]`
2022-10-25 01:51:04 +02: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
96ea5b2cd6 Fix dogfooding 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
9bd70dbb88 Make the match checking configurable 2022-10-24 22:05:39 +02:00
est31
173a8e0480 Replace from_different_macros with equivalent and simpler check 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