]> git.lizzy.rs Git - rust.git/log
rust.git
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 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 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`

2 years agoAuto merge of #8700 - youknowone:needless_match-false-positive, r=xFrednet
bors [Wed, 20 Apr 2022 17:16:39 +0000 (17:16 +0000)]
Auto merge of #8700 - youknowone:needless_match-false-positive, r=xFrednet

Fix needless_match false positive for if-let when the else block doesn't match to given expr

<!--

Thank you for making Clippy better!

We're collecting our changelog from pull request descriptions.
If your PR only includes internal changes, you can just write
`changelog: none`. Otherwise, please write a short comment
explaining your change. Also, it's helpful for us that
the lint name is put into brackets `[]` and backticks `` ` ` ``,
e.g. ``[`lint_name`]``.

If your PR fixes an issue, you can add "fixes #issue_number" into this
PR description. This way the issue will be automatically closed when
your PR is merged.

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]
- \[ ] Added passing UI tests (including committed `.stderr` file)
- \[x] `cargo test` passes locally
- \[x] Executed `cargo dev update_lints`
- \[ ] Added lint documentation
- \[x] Run `cargo dev fmt`

[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

Delete this line and everything above before opening your PR.

--->

fix #8695

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: Fixed ``[`needless_match`]`` false positive when else block expression differs.

2 years agoBetter documentation wording and add known problems section
bing [Wed, 20 Apr 2022 15:11:54 +0000 (23:11 +0800)]
Better documentation wording and add known problems section

2 years agoAuto merge of #8711 - kyoto7250:new-lint-bytes-count-to-len, r=giraffate
bors [Tue, 19 Apr 2022 12:44:07 +0000 (12:44 +0000)]
Auto merge of #8711 - kyoto7250:new-lint-bytes-count-to-len, r=giraffate

Take over: New lint bytes count to len

take over #8375
close #8083

This PR adds new lint about  considering replacing `.bytes().count()` with `.len()`.

Thank you in advance.

---

r! `@Manishearth`

changelog: adds new lint [`bytes_count_to_len`] to consider replacing `.bytes().count()` with `.len()`

2 years agoRollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov
Dylan DPC [Tue, 19 Apr 2022 12:43:21 +0000 (14:43 +0200)]
Rollup merge of #96142 - cjgillot:no-crate-def-index, r=petrochenkov

Stop using CRATE_DEF_INDEX outside of metadata encoding.

`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.  We should not manipulate raw `DefIndex` outside of metadata encoding.

2 years agofix ICE
asquared31415 [Tue, 19 Apr 2022 02:19:34 +0000 (22:19 -0400)]
fix ICE

2 years agoadd checking type
kyoto7250 [Sat, 16 Apr 2022 08:53:22 +0000 (17:53 +0900)]
add checking type

adding test patterns

cargo dev bless

fix comment

add ;

delete :

fix suggestion code

and update stderr in tests.

use match_def_path when checking method name

2 years agoadds lint logic and test for bytes_count_to_len
Chase Ruskin [Mon, 31 Jan 2022 00:16:10 +0000 (19:16 -0500)]
adds lint logic and test for bytes_count_to_len

formats code with

fixes single match clippy error to replace with if let

swaps ident.name.as_str to ident.name == sym for count fn

2 years agoAuto merge of #8707 - OneSignal:await-invalid-types, r=llogiq
bors [Mon, 18 Apr 2022 18:36:50 +0000 (18:36 +0000)]
Auto merge of #8707 - OneSignal:await-invalid-types, r=llogiq

Add `await_holding_invalid_type` lint

changelog: [`await_holding_invalid_type`]

