Commit Graph

8767 Commits

Author SHA1 Message Date
Niki4tap
cc98574883 Fix comments, use constant instead of raw constant_context 2022-12-18 22:47:02 +03:00
Niki4tap
20f501a9d9 Improve code style further 2022-12-18 22:39:06 +03:00
Niki4tap
9b2fc8e2a2 Make clippy happy 2022-12-18 19:43:26 +03: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
Niki4tap
b1ca307168 Address some of the code style issues 2022-12-18 18:58:15 +03:00
Niki4tap
dae54fad3e Doc codeblock fixup 2022-12-18 03:20:04 +03:00
Niki4tap
54a9168efb Remove useless pattern matching 2022-12-18 03:02:45 +03:00
Niki4tap
42106e0495 Add lint fn_null_check 2022-12-18 03:02:45 +03:00
Niki4tap
3cc67d0856 Relax clippy_utils::consts::miri_to_const pointer type restrictiveness 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
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
1f1d23cf51
Bump Clippy version -> 0.1.68 2022-12-17 13:57:41 +01: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
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
5b3a6669f7 fix manual_filter false positive
do explicit checks for the other branch being None
2022-12-15 23:53:28 -05:00
bors
3905f51230 Auto merge of #10073 - xFrednet:changelog-1-66, r=Alexendoo
Changelog 1.66

It's really nice to see a changelog with so many suggestion fixes and improvements. Not much else to say. This should be merged with the coming release on 2022-12-15. For the reviewer, please review it and approve it if it looks good. The merge should wait until the release :)

---

changelog: none

<!-- changelog_checked -->
2022-12-15 16:12:12 +00:00
Oli Scherer
fa87abf963 Remove TraitRef::new 2022-12-14 15:36:39 +00:00
Oli Scherer
65069d5c5b Ensure no one constructs AliasTys themselves 2022-12-14 15:36:39 +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
xFrednet
2532c56d86
Update version attribute for 1.66 lints 2022-12-13 23:36:47 +01:00
Michael Goulet
957ab6ae52 Combine projection and opaque into alias 2022-12-13 17:48:55 +00:00
Michael Goulet
89b8840543 squash OpaqueTy and ProjectionTy into AliasTy 2022-12-13 17:40:27 +00:00
Michael Goulet
a274e7e9a2 ProjectionTy.item_def_id -> ProjectionTy.def_id 2022-12-13 17:34:44 +00:00
Michael Goulet
ad55e4c972 Use ty::OpaqueTy everywhere 2022-12-13 17:29:26 +00:00
naosense
1f862c2ad3 remove assert macro 2022-12-13 21:43:16 +08:00
naosense
949d0709bd improve document 2022-12-13 16:52:55 +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
bors
17a092f467 Auto merge of #105160 - nnethercote:rm-Lit-token_lit, r=petrochenkov
Remove `token::Lit` from `ast::MetaItemLit`.

Currently `ast::MetaItemLit` represents the literal kind twice. This PR removes that redundancy. Best reviewed one commit at a time.

r? `@petrochenkov`
2022-12-12 05:16:50 +00: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
Samuel Moelius
2d444a92f6 Fix #10021 2022-12-08 20:09:08 +01: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
2701a4076f Fix #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
Nicholas Nethercote
6481d37bb9 Add StrStyle to ast::LitKind::ByteStr.
This is required to distinguish between cooked and raw byte string
literals in an `ast::LitKind`, without referring to an adjacent
`token::Lit`. It's a prerequisite for the next commit.
2022-12-02 10:38:58 +11: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
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
Vadim Petrochenkov
9314e5b942 rustc_hir: Change representation of import paths to support multiple resolutions 2022-12-01 18:51:05 +03:00
Vadim Petrochenkov
4f8c49e950 rustc_hir: Relax lifetime requirements on Visitor::visit_path 2022-12-01 17:04:02 +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
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
dswij
c502dee41e Use snippet_with_context instead of _with_macro_callsite 2022-11-30 14:50:13 +08:00
bors
bfb973f1c7 Auto merge of #9975 - xFrednet:0000-refutable-slice-pedantic, r=llogiq
Move `index_refutable_slice` to `pedantic`

During the creation, I out this lint into the nursery group to let it run in the wild before moving it to a commonly used group. This move never happened until now, though. It should be safe, as Clippy and I have been using it for months and there are no open issues for is :)

---

changelog: Move `index_refutable_slice` to `pedantic` (Now warn-by-default)
[#9975](https://github.com/rust-lang/rust-clippy/pull/9975)
2022-11-29 11:16:01 +00: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
c9bf4b75ce resolve conflicts 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
naosense
96f1385fdd add suppress_lint_in_const conf 2022-11-29 15:00:13 +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
xFrednet
6bbf16660b
Move index_refutable_slice to pedantic 2022-11-28 20:23:09 +01: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
Lukas Wirth
f62eab4312 Adjust description once more 2022-11-28 10:40:08 +01:00
Nicholas Nethercote
5011c675ad Rename ast::Lit as ast::MetaItemLit. 2022-11-28 15:18:49 +11:00