]> git.lizzy.rs Git - rust.git/log
rust.git
2 years agoUse the traits added to the Rust 2021 Edition prelude
Koichi ITO [Tue, 10 May 2022 16:03:52 +0000 (01:03 +0900)]
Use the traits added to the Rust 2021 Edition prelude

Follow up https://github.com/rust-lang/rust/pull/96861.

This PR uses the traits added to the Rust 2021 Edition prelude.

> The `TryInto`, `TryFrom` and `FromIterator` traits are now part of the prelude.

https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html

2 years agoAuto merge of #8796 - nsunderland1:master, r=giraffate
bors [Tue, 10 May 2022 13:25:27 +0000 (13:25 +0000)]
Auto merge of #8796 - nsunderland1:master, r=giraffate

New lint: [`derive_partial_eq_without_eq`]

Introduces a new lint, [`derive_partial_eq_without_eq`].

See: #1781 (doesn't close it though).

changelog: add lint [`derive_partial_eq_without_eq`]

2 years agoAuto merge of #8769 - yonip23:8719, r=xFrednet
bors [Tue, 10 May 2022 12:21:12 +0000 (12:21 +0000)]
Auto merge of #8769 - yonip23:8719, r=xFrednet

introduce rc_clone_in_vec_init lint

Closes #8719

changelog: Introduce [`rc_clone_in_vec_init`] lint

2 years agointroduce rc_clone_in_vec_init lint
yonip23 [Sun, 8 May 2022 19:20:25 +0000 (22:20 +0300)]
introduce rc_clone_in_vec_init lint

2 years agoNew lint: [`derive_partial_eq_without_eq`]
nsunderland1 [Fri, 6 May 2022 07:10:11 +0000 (00:10 -0700)]
New lint: [`derive_partial_eq_without_eq`]

2 years agoAuto merge of #8809 - Alexendoo:metadata-collection-expect, r=xFrednet
bors [Mon, 9 May 2022 19:55:37 +0000 (19:55 +0000)]
Auto merge of #8809 - Alexendoo:metadata-collection-expect, r=xFrednet

Ignore unfulfilled_lint_expectations in metadata collection

r? `@xFrednet`

When metadata collection is enabled the regular early/late pass registrations are skipped, which the `#[expect()]`s were no fan of: https://github.com/rust-lang/rust-clippy/runs/6356675328?check_suite_focus=true

changelog: none

2 years agoIgnore unfulfilled_lint_expectations in metadata collection
Alex Macleod [Mon, 9 May 2022 19:30:06 +0000 (20:30 +0100)]
Ignore unfulfilled_lint_expectations in metadata collection

2 years agoAuto merge of #8797 - xFrednet:0000-expect-a-playground, r=flip1995
bors [Mon, 9 May 2022 17:14:43 +0000 (17:14 +0000)]
Auto merge of #8797 - xFrednet:0000-expect-a-playground, r=flip1995

Replace `#[allow]` with `#[expect]` in Clippy

Hey `@rust-lang/clippy,` `@Alexendoo,` `@dswij,` I'm currently working on the expect attribute as defined in [Rust RFC 2383](https://rust-lang.github.io/rfcs/2383-lint-reasons.html). With that, an `#[allow]` attribute can be replaced with a `#[expect]` attribute that suppresses the lint, but also emits a warning, if the lint isn't emitted in the expected scope.

With this PR I would like to test the attribute on a project scale and Clippy obviously came to mind. This PR replaces (almost) all `#[allow]` attributes in `clippy_utils` and `clippy_lints` with the `#[expect]` attribute. I was also able to remove some allows since, the related FPs have been fixed :tada:.

My question is now, are there any concerns regarding this? It's still okay to add normal `#[allow]` attributes, I see the need to nit-pick about that in new PRs, unless it's actually a FP. Also, I would not recommend using `#[expect]` in tests, as changes to a lint could the trigger the expect attribute in other files.

Additionally, I've noticed that Clippy has a bunch of `#[allow(clippy::too_many_lines)]` attributes. Should we maybe allow the lint all together or increase the threshold setting? To me, it seems like we mostly just ignore it in our code. :sweat_smile: :upside_down_face:

---

changelog: none

r? `@flip1995` (I've requested you for now, since you're also helping with reviewing the expect implementation. You are welcome to delegate this PR, even if it should be a simple review :upside_down_face: )

2 years agoAuto merge of #8805 - Alexendoo:let-chain-docs, r=flip1995
bors [Mon, 9 May 2022 13:56:53 +0000 (13:56 +0000)]
Auto merge of #8805 - Alexendoo:let-chain-docs, r=flip1995

Recommend let chains over if_chain in docs

Switches over bit_mask.rs to let chains in order to create a nice example

While the rustfmt thing isn't resolved yet, my rust-analyzer isn't a fan of large `if_chains!`s, it stops giving me hover info and such after some number of if statements

changelog: none

2 years agoRecommend let chains over if_chain in docs
Alex Macleod [Mon, 9 May 2022 13:23:16 +0000 (14:23 +0100)]
Recommend let chains over if_chain in docs

2 years agouse let chains in bit_mask.rs
Alex Macleod [Mon, 9 May 2022 13:06:46 +0000 (14:06 +0100)]
use let chains in bit_mask.rs