This lint allows users to create a denylist of types which are not allowed to be
held across await points. This is essentially a re-implementation of the
language-level [`must_not_suspend`
lint](https://github.com/rust-lang/rust/issues/83310). That lint has a lot of
work still to be done before it will reach Rust stable, and in the meantime
there are a lot of types which can trip up developers if they are used
improperly.

I originally implemented this specifically for `tracing::span::Entered`, until I discovered #8434 and read the commentary on that PR. Given this implementation is fully user configurable, doesn't tie clippy to any one particular crate, and introduces no additional dependencies, it seems more appropriate.

2 years agofixup! Add `await_holding_invalid_type` lint
Lily Mara [Mon, 18 Apr 2022 18:32:28 +0000 (11:32 -0700)]
fixup! Add `await_holding_invalid_type` lint

2 years agofixup! Add `await_holding_invalid_type` lint
Lily Mara [Mon, 18 Apr 2022 18:30:59 +0000 (11:30 -0700)]
fixup! Add `await_holding_invalid_type` lint

2 years agofixup! Add `await_holding_invalid_type` lint
Lily Mara [Mon, 18 Apr 2022 18:16:35 +0000 (11:16 -0700)]
fixup! Add `await_holding_invalid_type` lint

2 years agofixup! Add `await_holding_invalid_type` lint
Lily Mara [Mon, 18 Apr 2022 17:34:17 +0000 (10:34 -0700)]
fixup! Add `await_holding_invalid_type` lint

2 years agoUpdate clippy_lints/src/await_holding_invalid.rs
Lily Mara [Mon, 18 Apr 2022 17:32:11 +0000 (10:32 -0700)]
Update clippy_lints/src/await_holding_invalid.rs

Co-authored-by: llogiq <bogusandre@gmail.com>
2 years agoUpdate clippy_lints/src/await_holding_invalid.rs
Lily Mara [Mon, 18 Apr 2022 17:32:03 +0000 (10:32 -0700)]
Update clippy_lints/src/await_holding_invalid.rs

Co-authored-by: llogiq <bogusandre@gmail.com>
2 years agoUpdate clippy_lints/src/await_holding_invalid.rs
Lily Mara [Mon, 18 Apr 2022 17:31:57 +0000 (10:31 -0700)]
Update clippy_lints/src/await_holding_invalid.rs

Co-authored-by: llogiq <bogusandre@gmail.com>
2 years agoAuto merge of #8701 - xFrednet:0000-clippy-print-hir-attr, r=flip1995
bors [Mon, 18 Apr 2022 13:06:03 +0000 (13:06 +0000)]
Auto merge of #8701 - xFrednet:0000-clippy-print-hir-attr, r=flip1995

Rework `#[clippy::dump]` attribute for debugging

Hey `@rust-lang/clippy,` this adds a new `#[clippy::print_hir]` attribute that prints the node to the console using `{:#?}`. Personally, I use print debugging quite a lot while working on Clippy, and this is a simple shortcut that also works in the playground (Once this has been synced). The question is now, if we want to have this attribute. Are there any concerns? I think it's similar to our `#[clippy::author]` attribute.

I haven't added a test, as the `.stdout` file would require updates with every HIR change inside rustc. Here are some examples, for the current implementation

<details>
<summary>`do_something(&map);`</summary>

```rs
Expr {
    hir_id: HirId {
        owner: DefId(0:7 ~ aaa[995b]::main),
        local_id: 21,
    },
    kind: Call(
        Expr {
            hir_id: HirId {
                owner: DefId(0:7 ~ aaa[995b]::main),
                local_id: 17,
            },
            kind: Path(
                Resolved(
                    None,
                    Path {
                        span: tests/ui/aaa.rs:23:5: 23:17 (#0),
                        res: Def(
                            Fn,
                            DefId(0:6 ~ aaa[995b]::do_something),
                        ),
                        segments: [
                            PathSegment {
                                ident: do_something#0,
                                hir_id: Some(
                                    HirId {
                                        owner: DefId(0:7 ~ aaa[995b]::main),
                                        local_id: 16,
                                    },
                                ),
                                res: Some(
                                    Err,
                                ),
                                args: None,
                                infer_args: true,
                            },
                        ],
                    },
                ),
            ),
            span: tests/ui/aaa.rs:23:5: 23:17 (#0),
        },
        [
            Expr {
                hir_id: HirId {
                    owner: DefId(0:7 ~ aaa[995b]::main),
                    local_id: 20,
                },
                kind: AddrOf(
                    Ref,
                    Not,
                    Expr {
                        hir_id: HirId {
                            owner: DefId(0:7 ~ aaa[995b]::main),
                            local_id: 19,
                        },
                        kind: Path(
                            Resolved(
                                None,
                                Path {
                                    span: tests/ui/aaa.rs:23:19: 23:22 (#0),
                                    res: Local(
                                        HirId {
                                            owner: DefId(0:7 ~ aaa[995b]::main),
                                            local_id: 15,
                                        },
                                    ),
                                    segments: [
                                        PathSegment {
                                            ident: map#0,
                                            hir_id: Some(
                                                HirId {
                                                    owner: DefId(0:7 ~ aaa[995b]::main),
                                                    local_id: 18,
                                                },
                                            ),
                                            res: Some(
                                                Local(
                                                    HirId {
                                                        owner: DefId(0:7 ~ aaa[995b]::main),
                                                        local_id: 15,
                                                    },
                                                ),
                                            ),
                                            args: None,
                                            infer_args: true,
                                        },
                                    ],
                                },
                            ),
                        ),
                        span: tests/ui/aaa.rs:23:19: 23:22 (#0),
                    },
                ),
                span: tests/ui/aaa.rs:23:18: 23:22 (#0),
            },
        ],
    ),
    span: tests/ui/aaa.rs:23:5: 23:23 (#0),
}
```
</details>

<details>
<summary>`use std::collections::HashMap;`</summary>

```rs
Item {
    ident: HashMap#0,
    def_id: DefId(0:5 ~ aaa[995b]::{misc#1}),
    kind: Use(
        Path {
            span: tests/ui/aaa.rs:8:5: 8:30 (#0),
            res: Def(
                Struct,
                DefId(1:1294 ~ std[928b]::collections::hash::map::HashMap),
            ),
            segments: [
                PathSegment {
                    ident: std#0,
                    hir_id: Some(
                        HirId {
                            owner: DefId(0:5 ~ aaa[995b]::{misc#1}),
                            local_id: 1,
                        },
                    ),
                    res: Some(
                        Def(
                            Mod,
                            DefId(1:0 ~ std[928b]),
                        ),
                    ),
                    args: None,
                    infer_args: false,
                },
                PathSegment {
                    ident: collections#0,
                    hir_id: Some(
                        HirId {
                            owner: DefId(0:5 ~ aaa[995b]::{misc#1}),
                            local_id: 2,
                        },
                    ),
                    res: Some(
                        Def(
                            Mod,
                            DefId(1:1193 ~ std[928b]::collections),
                        ),
                    ),
                    args: None,
                    infer_args: false,
                },
                PathSegment {
                    ident: HashMap#0,
                    hir_id: Some(
                        HirId {
                            owner: DefId(0:5 ~ aaa[995b]::{misc#1}),
                            local_id: 3,
                        },
                    ),
                    res: Some(
                        Err,
                    ),
                    args: None,
                    infer_args: false,
                },
            ],
        },
        Single,
    ),
    vis: Spanned {
        node: Inherited,
        span: tests/ui/aaa.rs:8:1: 8:1 (#0),
    },
    span: tests/ui/aaa.rs:8:1: 8:31 (#0),
}
```

</details>

<details>
<summary>`"100"`</summary>

```rs
Expr {
    hir_id: HirId {
        owner: DefId(0:7 ~ aaa[995b]::main),
        local_id: 27,
    },
    kind: Lit(
        Spanned {
            node: Str(
                "100",
                Cooked,
            ),
            span: tests/ui/aaa.rs:28:9: 28:14 (#0),
        },
    ),
    span: tests/ui/aaa.rs:28:9: 28:14 (#0),
}
```
</details>

---

changelog: Added `[clippy::print_hir]` to inspect rustc's internal representation

2 years agoUpdate lints
bing [Mon, 18 Apr 2022 06:48:34 +0000 (14:48 +0800)]
Update lints

2 years agoLess authoritative stable_sort_primitive message
bing [Mon, 18 Apr 2022 06:42:24 +0000 (14:42 +0800)]
Less authoritative stable_sort_primitive message

2 years agoFix needless_match false positive for if-let
Jeong YunWon [Fri, 15 Apr 2022 10:33:24 +0000 (19:33 +0900)]
Fix needless_match false positive for if-let

when the else block doesn't match to given expr

2 years agoAdd `#[clippy::print_hir]` attribute for debugging
xFrednet [Fri, 15 Apr 2022 09:37:58 +0000 (11:37 +0200)]
Add `#[clippy::print_hir]` attribute for debugging

2 years agoAuto merge of #8665 - InfRandomness:option_take_on_temporary, r=llogiq
bors [Sun, 17 Apr 2022 18:34:16 +0000 (18:34 +0000)]
Auto merge of #8665 - InfRandomness:option_take_on_temporary, r=llogiq

Introduce needless_option_take lint

- \[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`

Fixes #8618

changelog: Introduce [`needless_option_take`] lint

2 years agoAuto merge of #95779 - cjgillot:ast-lifetimes-undeclared, r=petrochenkov
bors [Sun, 17 Apr 2022 12:56:19 +0000 (12:56 +0000)]
Auto merge of #95779 - cjgillot:ast-lifetimes-undeclared, r=petrochenkov

Report undeclared lifetimes during late resolution.

First step in https://github.com/rust-lang/rust/pull/91557

We reuse the rib design of the current resolution framework. Specific `LifetimeRib` and `LifetimeRibKind` types are introduced. The most important variant is `LifetimeRibKind::Generics`, which happens each time we encounter something which may introduce generic lifetime parameters. It can be an item or a `for<...>` binder. The `LifetimeBinderKind` specifies how this rib behaves with respect to in-band lifetimes.

r? `@petrochenkov`

2 years agoStop using CRATE_DEF_INDEX.
Camille GILLOT [Fri, 15 Apr 2022 17:27:53 +0000 (19:27 +0200)]
Stop using CRATE_DEF_INDEX.

`CRATE_DEF_ID` and `CrateNum::as_def_id` are almost always what we want.

2 years agoBless clippy.
Camille GILLOT [Fri, 1 Apr 2022 17:18:10 +0000 (19:18 +0200)]
Bless clippy.

2 years agoAuto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot
bors [Sun, 17 Apr 2022 08:06:53 +0000 (08:06 +0000)]
Auto merge of #95655 - kckeiks:create-hir-crate-items-query, r=cjgillot

Refactor HIR item-like traversal (part 1)

Issue  #95004

- Create hir_crate_items query which traverses tcx.hir_crate(()).owners to return a hir::ModuleItems
- use tcx.hir_crate_items in tcx.hir().items() to return an iterator of hir::ItemId
- use tcx.hir_crate_items to introduce a tcx.hir().par_items(impl Fn(hir::ItemId)) to traverse all items in parallel;

Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
cc `@cjgillot`

2 years agoAuto merge of #8709 - matthiaskrgr:lintcheckfix, r=llogiq
bors [Sat, 16 Apr 2022 10:22:08 +0000 (10:22 +0000)]
Auto merge of #8709 - matthiaskrgr:lintcheckfix, r=llogiq

lintcheck: fix --fix

looks like --allow-no-vcs does no longer exist(?)

changelog: none

2 years agoAuto merge of #8706 - lupd:cast-abs-to-unsigned, r=xFrednet
bors [Sat, 16 Apr 2022 09:12:15 +0000 (09:12 +0000)]
Auto merge of #8706 - lupd:cast-abs-to-unsigned, r=xFrednet

Fix formatting of `cast_abs_to_unsigned` docs

The "use instead" section of the example was not being formatted as Rust code, and the "configuration" documentation was being formatted as Rust code.

changelog: `[cast_abs_to_unsigned]` Fix example/configuration formatting

2 years agoAuto merge of #8698 - xFrednet:0000-changelog-1-61, r=flip1995
bors [Sat, 16 Apr 2022 08:26:27 +0000 (08:26 +0000)]
Auto merge of #8698 - xFrednet:0000-changelog-1-61, r=flip1995

Changelog for Rust 1.61 :octopus:

roses are red,
violets are blue,
this changelog,
is no longer a todo!

---

changelog: none

2 years agoChangelog for Rust 1.61 :octopus:
xFrednet [Wed, 13 Apr 2022 21:14:35 +0000 (23:14 +0200)]
Changelog for Rust 1.61 :octopus:

2 years agoAuto merge of #94468 - Amanieu:global_asm_sym, r=nagisa
bors [Sat, 16 Apr 2022 04:46:01 +0000 (04:46 +0000)]
Auto merge of #94468 - Amanieu:global_asm_sym, r=nagisa

Implement sym operands for global_asm!

Tracking issue: #93333

This PR is pretty much a complete rewrite of `sym` operand support for inline assembly so that the same implementation can be shared by `asm!` and `global_asm!`. The main changes are:
- At the AST level, `sym` is represented as a special `InlineAsmSym` AST node containing a path instead of an `Expr`.
- At the HIR level, `sym` is split into `SymStatic` and `SymFn` depending on whether the path resolves to a static during AST lowering (defaults to `SynFn` if `get_early_res` fails).
  - `SymFn` is just an `AnonConst`. It runs through typeck and we just collect the resulting type at the end. An error is emitted if the type is not a `FnDef`.
  - `SymStatic` directly holds a path and the `DefId` of the `static` that it is pointing to.
- The representation at the MIR level is mostly unchanged. There is a minor change to THIR where `SymFn` is a constant instead of an expression.
- At the codegen level we need to apply the target's symbol mangling to the result of `tcx.symbol_name()` depending on the target. This is done by calling the LLVM name mangler, which handles all of the details.
  - On Mach-O, all symbols have a leading underscore.
  - On x86 Windows, different mangling is used for cdecl, stdcall, fastcall and vectorcall.
  - No mangling is needed on other platforms.

r? `@nagisa`
cc `@eddyb`

2 years agolintcheck: fix --fix
Matthias Krüger [Fri, 15 Apr 2022 22:56:28 +0000 (00:56 +0200)]
lintcheck: fix --fix

looks like --allow-no-vcs does no longer exist(?)

2 years agofixup! Add `await_holding_invalid_type` lint
Lily Mara [Fri, 15 Apr 2022 21:54:19 +0000 (14:54 -0700)]
fixup! Add `await_holding_invalid_type` lint