Commit graph

6829 commits

Author SHA1 Message Date
bors
1e68973582 Auto merge of #10067 - chansuke:issue-7943, r=giraffate
Add 2018/2021 edition tests for wildcard_imports

Fixes #7943

---

changelog: none
<!-- changelog_checked -->
2022-12-20 00:28:21 +00:00
Michael Goulet
24444945ec Make Clippy test no longer unsound 2022-12-19 18:16:22 +00:00
dboso
30e6e85508 add [permissions_set_readonly_false] #9702 2022-12-20 00:37:51 +09:00
Niki4tap
d0ac6ba0b1 Fix overflow ICE in large_stack/const_arrays 2022-12-19 18:27:42 +03:00
bors
b3145fea6a Auto merge of #10099 - Niki4tap:null_fn_lints, r=llogiq
Null fn lints

Adds lints to check for code, that assumes nullable `fn()`.

### Lint examples:

`transmute_null_to_fn`:
```rust
error: transmuting a known null pointer into a function pointer
  --> $DIR/transmute_null_to_fn.rs:9:23
   |
LL |         let _: fn() = std::mem::transmute(std::ptr::null::<()>());
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this transmute results in undefined behavior
   |
   = help: try wrapping your function pointer type in `Option<T>` instead, and using `None` as a null pointer value
```

`fn_null_check`:
```rust
error: function pointer assumed to be nullable, even though it isn't
  --> $DIR/fn_null_check.rs:13:8
   |
LL |     if (fn_ptr as *mut ()).is_null() {}
   |        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: try wrapping your function pointer type in `Option<T>` instead, and using `is_none` to check for null pointer value
```

Closes #1644

---