2 years agoAuto merge of #8802 - smoelius:allow-expect-unwrap-in-tests, r=llogiq
bors [Sun, 8 May 2022 15:00:30 +0000 (15:00 +0000)]
Auto merge of #8802 - smoelius:allow-expect-unwrap-in-tests, r=llogiq

Optionally allow `expect` and `unwrap` in tests

This addresses #1015, except it makes the new behavior optional.

The reason for the msrv-related changes is as follows.

Rather than expand `check_methods` list of arguments, it seemed easier to make `check_methods` a method of `Methods`, so that `check_methods` could access `Methods`' fields.

`check_methods` had an `msrv` parameter, which I consequently made a field of `Methods`. But, to avoid adding a lifetime parameter to `Methods`, I made the field type `Option<RustcVersion>` instead of the parameter's existing type, `Option<&RustcVersion>`. This seemed sensible since `RustcVersion` implements `Copy`. But this broke a lot of code that expected an `Option<&RustcVersion>` or `&Option<RustcVersion>`. I changed all of those occurrences to `Option<RustcVersion>`. IMHO, the code is better as a result of these changes, though.

The msrv-related changes are in their own commit to (hopefully) ease review.

Closes #1015

changelog: optionally allow `expect` and `unwrap` in tests

r? `@llogiq`

2 years agoOptionally allow `expect` and `unwrap` in tests
Samuel E. Moelius III [Sun, 8 May 2022 10:44:58 +0000 (06:44 -0400)]
Optionally allow `expect` and `unwrap` in tests

2 years agoPass msrvs by copy
Samuel E. Moelius III [Sun, 8 May 2022 11:13:14 +0000 (07:13 -0400)]
Pass msrvs by copy

2 years agoReplace `#[allow]` with `#[expect]` in Clippy
xFrednet [Sat, 7 May 2022 14:49:19 +0000 (16:49 +0200)]
Replace `#[allow]` with `#[expect]` in Clippy

2 years agoAuto merge of #8794 - smoelius:fix-8759, r=llogiq
bors [Sat, 7 May 2022 12:31:47 +0000 (12:31 +0000)]
Auto merge of #8794 - smoelius:fix-8759, r=llogiq

Address `unnecessary_to_owned` false positive

My proposed fix for #8759 is to revise the conditions that delineate `redundant_clone` and `unnecessary_to_owned`:
```rust
        // Only flag cases satisfying at least one of the following three conditions:
        // * the referent and receiver types are distinct
        // * the referent/receiver type is a copyable array
        // * the method is `Cow::into_owned`
        // This restriction is to ensure there is no overlap between `redundant_clone` and this
        // lint. It also avoids the following false positive:
        //  https://github.com/rust-lang/rust-clippy/issues/8759
        //   Arrays are a bit of a corner case. Non-copyable arrays are handled by
        // `redundant_clone`, but copyable arrays are not.
```
This change causes a few cases that were previously flagged by `unnecessary_to_owned` to no longer be flagged. But one could argue those cases would be better handled by `redundant_clone`.

Closes #8759

changelog: none

2 years agoAuto merge of #8793 - Alexendoo:dev-lint-extra-args, r=xFrednet
bors [Fri, 6 May 2022 16:14:11 +0000 (16:14 +0000)]
Auto merge of #8793 - Alexendoo:dev-lint-extra-args, r=xFrednet

Pass through extra args in `cargo dev lint`

changelog: Pass through extra args in `cargo dev lint`

Lets you pass some useful flags through, like `-A/W/etc`, `--fix`, `--force-warn`

2 years agoPass through extra args in `cargo dev lint`
Alex Macleod [Fri, 6 May 2022 12:21:08 +0000 (13:21 +0100)]
Pass through extra args in `cargo dev lint`

2 years agoAddress `unnecessary_to_owned` false positive
Samuel E. Moelius III [Fri, 6 May 2022 01:39:54 +0000 (21:39 -0400)]
Address `unnecessary_to_owned` false positive

2 years agoAuto merge of #8763 - arieluy:manual_range_contains, r=xFrednet
bors [Fri, 6 May 2022 11:33:47 +0000 (11:33 +0000)]
Auto merge of #8763 - arieluy:manual_range_contains, r=xFrednet

Support negative ints in manual_range_contains

fixes: #8721
changelog: Fixes issue where ranges containing ints with different signs would be
incorrect due to comparing as unsigned.

2 years agoAuto merge of #8792 - jyn514:remove-ast-json, r=flip1995
bors [Fri, 6 May 2022 09:44:19 +0000 (09:44 +0000)]
Auto merge of #8792 - jyn514:remove-ast-json, r=flip1995

Suggest -Zunpretty=ast-tree instead of -Zast-json

-Zast-json is being removed shortly: https://github.com/rust-lang/rust/pull/85993.
ast-tree does essentially the same thing, and still works today even before that PR lands.

changelog: none

2 years agoCreate RangeBounds struct
Ariel Uy [Fri, 6 May 2022 04:13:17 +0000 (21:13 -0700)]
Create RangeBounds struct

For check_range_bounds return type.

