Commit graph

13350 commits

Author SHA1 Message Date
bors
92048f4826 Auto merge of #8221 - Jarcho:while_let_on_iterator_8113, r=llogiq
Better detect when a field can be moved from in `while_let_on_iterator`

fixes #8113

changelog: Better detect when a field can be moved from in `while_let_on_iterator`
2022-01-05 06:45:58 +00:00
bors
20f2a89026 Auto merge of #8224 - Jarcho:type_repetition_in_bounds_8162, r=llogiq
Fix `type_repetition_in_bounds`

fixes #7360
fixes #8162
fixes #8056

changelog: Check for full equality in `type_repetition_in_bounds` rather than just equal hashes
2022-01-05 01:05:18 +00:00
bors
d5dcda2f42 Auto merge of #8223 - camsteffen:remove-in-macro, r=llogiq
Remove in_macro from clippy_utils

changelog: none

Previously done in #7897 but reverted in #8170. I'd like to keep `in_macro` out of utils because if a span is from expansion in any way (desugaring or macro), we should not proceed without understanding the nature of the expansion IMO.

r? `@llogiq`
2022-01-05 00:49:23 +00:00
bors
ba03dc70fd Auto merge of #8219 - camsteffen:macro-decoupling, r=llogiq
New macro utils

changelog: none

Sorry, this is a big one. A lot of interrelated changes and I wanted to put the new utils to use to make sure they are somewhat battle-tested. We may want to divide some of the lint-specific refactoring commits into batches for smaller reviewing tasks. I could also split into more PRs.

Introduces a bunch of new utils at `clippy_utils::macros::...`. Please read through the docs and give any feedback! I'm happy to introduce `MacroCall` and various functions to retrieve an instance. It feels like the missing puzzle piece. I'm also introducing `ExpnId` from rustc as "useful for Clippy too". `@rust-lang/clippy`

Fixes #7843 by not parsing every node of macro implementations, at least the major offenders.

I probably want to get rid of `is_expn_of` at some point.
2022-01-04 22:32:02 +00:00
bors
786f874c34 New macro utils
changelog: none

Sorry, this is a big one. A lot of interrelated changes and I wanted to put the new utils to use to make sure they are somewhat battle-tested. We may want to divide some of the lint-specific refactoring commits into batches for smaller reviewing tasks. I could also split into more PRs.

Introduces a bunch of new utils at `clippy_utils::macros::...`. Please read through the docs and give any feedback! I'm happy to introduce `MacroCall` and various functions to retrieve an instance. It feels like the missing puzzle piece. I'm also introducing `ExpnId` from rustc as "useful for Clippy too". `@rust-lang/clippy`

Fixes #7843 by not parsing every node of macro implementations, at least the major offenders.

I probably want to get rid of `is_expn_of` at some point.
2022-01-04 22:32:02 +00:00
Matthias Krüger
d7a60337fc Rollup merge of #91907 - lcnr:const-arg-infer, r=BoxyUwU
Allow `_` as the length of array types and repeat expressions

r? `@BoxyUwU` cc `@varkor`
2022-01-04 21:23:06 +01:00
Jason Newcomb
2dd216a186 Check for full equality in type_repetition_in_bounds rather than just equal hashes 2022-01-04 14:28:27 -05:00
bors
0e28e38e36 Auto merge of #8220 - Jarcho:manual_swap_8154, r=camsteffen
Consider auto-deref when linting `manual_swap`

fixes #8154

changelog: Don't lint `manual_swap` when a field access involves auto-deref
2022-01-04 18:23:39 +00:00
Jason Newcomb
a7097b80c3 Consider auto-deref when linting manual_swap 2022-01-04 13:22:30 -05:00
Cameron Steffen
00da1b8f14 Remove in_macro from utils 2022-01-04 12:07:42 -06:00
Jason Newcomb
ff58efb2b2 Better detect when a field can be moved from in while_let_on_iterator 2022-01-03 23:13:31 -05:00
bors
3ea77847fe Auto merge of #8216 - pmnoxx:piotr-fix-clippy-warnings, r=xFrednet
Fix `clippy::use-self`` warning in ` src/main.rs`

`ClippyCmd` warnings gets generated due to addition of `clippy::use-self`. This PR fixes that.

```
warning: unnecessary structure name repetition
  --> src/main.rs:99:9
   |