changelog: Improvement: [`transmuting_null`]: Now detects `const` pointers to all types
[#10099](https://github.com/rust-lang/rust-clippy/pull/10099)
changelog: New lint: [`transmute_null_to_fn`]
[#10099](https://github.com/rust-lang/rust-clippy/pull/10099)
changelog: New lint: [`fn_null_check`]
[#10099](https://github.com/rust-lang/rust-clippy/pull/10099)
<!-- changelog_checked (This is just a flag for me, please don't add it manually) -->
2022-12-19 12:44:23 +00:00
bors
910a97d7ce Auto merge of #10020 - samueltardieu:more-into-iter-removal, r=xFrednet
Identify more cases of useless `into_iter()` calls

changelog: Sugg: [`useless_conversion`]: Now suggests removing calls to `into_iter()` on an expression implementing `Iterator`
[#10020](https://github.com/rust-lang/rust-clippy/pull/10020)
<!-- changelog_checked -->
2022-12-18 16:01:29 +00:00
koka
ebb0759bb3
Add a test for regular wildcard
fix
2022-12-18 21:07:18 +09:00
Niki4tap
42106e0495 Add lint fn_null_check 2022-12-18 03:02:45 +03:00
Niki4tap
6afe5471cf Add lint transmute_null_to_fn 2022-12-18 03:02:37 +03:00
Samuel Tardieu
af39a8a4a8 Identify more cases of useless into_iter() calls
If the type of the result of a call to `IntoIterator::into_iter()`
and the type of the receiver are the same, then the receiver
implements `Iterator` and `into_iter()` is the identity function.

The call to `into_iter()` may be removed in all but two cases:

- If the receiver implements `Copy`, `into_iter()` will produce
  a copy of the receiver and cannot be removed. For example,
  `x.into_iter().next()` will not advance `x` while `x.next()` will.
- If the receiver is an immutable local variable and the call to
  `into_iter()` appears in a larger expression, removing the call to
  `into_iter()` might cause mutability issues. For example, if `x`
  is an immutable local variable, `x.into_iter().next()` will
  compile while `x.next()` will not as `next()` receives
  `&mut self`.
2022-12-17 16:20:43 +01:00
Philipp Krones
1c422524c7 Merge commit '4bdfb0741dbcecd5279a2635c3280726db0604b5' into clippyup 2022-12-17 14:12:54 +01:00
bors
4bdfb0741d Auto merge of #10097 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

I'm on the train and my internet is too bad to download the necessary toolchain, so I have to use CI to find sync fallout.

changelog: none
<!-- changelog_checked -->
2022-12-17 13:08:47 +00:00
Philipp Krones
d6488ae144
Merge remote-tracking branch 'upstream/master' into rustup 2022-12-17 13:56:32 +01:00
bors
391b2a6fac Auto merge of #10096 - feniljain:fix-seek-rewind, r=xFrednet
fix: not suggest seek_to_start_instead_of_rewind when expr is used

changelog: [`seek_to_start_instead_of_rewind`]: No longer lints, if the return of `seek` is used.
[#10096](https://github.com/rust-lang/rust-clippy/pull/10096)
<!-- changelog_checked -->

Fixes #10065
2022-12-17 12:35:26 +00:00
feniljain
c39849a34d fix: not suggest seek_to_start_instead_of_rewind when expr is used 2022-12-17 17:31:34 +05:30
chansuke
033f1ec797 Add 2018/2021 edition tests for wildcard_imports 2022-12-17 20:26:41 +09:00
Eric Wu
97c12e0460 fix logic in IncrementVisitor
There used to be a logical bug where IncrementVisitor would
completely stop checking an expression/block after seeing a continue
statement. This led to issue #10058 where a variable incremented
(or otherwise modified) after any continue statement would still be
considered incremented only once.

The solution is to continue scanning the expression after seeing a
`continue` statement, but increment self.depth so that the Visitor
thinks that the rest of the loop is within a conditional.
2022-12-16 10:54:12 -05:00
Eric Wu
3c14075b46 manual_filter: add a related test
The related issue is #9766 where the `manual_filter`
lint would remove side effects
2022-12-16 09:29:32 -05:00
Eric Wu
5b3a6669f7 fix manual_filter false positive
do explicit checks for the other branch being None
2022-12-15 23:53:28 -05:00
Gary Guo
7574c98371 Fix new_return_no_self with recursive bounds 2022-12-15 18:56:13 +00:00
bors
f43e4f30d8 Auto merge of #9927 - xFrednet:0000-rustc-tool-macro-update, r=matthiaskrgr
Cleanup `rustc_tool_util` and add a convenient macro for `build.rs`

changelog: none
<!-- changelog_checked -->

If possible, I'd like to have a new release for this, maybe `v0.3.0` to use the changes in another project. Then we can also remove the `path = "./rustc_tools_util"` from `Cargo.toml`. I'd be happy to help with the release on crates.io if you'd like the help :)

r? `@matthiaskrgr`
2022-12-15 12:04:30 +00:00
bors
be15e60d00 Auto merge of #10053 - naosense:fix_9933, r=xFrednet
improve `manual_is_ascii_check ` check

Sorry, not familiar the api, i can only check the method name of expression `<expr-1>.contains(<expr-2>)` after read clippy book and hints from #9933 . i dont know how to check
1.  if <expr-1> is a specific range
2. <expr-2> is a character

r? `@xFrednet` could you please provide some more hints? 😝️

---

changelog: Enhancement: [`manual_is_ascii_check`]: Now detects ranges with `.contains()` calls
[#10053](https://github.com/rust-lang/rust-clippy/pull/10053)
<!-- changelog_checked -->
2022-12-14 13:48:53 +00:00
naosense
1f862c2ad3 remove assert macro 2022-12-13 21:43:16 +08:00
naosense
55fdd1e78c replace reference with value 2022-12-13 16:52:55 +08:00
naosense
de92da2974 add more test, limits check 2022-12-13 16:52:55 +08:00
naosense
25c9718c04 check ranges with .contains calls 2022-12-13 16:52:55 +08:00
alex-semenyuk
3b6bbf7d16 Fix match_single_binding suggestion introduced an extra semicolon 2022-12-10 20:35:49 +03:00
koka
055f349670
Avoid match_wildcard_for_single_variants on guarded wild matches
fix #9993
changlog: [`match_wildcard_for_single_variants`] avoid suggestion on wildcard with guard
2022-12-10 21:05:08 +09:00
Taiki Endo
e5010c996e uninlined_format_args: Ignore assert! and debug_assert! before 2021 edition 2022-12-10 18:35:24 +09:00
Hannah Town
4c80f210c3 Add lint almost_complete_range
This replaces and expands `almost_complete_letter_range`.
2022-12-09 13:29:50 -05:00
bors
3492856c07 Auto merge of #10047 - Alexendoo:collapsible-str-replace-msrv, r=xFrednet
Add 1.58 MSRV for `collapsible_str_replace`

The `Pattern` impl for `[char; N]` was added in 1.58

changelog: Enhancement: [`collapsible_str_replace`]: Now takes MSRV into consideration. The minimal version is 1.58
[#10047](https://github.com/rust-lang/rust-clippy/pull/10047)
2022-12-09 12:05:20 +00:00
bors
5a3a722c05 Auto merge of #10004 - Jarcho:issue_9904, r=llogiq
Don't suggest keeping borrows in `identity_op`

fixes #9904
changelog: `identity_op`: Don't suggest keeping borrows
2022-12-09 11:53:14 +00:00
bors
d4cd91c288 Auto merge of #9826 - Veykril:semi-blocks, r=Alexendoo
Add semicolon-outside/inside-block lints

changelog: Add `semicolon_outside_block` and `semicolon_inside_block` lints

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

An earlier attempt at this can be found here https://github.com/rust-lang/rust-clippy/pull/7564. This PR still implements two separate lints but I am open to merging them into a single one that's configurable.
2022-12-09 11:41:24 +00:00
bors
39f0719a25 Auto merge of #9840 - c410-f3r:arith-2, r=Alexendoo
[`arithmetic-side-effects`]: Consider user-provided pairs

Depends on https://github.com/rust-lang/rust-clippy/pull/9592.

Because of https://github.com/rust-lang/rust-clippy/pull/9559#discussion_r985293523, r? `@Alexendoo`

```
changelog: [`arithmetic-side-effects`]: Consider user-provided pairs
```
2022-12-09 11:27:15 +00:00
Caio
1f92f97e5a [arithmetic-side-effects]: Consider user-provided pairs 2022-12-08 17:41:49 -03:00
Alex Macleod
591c18d2f0 Add 1.58 MSRV for collapsible_str_replace 2022-12-07 17:45:12 +00:00
bors
4129054120 Auto merge of #10023 - Jarcho:issue_10017, r=xFrednet
Fix `zero_ptr` suggestion for `no_std` crates

fixes #10017

---

changelog: Sugg: [`zero_ptr`]: Now suggests `core::` paths for `no_std` crates
[#10023](https://github.com/rust-lang/rust-clippy/pull/10023)
2022-12-06 18:57:05 +00:00
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
kraktus
e51e9308d5 default_numeric_fallback do not lint on constants 2022-10-12 22:34:32 +02:00
bors
45dd9f31f3 Auto merge of #9627 - Jarcho:ice-9625, r=xFrednet
Use the correct type when comparing nested constants.

fixes #9625

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

This fixes #371.

r? `@Alexendoo`

---

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

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

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

changelog: Add [`as_ptr_cast_mut`]
2022-10-11 08:08:17 +00:00
Jason Newcomb
0cc749296f Use the correct type when comparing nested constants. 2022-10-10 15:33:49 -04:00
Andre Bogus
bd61fdbd5f fix box-default ignoring trait objects' types 2022-10-10 21:11:37 +02:00
bors
cf72565a12 Auto merge of #9610 - Jarcho:fix-9608, r=Alexendoo
Don't suggest moving tuple structs with a significant drop to late evaluation

fixes #9608

changelog: Don't suggest moving tuple structs with a significant drop to late evaluation
2022-10-10 12:29:15 +00:00
Dylan DPC
5577e42ead Rollup merge of #99696 - WaffleLapkin:uplift, r=fee1-dead
Uplift `clippy::for_loops_over_fallibles` lint into rustc

This PR, as the title suggests, uplifts [`clippy::for_loops_over_fallibles`] lint into rustc. This lint warns for code like this:
```rust
for _ in Some(1) {}
for _ in Ok::<_, ()>(1) {}
```
i.e. directly iterating over `Option` and `Result` using `for` loop.

There are a number of suggestions that this PR adds (on top of what clippy suggested):
1. If the argument (? is there a better name for that expression) of a `for` loop is a `.next()` call, then we can suggest removing it (or rather replacing with `.by_ref()` to allow iterator being used later)
   ```rust
    for _ in iter.next() {}
    // turns into
    for _ in iter.by_ref() {}
    ```
2. (otherwise) We can suggest using `while let`, this is useful for non-iterator, iterator-like things like [async] channels
   ```rust
   for _ in rx.recv() {}
   // turns into
   while let Some(_) = rx.recv() {}
   ```
3. If the argument type is `Result<impl IntoIterator, _>` and the body has a `Result<_, _>` type, we can suggest using `?`
   ```rust
   for _ in f() {}
   // turns into
   for _ in f()? {}
   ```
4. To preserve the original behavior and clear intent, we can suggest using `if let`
   ```rust
   for _ in f() {}
   // turns into
   if let Some(_) = f() {}
   ```
(P.S. `Some` and `Ok` are interchangeable depending on the type)

I still feel that the lint wording/look is somewhat off, so I'll be happy to hear suggestions (on how to improve suggestions :D)!

Resolves #99272

[`clippy::for_loops_over_fallibles`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles
2022-10-10 13:43:40 +05:30
Maybe Waffle
7cfc6fa1f0 deprecate clippy::for_loops_over_fallibles 2022-10-09 13:07:21 +00:00
Maybe Waffle
05dcfd971a fixup lint name 2022-10-09 13:07:21 +00:00
Maybe Waffle
3fc903eb95 Fix clippy tests that trigger for_loop_over_fallibles lint 2022-10-09 13:07:21 +00:00
bors
272bbfb857 Auto merge of #9386 - smoelius:further-enhance-needless-borrow, r=Jarcho
Further enhance `needless_borrow`, mildly refactor `redundant_clone`

This PR does the following:
* Moves some code from `redundant_clone` into a new `clippy_utils` module called `mir`, and wraps that code in a function called `dropped_without_further_use`.
* Relaxes the "is copyable" condition condition from #9136 by also suggesting to remove borrows from values dropped without further use. The changes involve the just mentioned function.
* Separates `redundant_clone` into modules.

Strictly speaking, the last bullet is independent of the others. `redundant_clone` is somewhat hairy, IMO. Separating it into modules makes it slightly less so, by helping to delineate what depends upon what.

I've tried to break everything up into digestible commits.

r? `@Jarcho`

(`@Jarcho` I hope you don't mind.)

changelog: continuation of #9136
2022-10-08 21:24:54 +00:00
bors
292e313259 Auto merge of #9451 - kraktus:manual_filter2, r=dswij
Add `manual_filter` lint for `Option`

Share much of its implementation with `manual_map` and should greatly benefit from its previous feedback.
I'm sure it's possible to even more refactor both and would gladly take input on that as well as any clippy idiomatic usage, since this is my first lint addition.

I've added the lint to the complexity section for now, I don't know if every new lint needs to go in nursery first.

The matching could be expanded to more than `Some(<value>)` to lint on arbitrary struct matching inside the `Some` but I've left it like it was for `manual_map` for now. `needless_match::pat_same_as_expr` provides a more generic match example.

close https://github.com/rust-lang/rust-clippy/issues/8822

changelog: Add lint [`manual_filter`] for `Option`
2022-10-08 15:58:51 +00:00
Jason Newcomb
39a7d000b6 Don't suggest moving tuple structs with a significant drop to late evaluation. 2022-10-08 11:23:05 -04:00
kraktus
6f4546a4be [unnecessary_cast] Do not lint negative hexadecimal literals when cast as float
Floats cannot be expressed as hexadecimal literals
2022-10-08 16:15:18 +02:00
Urgau
5f6e1d397a Stabilize half_open_range_patterns 2022-10-08 11:00:13 +02:00
Ralf Jung
e91746ed82 make const_err a hard error 2022-10-07 18:08:49 +02:00
bors
2c8e473ffe Auto merge of #9585 - rust-lang:extend-box-default, r=Alexendoo
extend `box-default` lint, add suggestion

This extends the recently added `box-default` lint to also cover `Box::new(vec![])`, `Box::new(String::from(""))` and `Box::new(Vec::from([]))`. Also the lint now suggests a suitable replacement. I did not find a simple way to check whether the type is fully determined by the outside, so I at least checked for some variations to remove the turbofish in those cases.

---

changelog: none
2022-10-07 14:49:54 +00:00
Samuel Moelius
9cc8da222b Fix adjacent code 2022-10-07 05:07:44 -04:00
Samuel Moelius
037f698147 needless_borrow uses used_exactly_once 2022-10-07 05:07:44 -04:00
bors
65ae6666c8 Auto merge of #9595 - Alexendoo:author-let-chains, r=Jarcho
Replace if_chain with let chains in `clippy::author` output

Should help nudge new contributors towards let chains

changelog: none
2022-10-07 02:52:47 +00:00
Evan Typanski
23b16998c3 Add curlies to scrutinees with side effects 2022-10-06 15:14:55 -04:00
Philipp Krones
09a554db25 Merge commit '8f1ebdd18bdecc621f16baaf779898cc08cc2766' into clippyup 2022-10-06 17:41:53 +02:00
bors
8f1ebdd18b Auto merge of #9593 - Andy-Python-Programmer:master, r=llogiq
lint::unsafe_removed_from_name: fix false positive result when allowed

changelog: [`unsafe_removed_from_name`] Fix allowing on imports produces a false positive on `useless_attribute`.

Fixes: #9197

Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
2022-10-06 14:39:26 +00:00
Andre Bogus
d3c041a086 extend box-default lint, add suggestion 2022-10-06 16:00:45 +02:00
Yuri Astrakhan
cfd6c8d19d Add a temporary workaround for multiline formart arg inlining
per suggestion in
https://github.com/rust-lang/rust/pull/102729#discussion_r988990080

workaround for an internal crash when handling multi-line format
argument inlining.
2022-10-06 09:24:57 -04:00
Philipp Krones
d75b25faab Merge commit 'ac0e10aa68325235069a842f47499852b2dee79e' into clippyup 2022-10-06 09:44:38 +02:00
Philipp Krones
e2808afd60
Merge remote-tracking branch 'upstream/master' into rustup 2022-10-06 09:19:29 +02:00
Alex Macleod
9e70a0ff12 Replace if_chain with let chains in clippy::author output 2022-10-05 17:21:32 +00:00
bors
887ba0c5a4 Auto merge of #9586 - Alexendoo:format-args-commas, r=Manishearth
FormatArgsExpn: Find comma spans and ignore weird proc macro spans

Fixes the following cases:

A missing `, 1` from the `expect_fun_call` suggestion:

```rust
Some(()).expect(&format!("{x} {}", 1));
```
```
warning: use of `expect` followed by a function call
 --> t.rs:7:14
  |
7 |     Some(()).expect(&format!("{x} {}", 1));
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `unwrap_or_else(|| panic!("{x} {}"))`
```

The suggestion removing from the comma in the comment rather than the one after the format string:

```rust
println!(
    "{}",
    // a comment, with a comma in it
    x
);
```
```
warning: variables can be used directly in the `format!` string
  --> t.rs:9:5
   |
9  | /     println!(
10 | |         "{}",
11 | |         // a comment, with a comma in it
12 | |         x
13 | |     );
   | |_____^
   |
help: change this to
   |
10 ~         "{x}",
11 ~         // a comment
   |
```

It also no longer accepts expansions where a format string or argument has a "weird" proc macro span, that is one where the literal/expression it outputs has the span of one of its inputs. Kind of like a `format_args` specific `clippy_utils::is_from_proc_macro`, e.g. `format!(indoc! {" ... "})`

changelog: [`expect_fun_call`]: Fix suggestion for `format!` using captured variables
changelog: [`print_literal`], [`write_literal`], [`uninlined_format_args`]: Fix suggestion when following a comment including a comma
2022-10-05 16:27:03 +00:00
Alex Macleod
9226066bcb FormatArgsExpn: Find comma spans and ignore weird proc macro spans 2022-10-05 16:10:52 +00:00
Alex Macleod
86c86c3742 Add disallowed_macros lint 2022-10-05 13:44:06 +00:00
Andy-Python-Programmer
14f9f2b69d
lint::unsafe_removed_from_name: fix false positive result when allowed
* Allowing `unsafe_removed_from_name` on imports produces a false
positive on `useless_attribute`.

Fixes: #9197

Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
2022-10-05 18:59:01 +11:00
bors
425e1ea73d Auto merge of #9587 - c410-f3r:arith, r=Alexendoo
[arithmetic-side-effects] Do not ignore literal references

To my utter surprise, `rustc` does does not warn stuff like `let n: u8 = &255 + &1` or `let n: u8 = 255 + &1`.

changelog: [arithmetic-side-effects] Do not ignore literal references
2022-10-04 11:05:24 +00:00
bors
2f90b2acbd Auto merge of #9547 - nyurik:capt, r=flip1995
fallout: fix tests to allow uninlined_format_args

In order to switch `clippy::uninlined_format_args` from pedantic to style, all existing tests must not raise a warning. I did not want to change the actual tests, so this is a relatively minor change that:

* add `#![allow(clippy::uninlined_format_args)]` where needed
* normalizes all allow/deny/warn attributes
   * all allow attributes are grouped together
   * sorted alphabetically
   * the `clippy::*` attributes are listed separate from the other ones.
   * deny and warn attributes are listed before the allowed ones

See also https://github.com/rust-lang/rust-clippy/pull/9233, https://github.com/rust-lang/rust-clippy/pull/9525, https://github.com/rust-lang/rust-clippy/pull/9527

cc: `@llogiq` `@Alexendoo`

changelog: none
2022-10-04 07:20:24 +00:00
Caio
2a6a98f95b [arithmetic-side-effects] Do not ignore literal references 2022-10-03 19:49:03 -03:00
bors
e8c1b5478c Auto merge of #9559 - c410-f3r:arith, r=Alexendoo
Fix #9544

Fix #9544

r? `@Alexendoo`

changelog: [`arithmetic_side_effects`]: Fix false negative for `CustomType / usize`, `CustomType * float` and similar
2022-10-03 21:54:08 +00:00
Caio
99363fef65 Address comments 2022-10-03 18:36:12 -03:00
bors
5825ae7bd4 Auto merge of #9581 - ebobrow:mul-add-negative, r=Manishearth
`suboptimal_flops` lint for multiply and subtract

fixes #9526

changelog: [`suboptimal_flops`] lint for multiply and subtract
2022-10-03 17:12:10 +00:00
royrustdev
f1c831ad17 add implicit_saturating_add lint 2022-10-03 16:46:38 +05:30
Elliot Bobrow
15431b36bb
Merge branch 'master' into mul-add-negative 2022-10-02 21:27:57 -07:00
Elliot Bobrow
7747032b77 suboptimal_flops lint for multiply and subtract 2022-10-02 21:00:51 -07:00
TennyZhuang
bf18768219 let upper_case_acronyms check the enum name
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-03 10:11:57 +08:00
bors
bef93d3b14 Auto merge of #7962 - Jarcho:fix_match_type_on_diagnostic_items, r=llogiq
Fix and improve `match_type_on_diagnostic_item`

This extracts the fix for the lint out of #7647. There's still a couple of other functions to check, but at least this will get lint working again.

The two added util functions (`is_diagnostic_item` and `is_lang_item`) are needed to handle `DefId` for unit and tuple struct/variant constructors. The `rustc_diagnostic_item` and `lang` attributes are attached to the struct/variant `DefId`, but most of the time they are used through their constructors which have a different `DefId`. The two utility functions will check if the `DefId` is for a constructor and switch to the associated struct/variant `DefId`.

There does seem to be a bug on rustc's side where constructor `DefId`s from external crates seem to be returning `DefKind::Variant` instead of `DefKind::Ctor()`. There's a workaround put in right.

changelog: None
2022-10-02 19:46:46 +00:00
Yuri Astrakhan
eb3970285b fallout: fix tests to allow uninlined_format_args
In order to switch `clippy::uninlined_format_args` from pedantic to
style, all existing tests must not raise a warning. I did not want to
change the actual tests, so this is a relatively minor change that:

* add `#![allow(clippy::uninlined_format_args)]` where needed
* normalizes all allow/deny/warn attributes
   * all allow attributes are grouped together
   * sorted alphabetically
   * the `clippy::*` attributes are listed separate from the other ones.
   * deny and warn attributes are listed before the allowed ones

changelog: none
2022-10-02 15:13:22 -04:00
bors
0341198ba1 Auto merge of #9574 - Alexendoo:unused-fixed, r=Jarcho
Remove unused `.fixed` files, only run asm_syntax doctests on x86

Two small changes, removes some unused `.fixed` and makes `clippy_lints` doctests pass on non x86 arches

changelog: none
2022-10-02 19:06:58 +00:00
Jason Newcomb
162aa19793 Fix and improve internal lint checking for match_type usages
* Check for `const`s and `static`s from external crates
* Check for `LangItem`s
* Handle inherent functions which have the same name as a field
* Also check the following functions:
    * `match_trait_method`
    * `match_def_path`
    * `is_expr_path_def_path`
    * `is_qpath_def_path`
* Handle checking for a constructor to a diagnostic item or `LangItem`
2022-10-02 15:02:55 -04:00
bors
f8ba19287d Auto merge of #9576 - TennyZhuang:unnecessary_cast_for_non_literal_expr, r=llogiq
let unnecessary_cast work for trivial non_literal expressions

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

---

changelog: [`unnecessary_cast`]: fix for trivial non_literal expressions

Fixes #9562
2022-10-02 15:26:45 +00:00
bors
11a6d19c59 Auto merge of #9479 - kraktus:manual_assert2, r=llogiq
[`manual_assert`]: Preserve comments in the suggestion

close https://github.com/rust-lang/rust-clippy/issues/7730

changelog: [`manual_assert`]: Preserve comments in the suggestion
2022-10-02 15:13:32 +00:00
TennyZhuang
f2043989ca ignore the lint on some test files
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-02 23:02:13 +08:00
TennyZhuang
081f73954b let unnecessary_cast work for trivial non_literal expressions
Signed-off-by: TennyZhuang <zty0826@gmail.com>
2022-10-02 23:02:11 +08:00
bors
ac12011315 Auto merge of #9577 - kraktus:unnecessary_cast, r=llogiq
[`unnecessary_cast`] add parenthesis when negative number uses a method

fix #9563

The issue was probably introduced by 90fe3bea52

changelog: [`unnecessary_cast`] add parenthesis when negative number uses a method

r? llogiq
2022-10-02 14:18:41 +00:00
kraktus
3ab02aa359 fix tests 2022-10-02 15:25:50 +02:00
kraktus
a35734c172 revert manual_assert suggestion refactor
Because `Sugg` helper does not simplify multiple negations
2022-10-02 15:03:48 +02:00
kraktus
2c04c1a188 [manual_assert]: Preserve comments in the suggestion 2022-10-02 15:03:48 +02:00
kraktus
90b446fd38 [unnecessary_cast] add parenthesis when negative number uses a method 2022-10-02 14:35:38 +02:00
Alex Macleod
52a68dc097 lint nested patterns and slice patterns in needless_borrowed_reference 2022-10-01 22:31:10 +00:00
Alex Macleod
5a54db1286 Remove unused .fixed files 2022-10-01 22:24:48 +00:00
bors
64243c6f99 Auto merge of #9484 - Xaeroxe:clamping-without-clamp, r=Alexendoo
Implement `manual_clamp` lint

Fixes #9477
Fixes #6751

Identifies common patterns where usage of the `clamp` function would be more succinct and clear, and suggests using the `clamp` function instead.

changelog: [`manual_clamp`]: Implement manual_clamp lint
2022-10-01 20:55:20 +00:00
Jacob Kiesel
b221184572 Implement manual_clamp lint 2022-10-01 13:58:41 -06:00