2 years agoSuggest -Zunpretty=ast-tree instead of -Zast-json
Joshua Nelson [Fri, 6 May 2022 01:11:41 +0000 (20:11 -0500)]
Suggest -Zunpretty=ast-tree instead of -Zast-json

-Zast-json is being removed shortly: https://github.com/rust-lang/rust/pull/85993.
ast-tree does essentially the same thing, and still works today even before that PR lands.

2 years agoAuto merge of #8778 - sunfishcode:main, r=giraffate
bors [Fri, 6 May 2022 00:26:18 +0000 (00:26 +0000)]
Auto merge of #8778 - sunfishcode:main, r=giraffate

Fix `cast_lossless` to avoid warning on `usize` to `f64` conversion.

Previously, the `cast_lossless` lint would issue a warning on code that
converted a `usize` value to `f64`, on 32-bit targets.

`usize` to `f64` is a lossless cast on 32-bit targets, however there is
no corresponding `f64::from` that takes a `usize`, so `cast_lossless`'s
suggested replacement does not compile.

This PR disables the lint in the case of casting from `usize` or `isize`.

Fixes #3689.

changelog: [`cast_lossless`] no longer gives wrong suggestion on usize,isize->f64

2 years agoAuto merge of #8790 - Jarcho:attribute_line, r=flip1995
bors [Thu, 5 May 2022 21:39:11 +0000 (21:39 +0000)]
Auto merge of #8790 - Jarcho:attribute_line, r=flip1995

Lint `empty_lint_after_outer_attr` on argumentless macros

Reverts the change from 034c81b76145a0514916f34713671b16f26988df as it's no longer needed. The test is left just in case. Original issue is #2475.

changelog: Lint `empty_lint_after_outer_attr` on argumentless macros again

2 years agoRevert hack fixing #2475 added in commit 034c81b76145a0514916f34713671b16f26988df...
Jason Newcomb [Thu, 5 May 2022 17:24:38 +0000 (13:24 -0400)]
Revert hack fixing #2475 added in commit 034c81b76145a0514916f34713671b16f26988df. It's no longer needed.

2 years agoAuto merge of #8789 - fedemartinezdev:master, r=flip1995
bors [Thu, 5 May 2022 17:11:06 +0000 (17:11 +0000)]
Auto merge of #8789 - fedemartinezdev:master, r=flip1995

Added missing `### What it does`

Adds the missing line to ``[`cast-slice-different-sizes`]`` lint documentation
fixes #8781

changelog: none

2 years agoAdded missing `### What it does`
Federico Martinez [Thu, 5 May 2022 16:50:34 +0000 (18:50 +0200)]
Added missing `### What it does`

Adds the missing line to cast-slice-different-sizes lint documentation
/closes 8781

2 years agoAuto merge of #8788 - flip1995:rustup, r=xFrednet,flip1995
bors [Thu, 5 May 2022 13:12:09 +0000 (13:12 +0000)]
Auto merge of #8788 - flip1995:rustup, r=xFrednet,flip1995

Rustup

r? `@ghost`

changelog: move trait_duplication_in_bounds and type_repetition_in_bounds to nursery temporarily. This could already be reverted before the release. Check the Clippy in the Rust repo beta branch when writing this changelog.

2 years agoFix ICE in EarlyAttribtues lints
flip1995 [Thu, 5 May 2022 13:10:06 +0000 (14:10 +0100)]
Fix ICE in EarlyAttribtues lints

2 years agoHACK: Move buggy lints to nursery
flip1995 [Thu, 5 May 2022 12:32:31 +0000 (13:32 +0100)]
HACK: Move buggy lints to nursery

Those lints are trait_duplication_in_bounds and
type_repetition_in_bounds. I don't think those can be fixed on the
Clippy side alone, but need changes in the compiler. So let's move them
to nursery to get the sync through and then fix them on the rustc side.

Also adds a regression test that has to be fixed before they can be
moved back to pedantic.

2 years agoBump nightly version -> 2022-05-05
flip1995 [Thu, 5 May 2022 12:32:18 +0000 (13:32 +0100)]
Bump nightly version -> 2022-05-05

2 years agoMerge remote-tracking branch 'upstream/master' into rustup
flip1995 [Thu, 5 May 2022 12:01:37 +0000 (13:01 +0100)]
Merge remote-tracking branch 'upstream/master' into rustup

2 years agoAuto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkov
bors [Wed, 4 May 2022 21:16:28 +0000 (21:16 +0000)]
Auto merge of #96546 - nnethercote:overhaul-MacArgs, r=petrochenkov

Overhaul `MacArgs`

Motivation:
- Clarify some code that I found hard to understand.
- Eliminate one use of three places where `TokenKind::Interpolated` values are created.

r? `@petrochenkov`

2 years agoOverhaul `MacArgs::Eq`.
Nicholas Nethercote [Thu, 28 Apr 2022 20:52:01 +0000 (06:52 +1000)]
Overhaul `MacArgs::Eq`.

The value in `MacArgs::Eq` is currently represented as a `Token`.
Because of `TokenKind::Interpolated`, `Token` can be either a token or
an arbitrary AST fragment. In practice, a `MacArgs::Eq` starts out as a
literal or macro call AST fragment, and then is later lowered to a
literal token. But this is very non-obvious. `Token` is a much more
general type than what is needed.