99 |         ClippyCmd {
   |         ^^^^^^^^^ help: use the applicable keyword: `Self`
   |
   = note: `-W clippy::use-self` implied by `-W clippy::nursery`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#use_self
```

---

changelog: none
2022-01-03 16:54:39 +00:00
Piotr Mikulski
19cfcd5c5a Fix clippy warnings 2022-01-03 06:11:11 -08:00
Matthias Krüger
69750711d3 Rollup merge of #90102 - nbdd0121:box3, r=jonas-schievink
Remove `NullOp::Box`

Follow up of #89030 and MCP rust-lang/compiler-team#460.

~1 month later nothing seems to be broken, apart from a small regression that #89332 (1aac85bb716c09304b313d69d30d74fe7e8e1a8e) shows could be regained by remvoing the diverging path, so it shall be safe to continue and remove `NullOp::Box` completely.

r? `@jonas-schievink`
`@rustbot` label T-compiler
2022-01-03 14:44:15 +01:00
bors
8419108e96 Auto merge of #8204 - wigy-opensource-developer:fix-7210, r=xFrednet
[`erasing_op`] lint ignored when operation `Output` type is different from the type of constant `0`

fixes #7210

changelog: [`erasing_op`] lint ignored when operation `Output` type is different from the type of constant `0`
2022-01-02 18:50:44 +00:00
Wigy
e8b6b2ac0c
erasing_op lint ignored when output type is different from the non-const one 2022-01-02 19:36:02 +01:00
bors
b25dbc6a4d Auto merge of #8208 - nmathewson:selfkind_no_fix, r=xFrednet
wrong_self_convention: Match `SelfKind::No` more restrictively

The `wrong_self_convention` lint uses a `SelfKind` type to decide
whether a method has the right kind of "self" for its name, or whether
the kind of "self" it has makes its name confusable for a method in
a common trait.  One possibility is `SelfKind::No`, which is supposed
to mean "No `self`".

Previously, SelfKind::No matched everything _except_ Self, including
references to Self.  This patch changes it to match Self, &Self, &mut
Self, Box<Self>, and so on.

For example, this kind of method was allowed before:

```
impl S {
    // Should trigger the lint, because
    // "methods called `is_*` usually take `self` by reference or no `self`"
    fn is_foo(&mut self) -> bool { todo!() }
}
```

But since SelfKind::No matched "&mut self", no lint was triggered
(see #8142).

With this patch, the code above now gives a lint as expected.

fixes #8142

changelog: [`wrong_self_convention`] rejects `self` references in more cases
2022-01-02 17:14:18 +00:00
bors
7616eb0dd7 Auto merge of #8209 - xFrednet:8197-mention-attribute-on-struct, r=llogiq
return_self_not_must_use document `#[must_use]` on the type

Inspired by a discussion in rust-lang/rust-clippy#8197

---

r? `@llogiq`

changelog: none

The lint is this on nightly, therefore no changelog entry for you xD
2022-01-01 13:16:49 +00:00
bors
262b148d88 return_self_not_must_use document #[must_use] on the type
Inspired by a discussion in rust-lang/rust-clippy#8197

---

r? `@llogiq`

changelog: none

The lint is this on nightly, therefore no changelog entry for you xD
2022-01-01 13:16:49 +00:00
Josh Triplett
f5bbd1b529 Make tidy check for magic numbers that spell things
Remove existing problematic cases.
2021-12-31 21:13:07 -08:00
Nick Mathewson
3d41358a55 wrong_self_convention: Match SelfKind::No more restrictively
The `wrong_self_convention` lint uses a `SelfKind` type to decide
whether a method has the right kind of "self" for its name, or whether
the kind of "self" it has makes its name confusable for a method in
a common trait.  One possibility is `SelfKind::No`, which is supposed
to mean "No `self`".

Previously, SelfKind::No matched everything _except_ Self, including
references to Self.  This patch changes it to match Self, &Self, &mut
Self, Box<Self>, and so on.

For example, this kind of method was allowed before:

```
impl S {
    // Should trigger the lint, because
    // "methods called `is_*` usually take `self` by reference or no `self`"
    fn is_foo(&mut self) -> bool { todo!() }
}
```

But since SelfKind::No matched "&mut self", no lint was triggered
(see #8142).

With this patch, the code above now gives a lint as expected.

Fixes #8142

changelog: [`wrong_self_convention`] rejects `self` references in more cases
2021-12-31 23:39:40 -05:00
bors
c736a63123 Auto merge of #8193 - ebobrow:redundant_closure_fp, r=Manishearth
fix [`redundant_closure`] fp with `Rc<F>`/`Arc<F>`

fixes #8073

changelog: don't trigger [`redundant_closure`] on `Arc<F>` or `Rc<F>`
2021-12-31 19:01:42 +00:00
bors
490566bb38 Auto merge of #8179 - nmathewson:unused_async_io_amount, r=xFrednet
Extend unused_io_amount to cover async io.

Clippy helpfully warns about code like this, telling you that you
probably meant "write_all":

    fn say_hi<W:Write>(w: &mut W) {
       w.write(b"hello").unwrap();
    }

This patch attempts to extend the lint so it also covers this
case:

    async fn say_hi<W:AsyncWrite>(w: &mut W) {
       w.write(b"hello").await.unwrap();
    }

(I've run into this second case several times in my own programming,
and so have my coworkers, so unless we're especially accident-prone
in this area, it's probably worth addressing?)

Since this is my first attempt at a clippy patch, I've probably
made all kinds of mistakes: please help me fix them?  I'd like
to learn more here.

Open questions I have:

  * Should this be a separate lint from unused_io_amount?  Maybe
    unused_async_io_amount?  If so, how should I structure their
    shared code?
  * Should this cover tokio's AsyncWrite too?
  * Is it okay to write lints for stuff that isn't part of
    the standard library?  I see that "regex" also has lints,
    and I figure that "futures" is probably okay too, since it's
    an official rust-lang repository.
  * What other tests are needed?
  * How should I improve the code?

Thanks for your time!

---

changelog: [`unused_io_amount`] now supports async read and write traits
2021-12-31 17:36:04 +00:00
Nick Mathewson
b6bcf0c51b unused_io_amount: Use span_lint_and_help.
This improves the quality of the genrated output and makes it
more in line with other lint messages.

changelog: [`unused_io_amount`]: Improve help text
2021-12-31 12:21:43 -05:00
Nick Mathewson
65d1f83d2c Extend [unused_io_amount] to cover AsyncRead and AsyncWrite.
Clippy helpfully warns about code like this, telling you that you
probably meant "write_all":

    fn say_hi<W:Write>(w: &mut W) {
       w.write(b"hello").unwrap();
    }

This patch attempts to extend the lint so it also covers this
case:

    async fn say_hi<W:AsyncWrite>(w: &mut W) {
       w.write(b"hello").await.unwrap();
    }

(I've run into this second case several times in my own programming,
and so have my coworkers, so unless we're especially accident-prone
in this area, it's probably worth addressing?)

This patch covers the Async{Read,Write}Ext traits in futures-rs,
and in tokio, since both are quite widely used.

changelog: [`unused_io_amount`] now supports AsyncReadExt and AsyncWriteExt.
2021-12-31 12:10:59 -05:00
bors
1f3d6a669e Auto merge of #92252 - GuillaumeGomez:update-pulldown, r=camelid,xFrednet
Update pulldown-cmark version to 0.9

Fixes https://github.com/rust-lang/rust/issues/92206.

r? `@camelid`
2021-12-31 12:46:38 +00:00
Cameron Steffen
2b5257e4c7 Remove method_call! macro 2021-12-30 13:37:14 -06:00
flip1995
97ab44ca97 Merge commit '0eff589afc83e21a03a168497bbab6b4dfbb4ef6' into clippyup 2021-12-30 15:10:43 +01:00
bors
0eff589afc Auto merge of #8196 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
2021-12-30 13:22:47 +00:00
flip1995
b0f9894491
Bump nightly version -> 2021-12-30 2021-12-30 14:18:01 +01:00
flip1995
e45842e360
Merge remote-tracking branch 'upstream/master' into rustup 2021-12-30 14:17:53 +01:00
Elliot Bobrow
828ddbe414 fix [redundant_closure] fp with Arc 2021-12-29 09:05:04 -08:00
bors
c1cd64b9c6 Auto merge of #8117 - hotate29:issue7320, r=camsteffen
update: ```Sugg::not()``` replacing the comparison operator. #7320

fixes #7320

changelog: ```needless_bool```: Changed to make a smart suggestion.
2021-12-28 22:15:53 +00:00
bors
16ef044e72 Auto merge of #8183 - alex-ozdemir:limit-ident, r=camsteffen
Limit the ``[`identity_op`]`` lint to integral operands.

changelog: limit ``[`identity_op`]`` to integral operands

In the ``[`identity_op`]`` lint, if the operands are non-integers, then the lint is likely
wrong.
2021-12-28 22:01:57 +00:00
bors
a139949ead Auto merge of #8187 - ApamNapat:fix_7651, r=llogiq
Fixed issues with to_radians and to_degrees lints

fixes #7651

I fixed the original problem as described in the issue, but the bug remains for complex expressions (the commented out TC I added is an example). I would also love some feedback on how to cleanup my code and reduce duplication. I hope it's not a problem that the issue has been claimed by someone else - that was over two months ago.

changelog: ``[`suboptimal_flops`]`` no longer proposes broken code with `to_radians` and `to_degrees`
2021-12-28 17:11:40 +00:00
BB
d5c4119d42 Fixed issues with to_radians and to_degrees lints 2021-12-28 17:49:18 +01:00
Alex Ozdemir
ee6d5c5cda contants peel_refs to catch x << &0 2021-12-28 08:32:55 -08:00
Alex Ozdemir
bc0579f5bf test 2021-12-28 08:19:58 -08:00
Guillaume Gomez
dfd32544fa Update pulldown-cmark version in clippy 2021-12-28 16:19:23 +01:00
bors
56ccd30a27 Auto merge of #8127 - dswij:8090, r=xFrednet
Fix `enum_variants` FP on prefixes that are not camel-case

closes #8090

Fix FP on `enum_variants` when prefixes are only a substring of a camel-case word. Also adds some util helpers on `str_utils` to help parsing camel-case strings.

This changes how the lint behaves:

1. previously if the Prefix is only a length of 1, it's going to get ignored, i.e. these were previously ignored and now is warned
```rust
enum Foo {
    cFoo,
    cBar,
    cBaz,
}

enum Something {
    CCall,
    CCreate,
    CCryogenize,
}
```

2. non-ascii characters that doesn't have casing will not be split,
```rust
enum NonCaps {
    PrefixXXX,
    PrefixTea,
    PrefixCake,
}
```
will be considered as `PrefixXXX`, `Prefix`, `Prefix`, so this won't lint as opposed to fired previously.

changelog: [`enum_variant_names`] Fix FP when first prefix are only a substring of a camel-case word.

---

 (Edited by `@xFrednet` removed some non ascii characters)
2021-12-28 12:01:21 +00:00
bors
526fb6b7ea Auto merge of #8185 - dswij:8177, r=llogiq
`needless_return` suggest return unit type on void returns

closes #8177

previously, `needless_return` suggests an empty block `{}` to replace void `return` on match arms, this PR improve the suggestion by suggesting a unit instead.

changelog: `needless_return` suggests `()` instead of `{}` on match arms
2021-12-28 11:15:53 +00:00
bors
fc72e910fb needless_return suggest return unit type on void returns
closes #8177

previously, `needless_return` suggests an empty block `{}` to replace void `return` on match arms, this PR improve the suggestion by suggesting a unit instead.

changelog: `needless_return` suggests `()` instead of `{}` on match arms
2021-12-28 11:15:53 +00:00
bors
3c1b3ece99 Auto merge of #8175 - Kage-Yami:feature/document-8145, r=llogiq
Readme: note that config changes don't apply to already compiled code

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

changelog: added a note to the Readme that config changes don't apply to already compiled code
2021-12-28 09:29:08 +00:00
bors
a11e5c210a Readme: note that config changes don't apply to already compiled code
*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: added a note to the Readme that config changes don't apply to already compiled code
2021-12-28 09:29:08 +00:00
bors
3354876876 Auto merge of #8182 - rust-lang:cache-test-items, r=giraffate
cache test item names

This avoids quadratic behavior (collecting all test item names for each `eq_op` instance within the module). However, it invests a good deal of memory to buy this speedup. If that becomes a problem, I may need to change the cache to only store the chain of last visited modules.

This hopefully fixes #8171.

---

changelog: none
2021-12-28 05:50:20 +00:00
Andre Bogus
8da9a823cb cache test item names 2021-12-28 06:39:21 +01:00
bors
5d194d1952 Auto merge of #8181 - ApamNapat:typos_fixes, r=giraffate
Fixed some typos in README and CONTRIBUTING

changelog: none
2021-12-28 00:29:24 +00:00
Alex Ozdemir
ba70842c62 Limit the identity_op lint to integral operands.
If operands are being applied to non-integers, then the lint is likely
wrong.
2021-12-27 16:06:27 -08:00
BB
b59ff5861a Fixed some typos in README and CONTRIBUTING 2021-12-28 00:08:25 +01:00
bors
adba132411 Auto merge of #8170 - rust-lang:numbered-fields, r=xFrednet
new lint: `init-numbered-fields`

This fixes #7985.

r? `@xFrednet`

---

changelog: new lint: [`init_numbered_fields`]
2021-12-27 21:02:15 +00:00