Commit graph

17009 commits

Author SHA1 Message Date
Jason Newcomb
58132cb3b0 Improve SpanlessEq
* Don't consider expansions of different macros to be the same, even if they expand to the same tokens
* Don't consider `cfg!` expansions to be equal if they check different configs.
2023-05-18 16:42:13 -04:00
Jason Newcomb
5351170744 Slightly refactor constant evaluation and add detection for empty macro expansion and cfged statements. 2023-05-18 15:43:33 -04:00
Jason Newcomb
0b3c2ed811 Search for inactive cfg attributes and empty macro expansion through
the entire block
2023-05-18 15:43:23 -04:00
bors
392e9551d4 Auto merge of #10798 - Alexendoo:unnameable-ty-suggestions, r=Jarcho
Don't suggest unnameable types in `box_default`, `let_underscore_untyped`

changelog: [`box_default`], [`let_underscore_untyped`]: Don't suggest unnameable types
2023-05-18 18:58:53 +00:00
Alex Macleod
cfa5aa2aad Don't suggest unnameable types in box_default, let_underscore_untyped 2023-05-18 18:51:27 +00:00
bors
22b319606f Auto merge of #10753 - disco07:master, r=xFrednet
redundant_pattern_matching

This PR try to solve this issue https://github.com/rust-lang/rust-clippy/pull/10726,
but it enter in conflict with another test.

changelog: none

Try to test this:
```
let _w = match x {
     Some(_) => true,
     _ => false,
};
```

this happen:
```
 error: match expression looks like `matches!` macro
   --> $DIR/match_expr_like_matches_macro.rs:21:14
    |
 LL |       let _w = match x {
    |  ______________^
 LL | |         Some(_) => true,
 LL | |         _ => false,
 LL | |     };
    | |_____^ help: try this: `matches!(x, Some(_))`

+error: redundant pattern matching, consider using `is_some()`
+  --> $DIR/match_expr_like_matches_macro.rs:21:14
+   |
+LL |       let _w = match x {
+   |  ______________^
+LL | |         Some(_) => true,
+LL | |         _ => false,
+LL | |     };
+   | |_____^ help: try this: `x.is_some()`
+   |
+   = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
+
```
I need some help to fix this. Thanks
2023-05-18 09:52:27 +00:00
est31
ef38662d04 Some improvements to the manual_let_else lint suggestions
* Replace variables inside | patterns in the if let: let v = if let V::A(v) | V::B(v) = v { v } else ...
* Support nested patterns: let v = if let Ok(Ok(Ok(v))) = v { v } else ...
* Support tuple structs with more than one arg: let v = V::W(v, _) = v { v } else ...
* Correctly handle .. in tuple struct patterns: let v = V::X(v, ..) = v { v } else ...
2023-05-18 11:16:57 +02:00
est31
83a4b0987f Fix formatting of if let chain 2023-05-18 07:56:04 +02:00
bors
270cbeb735 Auto merge of #10674 - c410-f3r:macro-lint, r=Jarcho
Rename `integer_arithmetic`

The lack of official feedback in #10200 made me give up on pursuing the matter but after yet another use-case that is not handled by `integer_arithmetic` (#10615), I think it is worth trying again.

---