This commit restricts things, by introducing a new type `MacArgsEqKind`
that is either an AST expression (pre-lowering) or an AST literal
(post-lowering). The downside is that the code is a bit more verbose in
a few places. The benefit is that makes it much clearer what the
possibilities are (though also shorter in some other places). Also, it
removes one use of `TokenKind::Interpolated`, taking us a step closer to
removing that variant, which will let us make `Token` impl `Copy` and
remove many "handle Interpolated" code paths in the parser.

Things to note:
- Error messages have improved. Messages like this:
  ```
  unexpected token: `"bug" + "found"`
  ```
  now say "unexpected expression", which makes more sense. Although
  arbitrary expressions can exist within tokens thanks to
  `TokenKind::Interpolated`, that's not obvious to anyone who doesn't
  know compiler internals.
- In `parse_mac_args_common`, we no longer need to collect tokens for
  the value expression.

2 years agoAuto merge of #8575 - FoseFx:trim_split_whitespace2, r=flip1995
bors [Wed, 4 May 2022 13:31:19 +0000 (13:31 +0000)]
Auto merge of #8575 - FoseFx:trim_split_whitespace2, r=flip1995

add `trim_split_whitespace`

Closes #8521

changelog: [`trim_split_whitespace`]

2 years agoAuto merge of #8780 - Alexendoo:init-numbered-field-alias, r=flip1995
bors [Wed, 4 May 2022 13:17:35 +0000 (13:17 +0000)]
Auto merge of #8780 - Alexendoo:init-numbered-field-alias, r=flip1995

Ignore type aliases in `init_numbered_fields`

changelog: Ignore type aliases in [`init_numbered_fields`]

Fixes #8638

2 years agoadd trim_split_whitespace
Max Baumann [Tue, 22 Mar 2022 20:15:09 +0000 (21:15 +0100)]
add trim_split_whitespace

2 years agoAuto merge of #8779 - binggh:easier-needless-late-init, r=llogiq
bors [Tue, 3 May 2022 20:42:35 +0000 (20:42 +0000)]
Auto merge of #8779 - binggh:easier-needless-late-init, r=llogiq

Easier readability for `needless_late_init` message

Closes #8530

Updated the lint to use a `MultiSpan`, showing where the `let` statement was first used and where the initialisation statement was done, as in the format described, for easier readability.

Was wondering why, when pushing the span label for the initialisation statement, that sometimes the prior statement above the initialisation statement gets pulled into the output as well - any insight is appreciated!

---

changelog: [`needless_late_init`]: Now shows the `let` statement where it was first initialized

2 years agoAuto merge of #96558 - bjorn3:librarify_parse_format, r=davidtwco
bors [Tue, 3 May 2022 20:03:54 +0000 (20:03 +0000)]
Auto merge of #96558 - bjorn3:librarify_parse_format, r=davidtwco

Make rustc_parse_format compile on stable

This allows it to be used by lightweight formatting systems and may allow it to be used by rust-analyzer.

2 years agoAuto merge of #8783 - flip1995:ouir-nursery, r=llogiq
bors [Tue, 3 May 2022 18:06:52 +0000 (18:06 +0000)]
Auto merge of #8783 - flip1995:ouir-nursery, r=llogiq

Move only_used_in_recursion to nursery

r? `@llogiq`

I still think this is the right thing to do for this lint. See: #8782

I want to get this merged before the sync on Thursday, because I want to backport this and the last fix #8691 to beta.

changelog: Move [`only_used_in_recursion`] to nursery

2 years agoMove only_used_in_recursion to nursery
flip1995 [Tue, 3 May 2022 15:41:12 +0000 (16:41 +0100)]
Move only_used_in_recursion to nursery

2 years agoIgnore type aliases in `init_numbered_fields`
Alex Macleod [Tue, 3 May 2022 12:39:38 +0000 (13:39 +0100)]
Ignore type aliases in `init_numbered_fields`

2 years agocargo dev bless
binggh [Tue, 3 May 2022 09:51:34 +0000 (17:51 +0800)]
cargo dev bless

2 years agoEasier readability for needless_late_init
binggh [Tue, 3 May 2022 09:51:23 +0000 (17:51 +0800)]
Easier readability for needless_late_init

2 years agoMake rustc_parse_format compile on stable
bjorn3 [Fri, 29 Apr 2022 16:48:58 +0000 (18:48 +0200)]
Make rustc_parse_format compile on stable

This allows it to be used by lightweight formatting systems and may
allow it to be used by rust-analyzer.

2 years agoAuto merge of #8730 - tamaroning:fix8724, r=Alexendoo
bors [Tue, 3 May 2022 07:05:51 +0000 (07:05 +0000)]
Auto merge of #8730 - tamaroning:fix8724, r=Alexendoo

[FP] identity_op in front of if

fix #8724

changelog: FP: [`identity_op`]: is now allowed in front of if statements, blocks and other expressions where the suggestion would be invalid.

