Commit graph

6692 commits

Author SHA1 Message Date
bors
5d70746251 Auto merge of #9920 - naosense:suppress_lint_in_const, r=xFrednet
add `suppress_restriction_lint_in_const` config

According to #9808 , add a new lint `suppress_lint_in_const` to report even in const context. BTW, i am not good at naming either, if anyone have a better idea, i am happy to change it.

This PR is still in progress, so i keep it draft.

- \[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: Enhancement: [`indexing_slicing`]: add new config `suppress-restriction-lint-in-const` to enable restriction lints, even if the suggestion might not be applicable

r? `@xFrendet`
2022-12-06 18:43:28 +00:00
Lukas Wirth
20ec2ceab8 Add test case for blocks with semicolon inside and outside a block 2022-12-05 11:02:10 +01:00
bors
cb8df45333 Auto merge of #10027 - smoelius:fix-10021, r=dswij
Fix 10021

This PR proposes a fix for #10021.

The problem is similar to the one that `@mikerite` described in #9505. The compiler is generating an empty substitution for a call, even though the type of `Self` seems to be needed for a predicate. In `@mikerite's` case, the call was to [`IntoFuture::into_future`](https://doc.rust-lang.org/std/future/trait.IntoFuture.html#tymethod.into_future). In this case, the call is to [`Try::branch`](https://doc.rust-lang.org/std/ops/trait.Try.html#tymethod.branch).

The proposed fix is to verify that the parameter whose type is changing has an index within the substitution. The strikes me as a reasonable approach, since if the check were to fail, the following code would be a no-op:

4c123a06ba/clippy_lints/src/methods/unnecessary_to_owned.rs (L420-L428)

Like `@mikerite's` original solution, this solution turns ICEs into false negatives.

changelog: fix `unnecessary_to_owned` false positive involving `Try::branch`
2022-12-04 01:58:43 +00:00
naosense
eec5039f09 fix test 2022-12-03 16:06:57 +08:00
Samuel Moelius
cb420080ac Add test for #10021 2022-12-02 20:48:18 -05:00
Jason Newcomb
6ba2cda79a Fix zero_ptr suggestion for no_std crates 2022-12-02 15:36:17 -05:00
bors
38fce1235a Auto merge of #10022 - Jarcho:issue_10019, r=giraffate
Don't lint `implicit_clone` when the type doesn't implement clone

fixes #10019
changelog: `implicit_clone`: Don't lint when the type doesn't implement clone
2022-12-02 07:17:13 +00:00
bors
56d5657880 Auto merge of #9962 - mdgaziur:master, r=dswij
Fix #9958

This PR fixes #9958. In order to fix the issue, the lint will now peel reference operators and enclose the expression with parentheses when necessary.

changelog: [`comparison_to_empty`]: Peel deref operators in suggestions when necessary
2022-12-02 05:49:26 +00:00
bors
b43c9f7638 Auto merge of #9982 - Jarcho:issue_9935, r=flip1995
Don't lint `from_over_into` for opaque types

fixes #9935

This is stalled until the next sync. The impl in question can't be written on the pinned nightly.

changelog: Don't lint `from_over_into` for opaque types
2022-12-02 04:31:55 +00:00
bors
a1d22808af Auto merge of #104963 - petrochenkov:noaddids2, r=cjgillot
rustc_ast_lowering: Stop lowering imports into multiple items

Lower them into a single item with multiple resolutions instead.
This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-12-02 04:24:57 +00:00
Jason Newcomb
ab8c6beb85 Don't lint implicit_clone when the type doesn't implement clone 2022-12-01 23:05:53 -05:00
bors
fec00573a5 Auto merge of #10013 - Jarcho:issue_9886, r=Manishearth
Don't lint `manual_assert` in `else if`

fixes #9886
changelog: `manual_assert`: Don't lint in `else if`
2022-12-01 22:49:40 +00:00
Jason Newcomb
47fb67fa08 Don't lint manual_assert in else if 2022-12-01 17:37:18 -05:00
bors
e16a8b93ba Auto merge of #10008 - Jarcho:issue_9882, r=Manishearth
Treat custom enum discriminant values as constants

fixes #9882
changelog: All lints: Don't lint in enum discriminant values when the suggestion won't work in a const context
2022-12-01 22:37:15 +00:00
bors
be0eb20fff Auto merge of #10006 - Jarcho:issue_9890, r=Manishearth
Don't suggest removing `mut` from references in `redundant_static_lifetimes`

fixes #9890
changelog: `redundant_static_lifetimes`: Don't suggest removing `mut` from references
2022-12-01 22:25:38 +00:00
bors
53e1b45137 Auto merge of #9966 - alex-semenyuk:manual_let_else_paren, r=xFrednet
Fix manual_let_else produces a wrong suggestion with or-patterns

Fix #9938
changelog: Sugg: [`manual_let_else`]: Suggestions for or-patterns now include required brackets.
[#9966](https://github.com/rust-lang/rust-clippy/pull/9966)
2022-12-01 22:11:01 +00:00
Jason Newcomb
a21b5b25f6 Don't lint string_lit_as_bytes in match scrutinees 2022-12-01 14:52:41 -05:00
alex-semenyuk
05477ff8df Fix manual_let_else produces a wrong suggestion with or-patterns 2022-12-01 22:05:06 +03:00
Philipp Krones
d05e2865a0 Merge commit 'd822110d3b5625b9dc80ccc442e06fc3cc851d76' into clippyup 2022-12-01 18:29:38 +01:00
Jason Newcomb
6ecdff07e5 Don't lint from_over_into for opaque types 2022-12-01 11:51:31 -05:00
Vadim Petrochenkov
b0d490e308 rustc_ast_lowering: Stop lowering imports into multiple items
Lower them into a single item with multiple resolutions instead.
This also allows to remove additional `NodId`s and `DefId`s related to those additional items.
2022-12-01 18:51:20 +03:00
Philipp Krones
11434f270f
Merge remote-tracking branch 'upstream/master' into rustup 2022-12-01 12:55:15 +01:00
bors
641ced4eb9 Auto merge of #10007 - Jarcho:issue_10005, r=giraffate
Fix ICE in `result_large_err` with uninhabited enums

fixes #10005
changelog: `result_large_err`: Fix ICE with uninhabited enums
2022-12-01 07:20:06 +00:00
Jason Newcomb
a1b15f13f7 Treat custom enum discriminant values as constants 2022-11-30 22:34:42 -05:00
Jason Newcomb
7ae5c81e9f Fix ICE in result large_err with uninhabited enums 2022-11-30 21:44:18 -05:00
Jason Newcomb
55096eab0f Don't suggest removing mut from references in redundant_static_lifetimes 2022-11-30 21:29:48 -05:00
Jason Newcomb
03ba0ea400 Don't suggest keeping borrows in identity_op 2022-11-30 16:25:57 -05:00
bors
ee12b12be5 Auto merge of #9943 - dswij:pr-9940, r=Jarcho
manual_let_else: keep macro call on suggestion blocks

Closes #9940

changelog: [`manual_let_else`]: Do not expand macro calls on suggestions
2022-11-30 21:23:10 +00:00
bors
1cdb06d406 Auto merge of #10001 - Jarcho:issue_9866, r=llogiq
Fix ICE in `unused_rounding`

fixes #9866
changelog: `unused_rounding`: Fix ICE when using the `_` separator
2022-11-30 19:54:25 +00:00
bors
846c9b8170 Auto merge of #9996 - Jarcho:issue_9906, r=Alexendoo
Fix `unnecessary_cast` suggestion when taking a reference

fixes #9906
changelog: `unnecessary_cast`: Fix suggestion when taking a reference
2022-11-30 19:40:22 +00:00
bors
d7d098a7e6 Auto merge of #9997 - Jarcho:issue_9901, r=llogiq
Don't lint `explicit_auto_deref` when the initial type is neither a reference, nor a receiver

fixes #9901
fixes #9777
changelog: `explicit_auto_deref`: Don't lint when the initial value is neither a reference, nor a receiver
2022-11-30 19:29:40 +00:00
Jason Newcomb
c1b8bc66e9 Fix ICE in unused_rounding 2022-11-30 12:46:06 -05:00
bors
87963f03ba Auto merge of #9987 - Jarcho:issue_9957, r=flip1995
Don't cross contexts while building the suggestion for `redundant_closure_call`

fixes #9957

changelog: `redundant_closure_call`: Don't cross macro contexts while building the suggestion
2022-11-30 16:31:56 +00:00
Jason Newcomb
2d32b40359 Don't lint explicit_auto_deref when the initial type is neither a reference, nor a receiver 2022-11-30 11:23:01 -05:00
Jason Newcomb
73f4546d24 Fix unnecessary_cast suggestion when taking a reference 2022-11-30 10:55:48 -05:00
Jason Newcomb
e0eba9cafc Don't cross contexts while building the suggestion for redundant_closure_call 2022-11-30 10:53:27 -05:00
mdgaziur
7a0f0c0e8b
Fix #9958 2022-11-30 19:42:50 +06:00
bors
78589ffad2 Auto merge of #9989 - xFrednet:9986-move-safety-thingy, r=flip1995
Move `unnecessary_unsafety_doc` to `pedantic`

This lint was added in #9822. I like the idea, but also agree with #9986 as well. I think it should at least not be warn-by-default. This is one of these cases, where I'd like a group between pedantic and restriction. But I believe that users using `#![warn(clippy::pedantic)]` will know how to enable the lint if they disagree with it.

---

Since the lint is new:

changelog: none

r? `@flip1995` since I'd suggest back porting this, the original PR was merged 16 days ago.

Closes: #9986 (While it doesn't address everything, I believe that this is the best compromise)
2022-11-30 12:44:45 +00:00
xFrednet
cc43c3d25d
Move unnecessary_unsafety_doc to pedantic 2022-11-30 12:59:50 +01:00
bors
4cda21dc42 Auto merge of #9981 - Jarcho:issue_9954, r=flip1995
Don't lint `unnecessary_operation` in mixed macro contexts

fixes #9954

changelog: `unnecessary_operation`: Don't lint in mixed macro contexts.
2022-11-29 09:49:46 +00:00
naosense
67a94135cb change note style 2022-11-29 15:00:51 +08:00
naosense
1fc98c51df change default value 2022-11-29 15:00:51 +08:00
naosense
4528aec7e9 update config and suggest 2022-11-29 15:00:51 +08:00
naosense
aed9497978 add test and stderr 2022-11-29 15:00:51 +08:00
Jason Newcomb
f44b7aa81e Don't lint unnecessary_cast in mixed macro context 2022-11-28 23:58:02 -05:00
Jason Newcomb
0893322e54 Don't lint unnecessary_operation in mixed macro contexts 2022-11-28 23:56:02 -05:00
bors
12074808c7 Auto merge of #9865 - nyurik:allow-mixed, r=xFrednet
Add allow-mixed-uninlined-format-args config

Implement `allow-mixed-uninlined-format-args` config param to change the behavior of the `uninlined_format_args` lint. Now it is a part of `style` per [Zulip chat](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/.60uninlined_format_args.60.20category), and won't propose inlining in case of a mixed usage, e.g. `print!("{} {}", var, 1+2)`. If the user sets `allow-mixed-uninlined-format-args` config param to `false`, the lint would behave like it did before -- proposing to inline args even in the mixed case.

---

changelog: [`uninlined_format_args`]: Added a new config `allow-mixed-uninlined-format-args` to allow the lint, if only some arguments can be inlined
[#9865](https://github.com/rust-lang/rust-clippy/pull/9865)
changelog: Moved [`uninlined_format_args`] to `style` (Now warn-by-default)
[#9865](https://github.com/rust-lang/rust-clippy/pull/9865)
2022-11-28 17:22:36 +00:00
Esteban Küber
fc108d4b61 fix clippy tests 2022-11-28 00:41:31 -08:00
bors
c8eba8e4a1 Auto merge of #9967 - koka831:fix/9416, r=llogiq
Remove blank lines when needless_return returns no value

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

changelog: [`needless_return`] improve result format

r? `@llogiq`
2022-11-27 19:03:06 +00:00
Yuri Astrakhan
ab576afc18 addressed review feedback 2022-11-27 10:34:13 -05:00
Yuri Astrakhan
7a2d92e1f2 Add allow-mixed-uninlined-format-args config
Implement `allow-mixed-uninlined-format-args` config param to change the behavior of the `uninlined_format_args` lint. Now it is a part of `style`, and won't propose inlining in case of a mixed usage, e.g. `print!("{} {}", var, 1+2)`. If the user sets allow-mixed-uninlined-format-args config param to `false`, then it would behave like before, proposing to inline args even in the mixed case.
2022-11-27 10:12:51 -05:00
koka
8c50dfb546
Remove blank lines when needless_return returns no value
fix https://github.com/rust-lang/rust-clippy/issues/9416
2022-11-27 22:01:21 +09:00
Alex Macleod
461e219d1d Allow using clippy::msrv as an outer attribute 2022-11-27 12:43:17 +00:00
Lukas Wirth
dd1163f461 Fix macro statement handling 2022-11-25 17:10:10 +01:00
Lukas Wirth
23744cd4ba Use multi-span suggestions 2022-11-25 17:10:10 +01:00
Lukas Wirth
93b5c893e6 Add semicolon-outside/inside-block lints 2022-11-25 17:10:10 +01:00
kraktus
5610d22c8d Re-enable uninlined_format_args on multiline format!
But do not display the code suggestion which can be sometimes completely broken (fortunately when applied it's valid)
2022-11-25 16:36:22 +01:00
dswij
a4b53c9c14 manual_let_else: Add test with expanded macros 2022-11-25 18:17:34 +08:00
Lukas Wirth
f96dd38318 Address reviews 2022-11-25 10:09:35 +01:00
Lukas Wirth
4fa5757530 Lint unnecessary safety comments on statements and block tail expressions 2022-11-25 10:09:34 +01:00
Lukas Wirth
b8c3f64cee Add some more test cases for undocumented_unsafe_blocks 2022-11-25 10:09:34 +01:00
Lukas Wirth
a116b9bdba Lint unnecessary safety comments on items 2022-11-25 10:09:34 +01:00
Arpad Borsos
1ebdcca8b9 Avoid GenFuture shim when compiling async constructs
Previously, async constructs would be lowered to "normal" generators,
with an additional `from_generator` / `GenFuture` shim in between to
convert from `Generator` to `Future`.

The compiler will now special-case these generators internally so that
async constructs will *directly* implement `Future` without the need
to go through the `from_generator` / `GenFuture` shim.

The primary motivation for this change was hiding this implementation
detail in stack traces and debuginfo, but it can in theory also help
the optimizer as there is less abstractions to see through.
2022-11-24 10:04:27 +01:00
bors
69c5128cda Auto merge of #9924 - Alexendoo:msrv-stack, r=Jarcho
Add `clippy_utils::msrv::Msrv` to keep track of the current MSRV

changelog: Fix the scoping of the `#![clippy::msrv]` attribute

Fixes #6920

r? `@Jarcho`
2022-11-22 20:09:58 +00:00
bors
5595d7f5d5 Auto merge of #9750 - kraktus:lazy_eval, r=xFrednet
Fix [`unnecessary_lazy_eval`] when type has significant drop

fix for https://github.com/rust-lang/rust-clippy/issues/9427#issuecomment-1295742590

However current implementation gives too many false positive, rending the lint almost useless.

I don't know what's the best way to check if a type has a "significant" drop (in the common meaning, not the internal rustc one, for example Option<(u8, u8)> should not be considered significant)

changelog: Fix [`unnecessary_lazy_eval`] when type has significant drop
2022-11-22 17:21:23 +00:00
bors
94ce4465e5 Auto merge of #9796 - smoelius:issue-9771, r=flip1995
Fix #9771 (`unnecessary_to_owned` false positive)

Fixes #9771

In that issue's example(s), the lint tried to add a `&` to a value, which implicitly changed the type of a field to a reference. The fix is to add the reference to `receiver_ty` (the type of the receiver of the `to_owned`-like method), before passing `receiver_ty` to `can_change_type`. `can_change_type` properly rejects the modified `receiver_ty`.

cc: `@mikerite` just because I think he was the author of `can_change_type`.

changelog: fix `unnecessary_to_owned` false positive which implicitly tried to change the type of a field to a reference
2022-11-22 12:50:08 +00:00
bors
f4083c5ae7 Auto merge of #9745 - matttpt:fix-redundant-closure-for-method-calls-suggestion, r=flip1995
Fix `redundant_closure_for_method_calls` suggestion

Fixes #7746. The issue turns out to be more general than raw pointers. The `redundant_closure_for_method_calls` lint produces incorrect suggestions when the method is associated with a type that must be enclosed in angle brackets or must be written with generic arguments substituted. For example:

```rust
fn main() {
    // Clippy's suggestion: [T; N]::as_slice
    // Correct suggestion:  <[u8; 3]>::as_slice
    let array_opt: Option<&[u8; 3]> = Some(&[4, 8, 7]);
    array_opt.map(|a| a.as_slice());

    // Clippy's suggestion: [T]::len
    // Correct suggestion:  <[u8]>::len
    let slice_opt: Option<&[u8]> = Some(b"slice");
    slice_opt.map(|s| s.len());

    // Clippy's suggestion: *const T::is_null
    // Correct suggestion:  <*const usize>::is_null
    let ptr_opt: Option<*const usize> = Some(&487);
    ptr_opt.map(|p| p.is_null());

    // Clippy's suggestion: dyn TestTrait::method_on_dyn
    // Correct suggestion:  <dyn TestTrait>::method_on_dyn
    let test_struct = TestStruct {};
    let dyn_opt: Option<&dyn TestTrait> = Some(&test_struct);
    dyn_opt.map(|d| d.method_on_dyn());
}

// For the trait object example:
trait TestTrait {}
struct TestStruct {}
impl TestTrait for TestStruct {}

impl dyn TestTrait + '_ {
    fn method_on_dyn(&self) -> bool {
        false
    }
}
```

The issue also affects references and tuples, though I had to patch the standard library with non-trait methods for those types to test that. Just in case, I also included handling for `!`, since it appeared to be possible to call methods on it with angle brackets. I just couldn't verify the resulting suggestion, since dead-code analysis eliminates the code first.

This is my first exposure to Rust compiler internals, so please let me know if I'm taking the wrong approach here!

changelog: [`redundant_closure_for_method_calls`]: add angle brackets and substitute generic arguments in suggestion when needed
2022-11-22 09:20:50 +00:00
xFrednet
aa66212e29
Cleanup rustc_tool_util and add a convenient macro for build.rs 2022-11-21 23:28:26 +01:00
Philipp Krones
46c5a5d234 Merge commit 'f4850f7292efa33759b4f7f9b7621268979e9914' into clippyup 2022-11-21 20:51:52 +01:00
bors
73efce9ee6 Auto merge of #9770 - sgued:missnamed-getters, r=llogiq
Add new lint  [`misnamed-getters`]

```
changelog: Add new lint  [`misnamed-getters`]
```

Closes #9769

The current lint matches all methods with a body of just one expression under the form `(&mut?)? <expr>.field` where field doesn't match the name of the method but there is a field of the same type in `<expr>` that matches the name. This allows matching nested structs, for example for newtype wrappers. This may cast the net a bit too wide and cause false positives. I'll run [clippy_lint_tester](https://github.com/mikerite/clippy_lint_tester) on the top crates to see how frequently false positives happen.

There also may be room for improvement by checking that the replacement field would work taking into account implementations of `Deref` and `DerefMut` even if the types don't exactly match but I don't know yet how this could be done.
2022-11-21 19:51:42 +00:00
Philipp Krones
05b914a92b
Fix custom ICE message test on windows 2022-11-21 20:15:50 +01:00
Philipp Krones
fd5b85c957
Merge remote-tracking branch 'upstream/master' into rustup 2022-11-21 20:01:17 +01:00
Alex Macleod
637139d2ff Add clippy_utils::msrv::Msrv to keep track of the current MSRV 2022-11-21 18:16:40 +00:00
kraktus
ed183ee9ac Fix [unnecessary_lazy_eval] when type has significant drop 2022-11-21 12:45:35 +01:00
bors
e0c1959616 Auto merge of #9592 - c410-f3r:arith, r=Jarcho
[arithmetic-side-effects] Detect overflowing associated constants of integers

Triggers the negation of maximum unsigned integers using associated constants. Rustc already handles `-128i8` but doesn't handle `-i8::MAX`.

At the same time, allows stuff like `-1234`.

changelog: FP: [arithmetic-side-effects] Detect overflowing associated constants of integers
2022-11-20 22:51:25 +00:00
bors
a85c8f33ff Auto merge of #9870 - koka831:unformat-unused-rounding, r=Jarcho
Keep original literal notation in suggestion

While I did some investigation of https://github.com/rust-lang/rust-clippy/issues/9866 (I couldn't reproduce it though) I found that `unused_rounding` formats as follows:

```rust
3.0_f64.round() // => 3.0f64
```

This PR makes them preserve as the original notation.

```rust
3.0_f64.round() // => 3.0_f64
```

changelog: Suggestion Enhancement: [`unused_rounding`]: The suggestion now preserves the original float literal notation
2022-11-20 22:09:25 +00:00
Sosthène Guédon
1f2f50c34e Fix many false negatives caused by autoderef 2022-11-20 17:03:53 +01:00
Sosthène Guédon
0411edfbbd Improve diagnostic for cases where autoderef is used 2022-11-20 15:49:09 +01:00
Sosthène Guédon
77374a9527 Add failing test 2022-11-20 13:45:12 +01:00
Sosthène Guédon
3f1a186bd1 misnamed_getters: Trigger on unsafe with _unchecked 2022-11-20 13:45:12 +01:00
Sosthène Guédon
a867c17ab3 Improve code 2022-11-20 13:45:12 +01:00
Sosthène Guédon
3428da6e00 Fix typo missnamed -> misnamed 2022-11-20 13:45:12 +01:00
Sosthène Guédon
ddc49966dc Fix suggestion to point to the whole method 2022-11-20 13:45:12 +01:00
Sosthène Guédon
9891af348c missnamed_getters: Match owned methods 2022-11-20 13:45:12 +01:00
Sosthène Guédon
31b83d0895 Add missnamed_getters lint 2022-11-20 13:45:11 +01:00
Alex Macleod
4d8af99365 Fix #[allow] for module_name_repetitions & single_component_path_imports 2022-11-20 12:39:19 +00:00
Caio
98b343c5e6 [arithmetic-side-effects] Detect overflowing associated constants of integers 2022-11-19 08:22:27 -03:00
bors
f60186f35d Auto merge of #9800 - Alexendoo:def_path_res_multiple, r=dswij
Return multiple resolutions from `def_path_res`

Changes `def_path_res` to return all the resolutions matching the path rather than the first one (with a namespace hint that covered some cases).  This would fix any issues that come up with multiple versions of the same crate being present as they all have the same crate name

It also adds resolution of `impl _ {}` items for local items, and removes struct field resolution as it didn't seem to be used anywhere

I tested it on a local crate and it worked for the multiple crate issue, but I couldn't come up with a test that worked well with `// aux-build`, maybe `// aux-crate` after https://github.com/rust-lang/rust/pull/103266 could work but I'm not sure on that either

changelog: [`disallowed_methods`], [`disallowed_types`], [`disallowed_macros`]: fix path resolution with multiple versions of the same crate
changelog: [`disallowed_methods`]: Resolve methods in `impl`s in the current crate
2022-11-19 09:05:50 +00:00
bors
e144c7d1ae Auto merge of #9871 - koka831:fix/9864, r=xFrednet
Allow manual swap in const fn

Fix https://github.com/rust-lang/rust-clippy/issues/9864

changelog: Fix [`manual_swap`]: No longer lints in constant code
2022-11-18 16:04:18 +00:00
bors
d019fd9780 Auto merge of #9855 - Alexendoo:needless-borrowed-ref-extra, r=xFrednet
Extend `needless_borrowed_reference` to structs and tuples, ignore _

changelog: [`needless_borrowed_reference`]: Lint struct and tuple patterns, and patterns containing `_`

Now lints patterns like

```rust
&(ref a, ref b)
&Tuple(ref a, ref b)
&Struct { ref a, ref b }

&(ref a, _)
```
2022-11-18 14:26:50 +00:00
koka
928a158716
Allow manual swap in const fn 2022-11-18 21:51:43 +09:00
koka
921f4d317e
Keep original literal notation in suggestion 2022-11-18 21:23:16 +09:00
bors
01f40ce3bc Auto merge of #9863 - smoelius:expect-unwrap-used-typo, r=flip1995
Fix typo in `expect_used` and `unwrap_used` warning messages

"\`an Option\`" -> "an \`Option\`" and "\`a Result\`" -> "a \`Result\`".

changelog: fix typo in `expect_used` and `unwrap_used` warning messages
2022-11-18 11:49:47 +00:00
bors
dfe37f13cf Auto merge of #9850 - pheki:fix-7499-missing-ref, r=dswij
Preserve `ref` on `infallible_destructuring_match` suggestion

Fixes https://github.com/rust-lang/rust-clippy/issues/7499

changelog: [`infallible_destructuring_match`]: Preserve `ref` on suggestion
2022-11-18 09:43:51 +00:00
bors
1c9c34de17 Auto merge of #9858 - DesmondWillowbrook:never_loop, r=dswij
`never_loop`: don't emit AlwaysBreaks if it targets a block

ref: https://github.com/rust-lang/rust-clippy/pull/9837#issuecomment-1312788194

The previous fix (#9837) was too simple and ignored all break commands inside a labelled block, regardless of whether their destination was a labelled block or a loop. This fix tracks all the labelled blocks in scope to ensure that only breaks targeting loops are considered.

changelog: [`never_loop`]: prevent false negatives from `breaks` nested in labelled blocks
2022-11-18 09:31:20 +00:00
Philipp Krones
82afb16179 Add variant_name function to LangItem
Clippy has an internal lint that checks for the usage of hardcoded def
paths and suggests to replace them with a lang or diagnostic item, if
possible. This was implemented with a hack, by getting all the variants
of the `LangItem` enum and then index into it with the position of the
`LangItem` in the `items` list. This is no longer possible, because the
`items` list can't be accessed anymore.
2022-11-17 20:06:25 +01:00
Samuel Moelius
00ae5e15a8 Fix typo in expect_used and unwrap_used warning messages 2022-11-17 15:02:48 +00:00
Ralf Jung
2bf87f3830 cleanup and dedupe CTFE and Miri error reporting 2022-11-16 10:13:29 +01:00
Kartavya Vashishtha
036a0108ac
update tests 2022-11-16 11:39:09 +05:30
Kartavya Vashishtha
9f3b6e9acd
don't emit AlwaysBreaks if it targets a block
Introduced an ignored_ids parameter.
Takes O(n^2) time in the worst case.

Can be changed to collect block ids in first phase,
and then filter with binary search in second.
2022-11-16 11:01:07 +05:30
Alex Macleod
f75fc85783 Extend needless_borrowed_reference to structs and tuples, ignore _ 2022-11-15 18:24:18 +00:00
bors
38e059028f Auto merge of #9849 - koka831:fix/9748, r=Manishearth
Allow return types for closures with lifetime binder

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

changelog: Fix [`unused_unit`] Allow return types for closures with lifetime binder
2022-11-15 09:13:54 +00:00
bors
5b0d727bad Auto merge of #9570 - nfejzic:lint-unchecked-duration-subtraction, r=llogiq
feat: lint unchecked subtraction of a 'Duration' from an 'Instant'

Hello all, I tried to tackle the open issue #9371 and this is what I came up with.

I have a difficulty currently - some tests are failing:

```
failures:
    [ui] ui/manual_instant_elapsed.rs
```

The `manual_instant_elapsed` is failing because of `Instant::now() - duration` test, this now gets also picked by `unchecked_duration_subtraction` lint.
What is the correct way to proceed in this case? Simply update the `.stderr` file for `manual_instant_elapsed` lint?

changelog: [`unchecked_duration_subtraction`]: Add lint for unchecked subtraction of a `Duration` from an `Instant`.

fixes #9371
2022-11-15 06:09:10 +00:00
Aphek
93ac0f58bf Keep ref on infallible_destructuring_match suggestion 2022-11-15 01:57:56 -03:00
koka
7c4611c7e1
Allow return types for closures with lifetime binder 2022-11-15 12:58:17 +09:00
Lukas Markeffsky
b8357ffd1f fix vec-box-size-threshold off-by-one error 2022-11-14 16:06:21 +01:00
bors
a5995279fb Auto merge of #9837 - DesmondWillowbrook:never_loop, r=dswij
fix never_loop false positive

fixes #9831

changelog: [`never_loop`]: fixed false positive on unconditional break in internal labeled block
2022-11-13 15:44:14 +00:00
bors
493b78885a Auto merge of #9829 - hrxi:pr_or_fun_call, r=llogiq
Make it clear that `or_fun_call` can be a false-positive

Also move it to nursery so that the false-positives can be dealt with.

CC #8574

changelog: [`or_fun_call`]: Mention false-positives, move to nursery.
2022-11-13 14:29:42 +00:00
bors
6ba3a00b94 Auto merge of #9822 - Veykril:unnecessary-safety-doc, r=Jarcho
Add `unnecessary_safety_doc` lint

changelog: [`unnecessary_safety_doc`]: Add `unnecessary_safety_doc` lint

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

This lint does not trigger for private functions, just like `missing_safety_docs`. Reason for that was implementation simplicity and because I figured asking first would make more sense, so if it should trigger for private functions as well let me know and I'll fix that up as well.
2022-11-13 14:18:04 +00:00
bors
a8151409a0 Auto merge of #9698 - kraktus:xc_bool, r=xFrednet
[`fn_params_excessive_bools`] Make it possible to allow the lint at the method level

changelog: FP: [`fn_params_excessive_bools`]: `#[allow]` now works on methods

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

Tested without committing but `#[allow]`ing now works. Also rewrote the lint to be a late lint while at it :)
r? `@xFrednet`
2022-11-13 09:57:36 +00:00
hrxi
243661b739 Make it clear that or_fun_call can be a false-positive
Also move it to nursery so that the false-positives can be dealt with.

CC #8574
2022-11-12 22:26:09 +01:00
bors
9f283c97e1 Auto merge of #9835 - koka831:fix/9035, r=Alexendoo
Avoid linting unsized mutable reference

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

changelog: [`mut_mut`] avoid suggesting to reborrow unsized mutable reference
2022-11-12 21:07:18 +00:00
Kartavya Vashishtha
989986144c
fix never_loop false positive
on unconditional break to internal labeled block

ref #9831
2022-11-12 20:36:30 +05:30
koka
34c4520eae
Fix is_async_fn to check FnKind::Method 2022-11-12 22:36:20 +09:00
koka
93edc127a0
Avoid lint to unsized mutable reference 2022-11-12 20:31:25 +09:00
bors
cad0d3d6da Auto merge of #9662 - ebobrow:result-large-err, r=dswij
`result_large_err` show largest variants in err msg

fixes #9538

changelog: Sugg: [`result_large_err`]: Now show largest enum variants in error message
2022-11-11 06:58:59 +00:00
koka
2bc04bdac2
fix: cognitive_complexity for async fn 2022-11-11 00:14:18 +09:00
Nadir Fejzic
862ac29192 fix: remove (redundant) semicolon in lint suggestion 2022-11-10 15:47:12 +01:00
Nadir Fejzic
62ab4fb9c2 fix: add rust-fix annotation to unckd. duration subtr. lint test 2022-11-10 15:47:12 +01:00
Nadir Fejzic
4bd6d0beb0 test: update tests for manual_instant_elapsed lint 2022-11-10 15:47:12 +01:00
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
Lukas Wirth
146bd1e13d Add unnecessary_safety_doc lint 2022-11-10 10:09:33 +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
yukang
84c3a959a7 bless clippy 2022-11-09 19:23:23 +08: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
Elliot Bobrow
80e5856b02 result_large_err show largest variants in err msg 2022-11-07 18:00:35 -08:00
kraktus
3d4b73c26d [excessive_bools] lint trait functions even without bodies 2022-11-07 21:00:37 +01: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
kraktus
13b737d5b8 [fn_params_excessive_bools] whitelist in signle function in test 2022-11-07 19:49:43 +01:00
kraktus
9e1c7febe2 excessive_bools, do not lint in trait impls
Should not lint because the trait might not be changeable by the user
We only lint in the trait definition
2022-11-07 19:49:43 +01:00
kraktus
9c69e93595 Rewrite ExcessiveBools to be a LateLintPass lint
changelog: [`fn_params_excessive_bools`] Make it possible to allow the lint at the method level
2022-11-07 19:49:43 +01: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
Alex Macleod
1e1ac2b498 Return multiple resolutions from def_path_res 2022-11-04 21:58:07 +00:00
Trevor Arjeski
ddcfff6d9a Add allow-print-in-tests config
Add a config, allow-print-in-tests, that can be set in clippy.toml which
allows the usage of `[e]print[ln]!` macros in tests.

Closes #9795
2022-11-04 20:33:04 +03:00
Samuel Moelius
f27ca5c00a Fix #9771 (unnecessary_to_owned false positive) 2022-11-04 16:02:12 +00: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
9f2852f9a2 Auto merge of #103217 - mejrs:track, r=eholk
Track where diagnostics were created.

This implements the `-Ztrack-diagnostics` flag, which uses `#[track_caller]` to track where diagnostics are created. It is meant as a debugging tool much like `-Ztreat-err-as-bug`.

For example, the following code...

```rust
struct A;
struct B;

fn main(){
    let _: A = B;
}
```
...now emits the following error message:

```
error[E0308]: mismatched types
 --> src\main.rs:5:16
  |
5 |     let _: A = B;
  |            -   ^ expected struct `A`, found struct `B`
  |            |
  |            expected due to this
-Ztrack-diagnostics: created at compiler\rustc_infer\src\infer\error_reporting\mod.rs:2275:31
```
2022-11-01 21:09:45 +00: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
Matthew Ingwersen
329dc4715b Fix redundant_closure_for_method_calls suggestion
Certain types must be enclosed in angle brackets and must have generic
arguments substituted to create a working suggestion. For example, if
`s` has type `&[u8]`, then `|s| s.len()` may be replaced with
`<[u8]>::len`. Previously, Clippy erroneously suggested `[T]::len`.
2022-10-28 16:25:51 -04: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
mejrs
4b1cebbc18 Adjust normalization 2022-10-26 13:41:57 +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
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
mejrs
48edc83526 Add more normalization and tests 2022-10-24 23:19:48 +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
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
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
mejrs
beae0d298e Address some comments 2022-10-24 20:52:51 +02:00
JT
4f3fb0081d Update the corresponding test and bless tests 2022-10-25 07:28:09 +13: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
Alex Macleod
a201518a8a Generate lint categories and explanations with declare_clippy_lint
Changes it to be a proc_macro rather than macro_rules
2022-10-23 20:32:26 +00: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
a8a8fd77a9 Auto merge of #9686 - kraktus:unwrap_in_test_cfg, r=flip1995
[`unwrap_used`], [`expect_used`] do not lint in `test` cfg

changelog: [`unwrap_used`], [`expect_used`] do not lint in `test` cfg

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

I've updated the doc and used `cfg` acronym, not sure if `conditional compiler flag` would have been better
2022-10-23 13:23:38 +00:00
flip1995
cd0bb7de01 Merge commit '4f142aa1058f14f153f8bfd2d82f04ddb9982388' into clippyup 2022-10-23 15:18:45 +02: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
bors
28cd1ec9b7 Auto merge of #9688 - Alexendoo:msrv-tests, r=Manishearth
Move MSRV tests into the lint specific test files

There are currently two ways MSRV tests are done in the ui test suite, adding a case to the `#![clippy::msrv = "1.0"]` `tests/ui/min_rust_version_attr.rs` or adding the two `msrv_1_xx` functions to the test file of the lint in question

This updates the clippy book to suggest the `msrv_1_xx` style, and replaces the tests in `tests/ui/min_rust_version_attr.rs` with ones of that style

Almost the entire diff is just moving stuff around as a result, I made sure to check the line numbers the lints are emitted at correspond with the right `msrv` case, so feel free to only skim that part

changelog: none
2022-10-23 05:05:23 +00:00
Samuel Moelius
5c6c3534d9 Add lintcheck to packages linted by dogfood test 2022-10-22 07:37:10 -04: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
6551754945 [unwrap_used], [expect_used] do not lint in test cfg 2022-10-21 15:27:25 +02:00
kraktus
487c6fc9ad [collapsible_match] specify field name when destructuring structs 2022-10-21 14:51:13 +02:00
Dylan DPC
0569f56be3 Rollup merge of #103260 - cuviper:needs-asm-support, r=fee1-dead
Fixup a few tests needing asm support
2022-10-21 17:29:59 +05:30
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
Kevin Per
56506730c8 Implement assertions and fixes to not emit empty spans without suggestions 2022-10-20 08:25:31 +00:00
Josh Stone
4dfc7b2025 Fixup a few tests needing asm support 2022-10-19 11:34:00 -07: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
332b5b3d8b Auto merge of #9566 - smoelius:diagnostic-item-path, r=dswij
Expand internal lint `unnecessary_def_path`

This PR does essentially two things:
* Separates the internal lints into modules by pass. (`internal_lints.rs` was over 1400 lines, which is a little unruly IMHO.)
* ~Adds a new~ Expands the `unnecessary_def_path` internal lint to flag hardcoded paths to diagnostic and language items.

My understanding is that the latter is currently done by reviewers. Automating this process should make things easier for both reviewers and contributors.

I could make the first bullet a separate PR, or remove it entirely, if desired.

changelog: Add internal lint `diagnostic_item_path`
2022-10-16 05:56:19 +00: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
Samuel Moelius
2e5e3560e9 Fix adjacent code 2022-10-15 07:03:29 -04:00
Samuel Moelius
8611a0bb5c Expand unnecessary_def_path lint 2022-10-15 07:03:29 -04:00
Samuel Moelius
dfd3525cff Separate internal lints by pass 2022-10-15 07:01:44 -04: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