Commit Graph

415 Commits

Author SHA1 Message Date
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
flip1995
e45842e360
Merge remote-tracking branch 'upstream/master' into rustup 2021-12-30 14:17:53 +01: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
Alex Ozdemir
ee6d5c5cda contants peel_refs to catch x << &0 2021-12-28 08:32:55 -08: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
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
Andre Bogus
3ebd2bc2e4 new lint: init-numbered-fields 2021-12-26 16:19:22 +01:00
dswij
6f7e5cbe21 Some minor cleanup 2021-12-25 21:55:20 +08:00
dswij
8ed723bb1f Update str_utils test 2021-12-25 21:55:20 +08:00
dswij
c76e2d1e59 Add str_util helpers to split camelcase strings 2021-12-25 21:55:15 +08:00
hotate29
45a3b51c6d
Use helper functions in ``Sugg`` tests. 2021-12-25 00:29:30 +09:00
hotate29
0b6d1fdea2
refactor ``Sugg::BinOp`` 2021-12-25 00:29:29 +09:00
hotate29
b3b65a1bf6
Add test 2021-12-25 00:29:24 +09:00
Piotr Mikulski
01b7411482 Refactor 2021-12-23 22:00:20 -08:00
Piotr Mikulski
26cc55133e rewrite the PR 2021-12-23 21:41:25 -08:00
flip1995
eb47398773
Test clippy_utils in CI
This makes sure that the tests in clippy_utils are run in CI.

When looking into this I discovered that two tests were failing and
multiple doc tests were failing. This fixes those tests and enables a
few more doc tests.
2021-12-20 19:56:06 +01:00
bors
879eccead7 Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obk
Remove `SymbolStr`

This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences.

Best reviewed one commit at a time.

r? `@oli-obk`
2021-12-19 09:31:37 +00:00
bors
af1eea3f0a Auto merge of #89841 - cormacrelf:let-else-typed, r=nagisa
Implement let-else type annotations natively

Tracking issue: #87335

Fixes #89688, fixes #89807, edit: fixes  #89960 as well

As explained in https://github.com/rust-lang/rust/issues/89688#issuecomment-940405082, the previous desugaring moved the let-else scrutinee into a dummy variable, which meant if you wanted to refer to it again in the else block, it had moved.

This introduces a new hir type, ~~`hir::LetExpr`~~ `hir::Let`, which takes over all the fields of `hir::ExprKind::Let(...)` and adds an optional type annotation. The `hir::Let` is then treated like a `hir::Local` when type checking a function body, specifically:

* `GatherLocalsVisitor` overrides a new `Visitor::visit_let_expr` and does pretty much exactly what it does for `visit_local`, assigning a local type to the `hir::Let` ~~(they could be deduplicated but they are right next to each other, so at least we know they're the same)~~
* It reuses the code in `check_decl_local` to typecheck the `hir::Let`, simply returning 'bool' for the expression type after doing that.

* ~~`FnCtxt::check_expr_let` passes this local type in to `demand_scrutinee_type`, and then imitates check_decl_local's pattern checking~~
* ~~`demand_scrutinee_type` (the blindest change for me, please give this extra scrutiny) uses this local type instead of of creating a new one~~
    * ~~Just realised the `check_expr_with_needs` was passing NoExpectation further down, need to pass the type there too. And apparently this Expectation API already exists.~~

Some other misc notes:

* ~~Is the clippy code supposed to be autoformatted? I tried not to give huge diffs but maybe some rustfmt changes simply haven't hit it yet.~~
* in `rustc_ast_lowering/src/block.rs`, I noticed some existing `self.alias_attrs()` calls in `LoweringContext::lower_stmts` seem to be copying attributes from the lowered locals/etc to the statements. Is that right? I'm new at this, I don't know.
2021-12-17 22:12:34 +00:00
hotate29
13ad14b22d
update: ``Sugg::not()`` replacing the comparison operator. #7320
When inverting an expression, the output is now like ```foo != 0``` instead of ```!(foo == 0)```, the comparison operator is now replaced.
2021-12-18 00:07:36 +09:00
flip1995
ece0946d7f Merge commit '23d11428de3e973b34a5090a78d62887f821c90e' into clippyup 2021-12-17 13:40:22 +01:00
flip1995
fad9407c5a
Merge remote-tracking branch 'upstream/master' into rustup 2021-12-17 13:22:25 +01:00
Nicholas Nethercote
ecd4919ebb Remove unnecessary sigils around Symbol::as_str() calls. 2021-12-15 17:32:14 +11:00
Nicholas Nethercote
a89a063ba0 Remove SymbolStr.
By changing `as_str()` to take `&self` instead of `self`, we can just
return `&str`. We're still lying about lifetimes, but it's a smaller lie
than before, where `SymbolStr` contained a (fake) `&'static str`!
2021-12-15 13:30:26 +11:00
Matthias Krüger
55df990a9b Rollup merge of #91881 - Patrick-Poitras:stabilize-iter-zip, r=scottmcm
Stabilize `iter::zip`

Hello all!

As the tracking issue (#83574) for `iter::zip` completed the final commenting period without any concerns being raised, I hereby submit this stabilization PR on the issue.

As the pull request that introduced the feature (#82917) states, the `iter::zip` function is a shorter way to zip two iterators. As it's generally a quality-of-life/ergonomic improvement, it has been integrated into the codebase without any trouble, and has been
used in many places across the rust compiler and standard library since March without any issues.

For more details, I would refer to `@cuviper's` original PR, or the [function's documentation](https://doc.rust-lang.org/std/iter/fn.zip.html).
2021-12-15 01:28:08 +01:00
PFPoitras
288afb366a Remove iter::zip feature gate from clippy 2021-12-14 18:50:46 -04:00
Esteban Kuber
d8af82e4bb Fix clippy uses of QPath::LangItem 2021-12-13 17:09:16 +00:00
Samuel E. Moelius III
3807905e08 Handle to_vec on for loop expression #8069 2021-12-13 07:04:57 -05:00
Samuel E. Moelius III
290f74be4e Address review comments
* Share a list of methods with `implicit_clone`
* Ensure no overlap with `redundant_clone`
2021-12-13 06:31:17 -05:00
Samuel E. Moelius III
468c86e4a3 Add unnecessary_to_owned lint 2021-12-13 06:31:17 -05:00
Cormac Relf
17c1ff9faa let-else: use hir::Let in clippy
fix clippy format using `cargo fmt -p clippy_{lints,utils}`
manually revert rustfmt line truncations
rename to hir::Let in clippy
Undo the shadowing of various `expr` variables after renaming `scrutinee`
reduce destructuring of hir::Let to avoid `expr` collisions
cargo fmt -p clippy_{lints,utils}
bless new clippy::author output
2021-12-13 14:02:41 +11:00
bors
53059792e9 Auto merge of #8071 - GuillaumeGomez:method-must-use, r=xFrednet
Add new lint to warn when #[must_use] attribute should be used on a method

This lint is somewhat similar to https://rust-lang.github.io/rust-clippy/master/index.html#must_use_candidate but also different: it emits a warning by default and only targets methods (so not functions nor associated functions).

Someone suggested it to me after this tweet: https://twitter.com/m_ou_se/status/1466439813230477312

I think it would reduce the number of cases of API misuses quite a lot.

What do you think?

---

changelog: Added new [`return_self_not_must_use`] lint
2021-12-08 19:09:25 +00:00
Guillaume Gomez
e93767b395 Apply new lint on clippy source code 2021-12-08 11:16:14 +01:00
Guillaume Gomez
8dfb3ec8a4 Add new lint to warn when #[must_use] attribute should be used on a method 2021-12-08 11:16:14 +01:00
Cameron Steffen
f690ef6f5c Refactors with peel_blocks 2021-12-06 12:33:02 -06:00
Cameron Steffen
284b63a687 Rename remove_blocks to peel_blocks 2021-12-06 12:33:02 -06:00
flip1995
8fea1d94f3 Merge commit 'a5d597637dcb78dc73f93561ce474f23d4177c35' into clippyup 2021-12-06 12:33:31 +01:00
Yechan Bae
844996b42e Consider NonNull as a pointer type 2021-12-03 19:11:40 -05:00
bors
d5d830a50f Auto merge of #7463 - ThibsG:find_any_7392, r=xFrednet
Fix `any()` not taking reference in `search_is_some` lint

`find` gives reference to the item, but `any` does not, so suggestion is broken in some specific cases.

Fixes: #7392

changelog: [`search_is_some`] Fix suggestion for `any()` not taking item by reference
2021-12-02 17:27:54 +00:00
flip1995
ec57cc1455
Bump Clippy Version -> 0.1.59 2021-12-02 09:32:47 +00:00
bors
908815ce98 Auto merge of #8001 - Jarcho:unprefixed_strlen, r=giraffate
Improve `strlen_on_c_string`

fixes: #7436

changelog: lint `strlen_on_c_string` when used without a fully-qualified path
changelog: suggest removing the surrounding unsafe block for `strlen_on_c_string` when possible
2021-11-29 01:03:48 +00:00
ThibsG
a8e7fed172 Add a note about type annotation on closure param 2021-11-28 10:22:15 +01:00
ThibsG
917fdb11e4 Rewrite comment when handling special case for ProjectionKind::Deref 2021-11-27 20:32:50 +01:00
ThibsG
c5ce7ff6d9 Add Index when checking projs in a call, rename some variables and remove unneeded statements 2021-11-27 19:22:19 +01:00
flip1995
5740230ec7
Merge remote-tracking branch 'upstream/master' into rustup 2021-11-23 11:22:34 +01:00
Cameron Steffen
e58ffb88e6 Fix Clippy with changed for loop desugar 2021-11-21 08:16:09 -06:00
ThibsG
092fe209a6 Move deref closure builder to clippy_utils::sugg module 2021-11-20 15:48:21 +01:00
Jason Newcomb
0d1f1cec44 Remove surrounding unsafe block in strlen_on_c_strings when possible 2021-11-19 21:14:51 -05:00
Jason Newcomb
c443f8fb95 Fix strlen_on_c_strings when not used with a full path 2021-11-19 20:02:49 -05:00