Resolved simular problems with blocks, mathces, and loops.
identity_op always does NOT suggest reducing `0 + if b { 1 } else { 2 } + 3` into  `if b { 1 } else { 2 } + 3` even in the case that the expression is in `f(expr)` or `let x = expr;` for now.

2 years agoFix `cast_lossless` to avoid warning on `usize` to `f64` conversion.
Dan Gohman [Mon, 2 May 2022 20:46:29 +0000 (13:46 -0700)]
Fix `cast_lossless` to avoid warning on `usize` to `f64` conversion.

Previously, the `cast_lossless` lint would issue a warning on code that
converted a `usize` value to `f64`, on 32-bit targets.

`usize` to `f64` is a lossless cast on 32-bit targets, however there is
no corresponding `f64::from` that takes a `usize`, so `cast_lossless`'s
suggested replacement does not compile.

This PR disables the lint in the case of casting from `usize` or `isize`.

Fixes #3689.

changelog: [`cast_lossless`] no longer gives wrong suggestion on usize->f64

2 years agorustc: Panic by default in `DefIdTree::parent`
Vadim Petrochenkov [Mon, 25 Apr 2022 19:08:45 +0000 (22:08 +0300)]
rustc: Panic by default in `DefIdTree::parent`

Only crate root def-ids don't have a parent, and in majority of cases the argument of `DefIdTree::parent` cannot be a crate root.
So we now panic by default in `parent` and introduce a new non-panicing function `opt_parent` for cases where the argument can be a crate root.

Same applies to `local_parent`/`opt_local_parent`.

2 years agoimprove identity_op
tamaron [Fri, 22 Apr 2022 01:39:38 +0000 (10:39 +0900)]
improve identity_op

fix

Update identity_op.rs

ok

update without_loop_counters test

chore

fix

chore

remove visitor and leftmost

fix

add document

2 years agoFix the clippy build
Scott McMurray [Mon, 25 Apr 2022 02:08:23 +0000 (19:08 -0700)]
Fix the clippy build

2 years agoAuto merge of #8767 - xFrednet:8765-fix-doc-example, r=camsteffen
bors [Sat, 30 Apr 2022 17:37:00 +0000 (17:37 +0000)]
Auto merge of #8767 - xFrednet:8765-fix-doc-example, r=camsteffen

Add missing quite in `large_include_file` example

Roses are red,
violets are blue,
this fix,
was simple to do

Closes: https://github.com/rust-lang/rust-clippy/issues/8765
changelog: None

2 years agoAuto merge of #8625 - Jarcho:rename_lint, r=xFrednet
bors [Sat, 30 Apr 2022 17:22:34 +0000 (17:22 +0000)]
Auto merge of #8625 - Jarcho:rename_lint, r=xFrednet

Add `cargo dev rename_lint`

fixes #7799

changelog: None

2 years agoAdd missing quite in `large_include_file` example
xFrednet [Sat, 30 Apr 2022 17:16:19 +0000 (19:16 +0200)]
Add missing quite in `large_include_file` example

2 years agoAuto merge of #8720 - asquared31415:ptr-cast-ice-fix, r=Alexendoo,xFrednet
bors [Sat, 30 Apr 2022 16:51:01 +0000 (16:51 +0000)]
Auto merge of #8720 - asquared31415:ptr-cast-ice-fix, r=Alexendoo,xFrednet

fix ICE in `cast_slice_different_sizes`

fixes #8708

changelog: fixes an ICE introduced in #8445

2 years agoAuto merge of #8764 - dtolnay-contrib:checkoutv3, r=llogiq
bors [Sat, 30 Apr 2022 14:54:45 +0000 (14:54 +0000)]
Auto merge of #8764 - dtolnay-contrib:checkoutv3, r=llogiq

Update GitHub Actions actions/checkout@v2 to v3

The v2 implementation uses Node 12, which is end-of-life on April 30, 2022. See https://nodejs.org/en/about/releases/. Update to v3, which is based on Node 16 whose support lasts until April 30, 2024.

---

changelog: none

2 years agoBless tests.
Camille GILLOT [Mon, 14 Mar 2022 14:56:37 +0000 (15:56 +0100)]
Bless tests.

2 years agoStore all generic bounds as where predicates.
Camille GILLOT [Mon, 7 Feb 2022 21:58:30 +0000 (22:58 +0100)]
Store all generic bounds as where predicates.

2 years agoInline WhereClause into Generics.
Camille GILLOT [Sat, 5 Feb 2022 14:48:02 +0000 (15:48 +0100)]
Inline WhereClause into Generics.

2 years agoBox HIR Generics and Impl.
Camille GILLOT [Sat, 5 Feb 2022 14:26:49 +0000 (15:26 +0100)]
Box HIR Generics and Impl.

2 years agoUpdate GitHub Actions actions/checkout@v2 to v3
David Tolnay [Sat, 30 Apr 2022 02:28:03 +0000 (19:28 -0700)]
Update GitHub Actions actions/checkout@v2 to v3

The v2 implementation uses Node 12, which is end-of-life on April 30, 2022.
See https://nodejs.org/en/about/releases/. Update to v3, which is based on
Node 16 whose support lasts until April 30, 2024.