changelog: Move/Deprecation: Rename `integer_arithmetic` to `arithmetic_side_effects`
[#10674](https://github.com/rust-lang/rust-clippy/pull/10674)
<!-- changelog_checked -->
2023-05-18 05:26:33 +00:00
bors
815a07e667 Auto merge of #10725 - y21:issue9914, r=Jarcho
don't remove `dbg!` in arbitrary expressions

Fixes #9914

The `dbg_macro` lint replaces empty `dbg!` invocations with the empty string in its suggestion, which is not always valid code in certain contexts (e.g. `let _ = dbg!();` becomes `let _ = ;`). This PR changes it to `()`, which should always be valid where `dbg!()` is valid (`dbg!()` with no arguments evaluates to `()`).

It also special-cases "standalone" `dbg!();` expression statements, where it will suggest removing the whole statement entirely like it did before.

changelog: [`dbg_macro`]: don't remove `dbg!()` in arbitrary expressions as it sometimes results in syntax errors
2023-05-18 05:11:52 +00:00
bors
cf182b9f43 Auto merge of #10789 - Centri3:patch-1, r=xFrednet
fix example heading in `string_slice`

changelog: none
2023-05-18 02:22:41 +00:00
bors
9cd483d5c9 Auto merge of #10786 - mickvangelderen:remove-unnecessary-clone-from-needless-collect-example, r=Alexendoo
Remove unnecessary `clone` from `needless_collect` example

The example for [clippy::needless_collect](https://rust-lang.github.io/rust-clippy/master/#needless_collect) is written as follows:

```rust
let len = iterator.clone().collect::<Vec<_>>().len();
// should be
let len = iterator.count();
```

With this change, the unnecessary `clone()` is removed and the the standard

    ### Example
    ```rust
    // original
    ```
    Use instead:
    ```rust
    // improved
    ```

structure is followed.

Discussion: https://github.com/rust-lang/rust-clippy/discussions/10784#discussion-5198885

changelog: [`needless_collect`]: Cleaned up the example in the lint documentation.
2023-05-18 02:11:02 +00:00
bors
f3f6fd8920 Auto merge of #10775 - lochetti:fix_10723, r=xFrednet
Ignoring `let_underscore_untyped` warnings in code from proc macros

Don't linting let_underscore_untyped if code was generated by procedural macro.

This PR fixes https://github.com/rust-lang/rust-clippy/issues/10723

---

closes: https://github.com/rust-lang/rust-clippy/issues/10723

changelog: Fix: [`let_underscore_untyped`]: No longer lints inside proc macros
[#10775](https://github.com/rust-lang/rust-clippy/pull/10775)
<!-- changelog_checked -->
2023-05-18 01:59:38 +00:00
bors
223f5184ba Auto merge of #10682 - J-ZhengLi:issue10680, r=dswij
fix [`invalid_regex`] not recognizing new syntax introduced after regex-1.8.0

fixes: #10680

---

changelog: fix [`invalid_regex`] not recognizing new syntax introduced after regex-1.8.0

bump up `regex-syntax` dependency version to 0.7.0
2023-05-18 01:46:01 +00:00
bors
407c352688 Auto merge of #10337 - EliasHolzmann:fix/10335, r=dswij
Fix: Some suggestions generated by the option_if_let_else lint did not compile

This addresses a bug in Clippy where the fix suggestend by the `option_if_let_else` lint would not compile for `Result`s which have an impure expression in the `else` branch.

---

changelog: [`option_if_let_else`]: Fixed incorrect suggestion for `Result`s
[#10337](https://github.com/rust-lang/rust-clippy/pull/10337)
<!-- changelog_checked -->

Fixes #10335.
2023-05-18 01:34:19 +00:00
bors
7e18451633 Auto merge of #10175 - koka831:fix/10171, r=giraffate
Use original variable name in the suggestion

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

---

changelog: Sugg: [`manual_let_else`]: Now suggest the correct variable name
[#10175](https://github.com/rust-lang/rust-clippy/pull/10175)
<!-- changelog_checked -->
2023-05-18 01:21:27 +00:00
León Orell Valerian Liehr
0eb364b8d6 Exclude inherent projections from some alias ty matches 2023-05-17 23:53:58 +02:00
adrianEffe
591f5f7ea9
Update urls in Type Checking 2023-05-17 22:55:14 +03:00
Dylan DPC
506b50ee39 Rollup merge of #111648 - Nilstrieb:language-items, r=WaffleLapkin
Remove `LangItems::require`

It's just a short wrapper used by `tcx.require_lang_item`. Deleting it gives us a negative diff.
2023-05-17 11:13:56 +05:30
Catherine
ae40b7f8cc
fix example heading in string_slice 2023-05-16 18:11:20 -05:00
Centri3
97467e4aa3 change clippy::version to 1.71.0 2023-05-16 16:29:31 -05:00
Nilstrieb
fc126379be Remove LangItems::require
It's just a short wrapper used by `tcx.require_lang_item`. Deleting it
gives us a negative diff.
2023-05-16 19:53:38 +02:00
Centri3
4ff1cd365d add description and rename msrv tests 2023-05-16 11:20:00 -05:00
Renato Lochetti
2d9d81fc1e
Checking for proc_macro not only when local.init is Some 2023-05-16 09:36:22 +01:00
Mick van Gelderen
79eb06c6ec
Remove unnecessary from example 2023-05-15 22:24:37 +02:00
y21
f0be0ee1aa handle nested macros and add tests for them 2023-05-15 21:45:28 +02:00
Catherine
f6a0437e74
Update clippy_lints/src/casts/ptr_cast_constness.rs
Co-authored-by: llogiq <bogusandre@gmail.com>
2023-05-15 13:14:45 -05:00
disco07
79a8867add update test option 2023-05-15 19:43:22 +02:00
bors
c4909746ad Auto merge of #10781 - flip1995:stepping-down, r=xFrednet
flip1995: Stepping down from the reviewer rotation

A step I was trying to avoid for way too long, but sadly necessary now. I hope I can come back stronger in a few months.

More explanation on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Stepping.20back.20from.20review.20rotation/near/358384096)

changelog: none
2023-05-15 11:34:01 +00:00
Philipp Krones
9c6350b19c
flip1995: Stepping down from the reviewer rotation
A step I was trying to avoid for way too long, but sadly necessary now. I hope I
can come back stronger in a few months.
2023-05-15 10:00:14 +02:00
Centri3
c5a914b181 check msrv 2023-05-14 19:31:12 -05:00
Centri3
8c191add87 the implementation!! 2023-05-14 19:25:23 -05:00
bors
590c9fc108 Auto merge of #10778 - Centri3:type-alias-fix, r=llogiq
Don't emit clippy::useless_conversion on type aliases

Fixes #10773

changelog: Enhancement: [`useless_conversion`]: Don't lint on type aliases
2023-05-14 20:24:27 +00:00
Centri3
a36d9a7820 move is_ty_alias to clippy_utils 2023-05-14 12:39:08 -05:00
Centri3
1190c02bb8 fix #10773 2023-05-14 12:21:23 -05:00
Icxolu
84f89f30eb enhance needless_collect
Updates `needless_collect` to lint for collecting into a method or
function argument thats taking an `IntoIterator` (for example `extend`).
Every `Iterator` trivially implements `IntoIterator` and colleting it
only causes an unnecessary allocation.
2023-05-14 18:47:16 +02:00
David Tolnay
fcb132765c Exposes false negative in clippy's diverging_sub_expression 2023-05-14 07:58:45 -07:00
Caio
493b2ae8dc Rename integer_arithmetic 2023-05-14 08:37:12 -03:00
Renato Lochetti
df200aaf39
fixing fmt 2023-05-14 10:38:32 +01:00
Renato Lochetti
e234dfa63e
Ignoring let_underscore_untyped warnings in code from proc macros 2023-05-14 10:26:48 +01:00
bors
a167973e81 Auto merge of #10768 - c410-f3r:arith-3, r=Jarcho
[arithmetic_side_effects] Consider referenced allowed or hard-coded types

Fix #10767

```
changelog: [`arithmetic_side_effects`]: Do not fire when dealing with allowed or hard-coded types that are referenced.
```
2023-05-14 04:41:41 +00:00
Caio
891fffef0c Consider referenced allowed or hard-coded types 2023-05-13 23:24:33 -03:00
bors
fff790b659 Auto merge of #10691 - jdswensen:jds/fix-doc-empty-line, r=Jarcho
fix: warn on empty line outer AttrKind::DocComment

changelog: [`empty_line_after_doc_comments`]: add lint for checking empty lines after rustdoc comments.

Fixes: #10395
2023-05-12 16:39:02 +00:00
bors
6cbd7679ed Auto merge of #10772 - giraffate:update_actions_setup-node, r=flip1995
Update actions/setup-node

Follow up of https://github.com/rust-lang/rust-clippy/pull/10771. One warning remains: https://github.com/rust-lang/rust-clippy/actions/runs/4959567213

changelog: none
2023-05-12 14:07:54 +00:00
Takayuki Nakata
fce41cef7f Update actions/setup-node 2023-05-12 23:05:20 +09:00
bors
035c45727e Auto merge of #10771 - giraffate:update_actions_checkout, r=flip1995
Update actions/checkout

Suppress the warning in GitHub Actions: https://github.com/rust-lang/rust-clippy/actions/runs/4941438718

changelog: none
2023-05-12 13:46:43 +00:00
Takayuki Nakata
8100a8843b Update actions/checkout 2023-05-12 22:39:33 +09:00
bors
3d456ce5b0 Auto merge of #10769 - Icxolu:manual_next_back, r=giraffate
add lint `manual_next_back`

changelog: [`manual_next_back`]: checks for manual reverse iteration (`.rev().next()`) of a `DoubleEndedIterator`

fixes #10274
2023-05-12 13:34:15 +00:00
Icxolu
a8834bc46a add lint manual_next_back
checks for manual reverse iteration (`.rev().next()`) of a
`DoubleEndedIterator`
2023-05-11 22:25:14 +02:00
disco07
c53ceba56f update tests 2023-05-11 07:20:02 +02:00