2 years agoSupport negative ints in manual_range_contains
Ariel Uy [Fri, 29 Apr 2022 03:54:58 +0000 (20:54 -0700)]
Support negative ints in manual_range_contains

Fixes issue where ranges containing ints with different signs would be
incorrect due to comparing as unsigned.

2 years agouse non-panicking snippet, use struct update syntax and add comment
asquared31415 [Fri, 29 Apr 2022 01:27:32 +0000 (21:27 -0400)]
use non-panicking snippet, use struct update syntax and add comment

2 years agoerrors: `span_suggestion` takes `impl ToString`
David Wood [Tue, 26 Apr 2022 05:17:33 +0000 (06:17 +0100)]
errors: `span_suggestion` takes `impl ToString`

Change `span_suggestion` (and variants) to take `impl ToString` rather
than `String` for the suggested code, as this simplifies the
requirements on the diagnostic derive.

Signed-off-by: David Wood <david.wood@huawei.com>
2 years agoAuto merge of #8431 - dswij:8416, r=xFrednet
bors [Wed, 27 Apr 2022 09:47:08 +0000 (09:47 +0000)]
Auto merge of #8431 - dswij:8416, r=xFrednet

`redundant_closure` fix FP on coerced closure

Closes https://github.com/rust-lang/rust-clippy/issues/8416,
Closes https://github.com/rust-lang/rust-clippy/issues/7812
Closes https://github.com/rust-lang/rust-clippy/issues/8091

~~Seems like this is fixed in #817 and regressed.~~

Ignore coerced closure false positives, but this will lead to some false negatives on resolvable generics. IMO, this is still an overall improvement

changelog: [`redundant_closure`] ignores coerced closure

2 years agoAuto merge of #8743 - Alexendoo:useless-attribute-redundant-pub-crate, r=llogiq
bors [Wed, 27 Apr 2022 05:43:13 +0000 (05:43 +0000)]
Auto merge of #8743 - Alexendoo:useless-attribute-redundant-pub-crate, r=llogiq

ignore `redundant_pub_crate` in `useless_attribute`

changelog: [`useless_attribute`] no longer lints [`redundant_pub_crate`]

As mentioned in https://github.com/rust-lang/rust-clippy/issues/8732#issuecomment-1106489634

> And it turns out I can't even explicitly allow it at the usage site, because then `clippy::useless_attribute` fires (which would also be a FP?), which is deny-by-default.
>
> Though it does work if I then allow `clippy::useless_attribute`. ðŸ˜‚
>
> ```rust
> #[allow(clippy::useless_attribute)]
> #[allow(clippy::redundant_pub_crate)]
> pub(crate) use bit;
> ```
>
> The originally-reported warning now no longer occurs.

2 years ago`redundant_closure` ignore coerced closure
dswij [Wed, 23 Feb 2022 15:04:06 +0000 (23:04 +0800)]
`redundant_closure` ignore coerced closure

2 years agoAuto merge of #8617 - Alexendoo:relax-needless-late-init, r=giraffate
bors [Wed, 27 Apr 2022 00:11:17 +0000 (00:11 +0000)]
Auto merge of #8617 - Alexendoo:relax-needless-late-init, r=giraffate

`needless_late_init`: ignore `if let`, `let mut` and significant drops

No longer lints `if let`, personal taste on this one is pretty split, so it probably shouldn't be warning by default. Fixes #8613

```rust
let x = if let Some(n) = y {
    n
} else {
    1
}
```

No longer lints `let mut`, things like the following are not uncommon and look fine as they are

https://github.com/shepmaster/twox-hash/blob/b169c16d86eb8ea4a296b0acb9d00ca7e3c3005f/src/sixty_four.rs#L88-L93

Avoids changing the drop order in an observable way, where the type of `x` has a drop with side effects and something between `x` and the first use also does, e.g.

https://github.com/denoland/rusty_v8/blob/48cc6cb791cac57d22fab1a2feaa92da8ddc9a68/tests/test_api.rs#L159-L167

The implementation of `type_needs_ordered_drop_inner` was changed a bit, it now uses `Ty::has_significant_drop` and reordered the ifs to check diagnostic name before checking the implicit drop impl

changelog: [`needless_late_init`]: No longer lints `if let` statements, `let mut` bindings and no longer significantly changes drop order

2 years ago`needless_late_init`: ignore `if let`, `let mut` and significant drops
Alex Macleod [Fri, 1 Apr 2022 17:23:47 +0000 (18:23 +0100)]
`needless_late_init`: ignore `if let`, `let mut` and significant drops

2 years agoAuto merge of #8737 - smoelius:extra-impl-lifetimes, r=giraffate
bors [Tue, 26 Apr 2022 00:06:53 +0000 (00:06 +0000)]
Auto merge of #8737 - smoelius:extra-impl-lifetimes, r=giraffate

Extend `extra_unused_lifetimes` to handle impl lifetimes

Fixes #6437 (cc: `@carols10cents)`

changelog: fix #6437

2 years agoAuto merge of #8727 - Serial-ATA:lint-large-includes, r=xFrednet
bors [Mon, 25 Apr 2022 17:29:27 +0000 (17:29 +0000)]
Auto merge of #8727 - Serial-ATA:lint-large-includes, r=xFrednet

Add `large_include_file` lint

changelog: Add [`large_include_file`] lint
closes #7005

2 years agoFix naming
Samuel E. Moelius III [Mon, 25 Apr 2022 13:23:59 +0000 (09:23 -0400)]
Fix naming

2 years agoFix false positives
Samuel E. Moelius III [Mon, 25 Apr 2022 09:20:08 +0000 (05:20 -0400)]
Fix false positives

2 years agoremove extra lifetime
asquared31415 [Sun, 24 Apr 2022 23:41:43 +0000 (19:41 -0400)]
remove extra lifetime

2 years agoAuto merge of #8742 - goth-turtle:mistyped-literal-suffix, r=llogiq
bors [Sun, 24 Apr 2022 20:16:40 +0000 (20:16 +0000)]
Auto merge of #8742 - goth-turtle:mistyped-literal-suffix, r=llogiq

mistyped_literal_suffix: improve integer suggestions, avoid wrong float suggestions

This PR fixes 2 things:
- The known problem that integer types are always suggested as signed, by suggesting an unsigned suffix for literals that wouldnt fit in the signed type, and ignores any literals too big for the corresponding unsigned type too.
- The lint would only look at the integer part of any floating point literals without an exponent, this causing #6129. This just ignores those literals.

Examples:
```rust
let _ = 2_32; // still 2_i32
let _ = 234_8; // would now suggest 234_u8

// these are now ignored
let _ = 500_8;
let _ = 123_32.123;
```

changelog: suggest correct integer types in [`mistyped_literal_suffix`], ignore float literals without an exponent
fixes #6129

2 years agoAdd `large_include_file` lint
Serial [Thu, 21 Apr 2022 15:01:18 +0000 (11:01 -0400)]
Add `large_include_file` lint

2 years agomistyped_literal_suffixes: ignore floats without exponent
goth-turtle [Sun, 24 Apr 2022 13:06:48 +0000 (15:06 +0200)]
mistyped_literal_suffixes: ignore floats without exponent

Previously this lint would only look at the integer part of floating
point literals without an exponent, giving wrong suggestions like:

```
  |
8 |     let _ = 123_32.123;
  |             ^^^^^^^^^^ help: did you mean to write: `123.123_f32`
  |
```

Instead, it now ignores these literals.
Fixes #6129

2 years agomistyped_literal_suffixes: improve suggestions for integer types
goth-turtle [Sat, 23 Apr 2022 20:20:50 +0000 (22:20 +0200)]
mistyped_literal_suffixes: improve suggestions for integer types

Instead of just always suggesting signed suffixes regardless of size
of the value, it now suggests an unsigned suffix when the value wouldn't
fit into the corresponding signed type, and ignores the literal entirely
if it is too big for the unsigned type as well.

2 years agoAdd `rename_lint` command
Jason Newcomb [Mon, 4 Apr 2022 00:28:47 +0000 (20:28 -0400)]
Add `rename_lint` command

2 years agoAuto merge of #8738 - tamaroning:fix_wrong_self_convention, r=xFrednet
bors [Sun, 24 Apr 2022 12:40:15 +0000 (12:40 +0000)]
Auto merge of #8738 - tamaroning:fix_wrong_self_convention, r=xFrednet

wrong_self_convention allows `is_*` to take `&mut self`

fix #8480 and #8513
Allowing `is_*` to take `&self` or none is too restrictive.

changelog: FPs: [`wrong_self_convention`] now allows `&mut self` and no self as arguments for `is_*` methods

2 years agoAuto merge of #8736 - Serial-ATA:issue-8732, r=xFrednet
bors [Sun, 24 Apr 2022 12:06:08 +0000 (12:06 +0000)]
Auto merge of #8736 - Serial-ATA:issue-8732, r=xFrednet

Add macro export exemption to `redundant_pub_crate`

changelog: Add macro export exemption to `redundant_pub_crate`
closes #8732

2 years agoMake clippy inspector more precise.
Camille GILLOT [Mon, 14 Feb 2022 12:20:47 +0000 (13:20 +0100)]
Make clippy inspector more precise.

2 years agofix ICE by using a type to return the info we want and also fix some bugs in displayi...
asquared31415 [Sat, 23 Apr 2022 16:49:40 +0000 (12:49 -0400)]
fix ICE by using a type to return the info we want and also fix some bugs in displaying an extra mut when a TypeAndMut was wrong

2 years agofix
tamaron [Sat, 23 Apr 2022 13:45:26 +0000 (22:45 +0900)]
fix

2 years agoignore `redundant_pub_crate` in `useless_attribute`
Alex Macleod [Sat, 23 Apr 2022 11:23:18 +0000 (12:23 +0100)]
ignore `redundant_pub_crate` in `useless_attribute`

2 years agoDrop vis in Item.
Camille GILLOT [Sun, 13 Feb 2022 10:30:48 +0000 (11:30 +0100)]
Drop vis in Item.

2 years agoDrop vis in ImplItem.
Camille GILLOT [Sun, 13 Feb 2022 09:54:07 +0000 (10:54 +0100)]
Drop vis in ImplItem.

2 years agoDrop vis in FieldDef.
Camille GILLOT [Sun, 13 Feb 2022 00:54:13 +0000 (01:54 +0100)]
Drop vis in FieldDef.

2 years agoStop visiting visibility.
Camille GILLOT [Sun, 13 Feb 2022 14:40:08 +0000 (15:40 +0100)]
Stop visiting visibility.

2 years agoExtend `extra_unused_lifetimes` to handle impl lifetimes
Samuel E. Moelius III [Sat, 23 Apr 2022 00:05:18 +0000 (20:05 -0400)]
Extend `extra_unused_lifetimes` to handle impl lifetimes

2 years agoAdd macro export exemption to `redundant_pub_crate`
Serial [Fri, 22 Apr 2022 22:03:23 +0000 (18:03 -0400)]
Add macro export exemption to `redundant_pub_crate`

2 years agoAuto merge of #8731 - Alexendoo:dogfood-allow-unknown-lints, r=xFrednet
bors [Fri, 22 Apr 2022 17:11:53 +0000 (17:11 +0000)]
Auto merge of #8731 - Alexendoo:dogfood-allow-unknown-lints, r=xFrednet

dogfood: allow unknown lints when not running with `internal` feature

changelog: none

https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/unknown.20lint.20in.20test.20dogfood_clippy

It's only a warning so this wasn't causing the test to fail, but if you had another error somewhere or used `--nocapture` the extra warnings would be shown

2 years agodogfood: allow unknown lints when not running with `internal` feature
Alex Macleod [Fri, 22 Apr 2022 12:05:53 +0000 (13:05 +0100)]
dogfood: allow unknown lints when not running with `internal` feature

2 years agoAuto merge of #8717 - Alexendoo:manual-split-once-manual-iter, r=dswij,xFrednet
bors [Fri, 22 Apr 2022 09:57:00 +0000 (09:57 +0000)]
Auto merge of #8717 - Alexendoo:manual-split-once-manual-iter, r=dswij,xFrednet

`manual_split_once`: lint manual iteration of `SplitN`

changelog: `manual_split_once`: lint manual iteration of `SplitN`

Now lints:

```rust
let mut iter = "a.b.c".splitn(2, '.');
let first = iter.next().unwrap();
let second = iter.next().unwrap();

let mut iter = "a.b.c".splitn(2, '.');
let first = iter.next()?;
let second = iter.next()?;

let mut iter = "a.b.c".rsplitn(2, '.');
let first = iter.next().unwrap();
let second = iter.next().unwrap();

let mut iter = "a.b.c".rsplitn(2, '.');
let first = iter.next()?;
let second = iter.next()?;
```

It suggests (minus leftover whitespace):

```rust
let (first, second) = "a.b.c".split_once('.').unwrap();

let (first, second) = "a.b.c".split_once('.')?;

let (second, first) = "a.b.c".rsplit_once('.').unwrap();

let (second, first) = "a.b.c".rsplit_once('.')?;
```

Currently only lints if the statements are next to each other, as detecting the various kinds of shadowing was tricky, so the following won't lint

```rust
let mut iter = "a.b.c".splitn(2, '.');
let something_else = 1;
let first = iter.next()?;
let second = iter.next()?;
```

2 years agoAuto merge of #8729 - Serial-ATA:issue-7318, r=Manishearth
bors [Thu, 21 Apr 2022 18:05:14 +0000 (18:05 +0000)]
Auto merge of #8729 - Serial-ATA:issue-7318, r=Manishearth

Fix missing whitespace in `collapsible_else_if` suggestion

changelog: Fix missing whitespace in [`collapsible_else_if`] suggestion
closes #7318

2 years agoFix missing whitespace in `collapsible_else_if` suggestion
Serial [Thu, 21 Apr 2022 17:42:55 +0000 (13:42 -0400)]
Fix missing whitespace in `collapsible_else_if` suggestion

2 years ago`manual_split_once`: lint manual iteration of `SplitN`
Alex Macleod [Mon, 18 Apr 2022 12:28:23 +0000 (13:28 +0100)]
`manual_split_once`: lint manual iteration of `SplitN`

2 years agoAuto merge of #8571 - PyroTechniac:empty-drop, r=flip1995
bors [Thu, 21 Apr 2022 08:03:31 +0000 (08:03 +0000)]
Auto merge of #8571 - PyroTechniac:empty-drop, r=flip1995

add `empty_drop`

Closes #8352

changelog: New lint [`empty_drop`]

2 years agoAdd empty_drop lint
Gryffon Bellish [Fri, 25 Mar 2022 19:31:52 +0000 (15:31 -0400)]
Add empty_drop lint

2 years agoAuto merge of #8716 - binggh:stable-sort-message-update, r=giraffate
bors [Thu, 21 Apr 2022 00:27:13 +0000 (00:27 +0000)]
Auto merge of #8716 - binggh:stable-sort-message-update, r=giraffate

Less authoritative stable_sort_primitive message

fixes #8241

Hey all - first contribution here so I'm deciding to start with something small.

Updated the linked message to be less authoritative as well as moved the lint grouping from `perf` to `pedantic` as suggested by `@camsteffen` under the issue.

changelog: [`stable_sort_primitive`]: emit less authoritative message and move to `pedantic`