Commit graph

8477 commits

Author SHA1 Message Date
bors
0c9427309c Auto merge of #5596 - ebroto:issue_5212, r=phansch
Fix comparison_chain false positive

changelog: comparison_chain: fix false positives when the binary operation is the same.

Fixes #5212
2020-05-16 08:49:15 +00:00
bors
53a98050b8 Auto merge of #5602 - ebroto:issue_3430, r=phansch
identity_op: allow `1 << 0`

I went for accepting `1 << 0` verbatim instead of something more general as it seems to be what everyone in the issue thread needed.

changelog: identity_op: allow `1 << 0` as it's a common pattern in bit manipulation code.

Fixes #3430
2020-05-16 08:33:47 +00:00
bors
cac9ad02cf Auto merge of #5599 - dtolnay:letif, r=flip1995
Downgrade useless_let_if_seq to nursery

I feel that this lint has the wrong balance of incorrect suggestions for a default-enabled lint.

The immediate code I faced was something like:

```rust
fn main() {
    let mut good = do1();
    if !do2() {
        good = false;
    }
    if good {
        println!("good");
    }
}

fn do1() -> bool { println!("1"); false }
fn do2() -> bool { println!("2"); false }
```

On this code Clippy calls it unidiomatic and suggests the following diff, which has different behavior in a way that I don't necessarily want.

```diff
- let mut good = do1();
- if !do2() {
-     good = false;
- }
+ let good = if !do2() {
+     false
+ } else {
+     do1()
+ };
```

On exploring issues filed about this lint, I have found that other users have also struggled with inappropriate suggestions (https://github.com/rust-lang/rust-clippy/issues/4124, https://github.com/rust-lang/rust-clippy/issues/3043, https://github.com/rust-lang/rust-clippy/issues/2918, https://github.com/rust-lang/rust-clippy/issues/2176) and suggestions that make the code worse (https://github.com/rust-lang/rust-clippy/issues/3769, https://github.com/rust-lang/rust-clippy/issues/2749). Overall I believe that this lint is still at nursery quality for now and should not be enabled.

---

changelog: Remove useless_let_if_seq from default set of enabled lints
2020-05-15 21:55:43 +00:00
Eduardo Broto
fc8ab099c3 identity_op: allow 1 << 0 2020-05-15 21:17:37 +02:00
bors
e22ccf5332 Auto merge of #5592 - ebroto:extend_unused_unit, r=flip1995
unused_unit: lint also in type parameters and where clauses

changelog: unused_unit now also lints in type parameters and where clauses

Fixes #5585
2020-05-15 14:47:11 +00:00
David Tolnay
95399f8f94
Downgrade useless_let_if_seq to nursery 2020-05-14 09:57:36 -07:00
bors
e1842b0cac Auto merge of #5583 - ebroto:reversed_empty_ranges, r=yaahc,flip1995
Reversed empty ranges

This lint checks range expressions with inverted limits which result in empty ranges. This includes also the ranges used to index slices.

The lint reverse_range_loop was covering iteration of reversed ranges in a for loop, which is a subset of what this new lint covers, so it has been removed. I'm not sure if that's the best choice. It would be doable to check in the new lint that we are not in the arguments of a for loop; I went for removing it because the logic was too similar to keep them separated.

changelog: Added reversed_empty_ranges lint that checks for ranges where the limits have been inverted, resulting in empty ranges. Removed reverse_range_loop which was covering a subset of the new lint.

Closes #4192
Closes #96
2020-05-14 12:59:24 +00:00
bors
7147068399 Auto merge of #5590 - ebroto:issue_5579, r=phansch
Fix ICE caused in unwrap module

changelog: Fix ICE in unwrap module with unexpected number of parameters for method of Option/Result

Fixes #5579
2020-05-14 05:34:54 +00:00
Eduardo Broto
9217675c7f Fix comparison_chain false positive 2020-05-14 00:26:09 +02:00
Eduardo Broto
671c1e34cc Avoid running doctest that is expected to panic 2020-05-13 21:07:13 +02:00
Eduardo Broto
8d1029d3ca Move test for issue 5579 under tests/ui/crashes 2020-05-13 20:47:44 +02:00
Eduardo Broto
e4cd8e7961 Fix ICE caused in unwrap module 2020-05-13 20:35:52 +02:00
Eduardo Broto
064431d22f Re-add old tests for empty range loops 2020-05-13 20:33:32 +02:00
Eduardo Broto
0f2b1193f9 Remove reverse_range_loop lint 2020-05-13 20:33:32 +02:00
Eduardo Broto
8ffa0bfaa2 New lint: reversed_empty_ranges 2020-05-13 20:33:32 +02:00
Eduardo Broto
f20b962773 unused_unit: lint also in type parameters and where clauses 2020-05-13 20:33:12 +02:00
bors
b20a9cd474 Auto merge of #5587 - flip1995:rustup, r=phansch
Rustup

Done with

```bash
git subtree push -P src/tools/clippy git@github.com:flip1995/rust-clippy rustup
```

from https://github.com/flip1995/rust/tree/clippyup

A rebase was required to get rid of empty merge commits, that somehow were not empty? 🤔

changelog: none
2020-05-13 05:55:10 +00:00
flip1995
eec17d2c21
Update failing test 2020-05-11 21:40:33 +02:00
flip1995
505280b108
Run cargo dev fmt 2020-05-11 21:31:01 +02:00
flip1995
33a3d852f5
Fix fallout
Re-remove util/dev file
2020-05-11 21:28:14 +02:00
Camille GILLOT
8ab3224b3b
Fix clippy. 2020-05-11 21:26:39 +02:00
Jack Huey
01662d3a23
Fix nit and cargo.lock 2020-05-11 21:26:38 +02:00
bors
43a1777b89 Auto merge of #5564 - MrAwesome:master, r=flip1995
Allow `use super::*;` glob imports

changelog: Allow super::* glob imports

fixes #5554
fixes #5569

A first pass at #5554 - this allows all `use super::*` to pass, which may or may not be desirable. The original issue was around allowing test modules to import their entire parent modules - I'm happy to modify this to do that instead, may just need some guidance on how to implement that (I played around a bit with #[cfg(test)] but from what I can gather, clippy itself isn't in test mode when running, even if the code in question is being checked for the test target).
2020-05-09 18:43:28 +00:00
Glenn Hope
b69200b846 Move is_test_module check to top of function 2020-05-09 11:10:16 -07:00
Glenn Hope
0ba61c612e Check is_macro inside check_exceptions, update references to fix test 2020-05-09 11:10:16 -07:00
Glenn Hope
a339766136 Fix test from auto-formatter fix 2020-05-09 11:10:16 -07:00
Glenn Hope
4db6abcd50 Remove check for Fn, reflect this in test cases, make test cases more robust/explicit 2020-05-09 11:09:38 -07:00
Glenn Hope
152cdcb45b Remove unnecessary field, check for Mod/Fn ItemKind 2020-05-09 11:09:38 -07:00
Glenn Hope
a42a2bdac2 Also have flag disable macro check 2020-05-09 11:09:38 -07:00
Glenn Hope
ad92486d52 Add check for "test" in parent name. Include flag for disabling wildcard import exceptions 2020-05-09 11:09:38 -07:00
Glenn Hope
56f4e1c3a8 Check if the parent module name contains "test" 2020-05-09 11:09:38 -07:00
Glenn Hope
bdc75dbb7b Run cargo dev fmt 2020-05-09 11:09:38 -07:00
Glenn Hope
0c14ea8ed7 Allow 'use super::*;' imports 2020-05-09 11:09:38 -07:00
bors
43d9cdc7b3 Auto merge of #5580 - matthiaskrgr:regex_dep, r=flip1995
deps: remove unused regex dependency from root crate

changelog: none
2020-05-09 12:41:19 +00:00
Matthias Krüger
438877380a deps: remove unused regex dependency from root crate 2020-05-09 01:27:30 +02:00
bors
ceddf34b2e Auto merge of #5541 - DarkEld3r:patch-1, r=flip1995
Extend example for the `unneeded_field_pattern` lint

Current example is incorrect (or pseudo-code) because a struct name is omitted. I have used the code from the tests instead. Perhaps this example can be made less verbose, but I think it is more convenient to see a "real" code as an example.

---

changelog: extend example for the `unneeded_field_pattern` lint
2020-05-08 10:34:50 +00:00
bors
78b7d4944c Auto merge of #5576 - ebroto:manual_async_fn, r=flip1995
Add the manual_async_fn lint

changelog: Added the `manual_async_fn` lint to warn on functions that can be simplified using async syntax

Closes #5503
2020-05-08 01:50:28 +00:00
Eduardo Broto
3e4bc026e2 Apply suggestions from PR review 2020-05-07 22:40:28 +02:00
Eduardo Broto
4ac348b308 Fix doc comment in lint declaration 2020-05-07 22:03:38 +02:00
Eduardo Broto
3b58d66b22 Add the manual_async_fn lint 2020-05-07 21:42:40 +02:00
bors
b63868dedb Auto merge of #5566 - oli-obk:sync-from-rustc, r=flip1995
Update to rustc changes

changelog: none

So, turns out `git subtree push` dies in various interesting ways, but the source cause is that the rustc repo looks like

```
--- A --- B --- C ---
     \--- D ---/
```

where `B` is the commit where I added clippy to rustc and `D` is an arbitrary other PR and `C` is the master branch (or an earlier commit in it). When we now do `git subtree push`, it doesn't stop looking for things to merge at `B` as it needs to look at `D`, too, but then the bad thing happens, and it doesn't stop at `A` either, and just goes on looking at the entire history of rustc in a recursive bash script. That recursion then quickly runs into a stack overflow. While we can increase the stack size via `ulimit -s 60000`, that just means I was waiting for 30 minutes looking at `git subtree push` counting up the number of commits it has looked at. I aborted that, as a process that needs 30 mins for a push is not reasonable.

This PR cheats by just doing a `cp -r ../rustc/src/tools/clippy/* .` inside my clippy checkout and committing all changes. I'm working on getting us a better workflow, but until then, this workaround will work nicely. Note that this requires a `git subrepo pull` to have occurred in the `rustc` checkout. It's not necessary to merge that pull in order to update clippy, it's just necessary in order to not revert code in the clippy repo that hasn't been synced yet to the rustc repo.
2020-05-06 09:49:00 +00:00
Oliver Scherer
780a63a1ba Update ui tests 2020-05-05 15:11:59 +02:00
Oliver Scherer
7744cf4e53 Update to rustc changes 2020-05-04 15:13:07 +02:00
bors
76ddac5e8e Auto merge of #5560 - CrazyRoka:fix-match-on-vector-full-range, r=phansch,flip1995
Fix match on vec items: match on vec[..]

- Added new tests
- Fixed false positive when matching on full range, which will never panic

Closes #5551
changelog: fix match_on_vec_items when matching full range
2020-05-02 16:13:02 +00:00
bors
75a717159d Auto merge of #5558 - ThibsG:FixUnwrapInArgs, r=flip1995
Fix `unnecessary_unwrap` lint when checks are done in parameters

Fixes a false positive in `unnecessary_unwrap` lint when checks are done in macro parameters.

FIxes #5174

changelog: Fixes a false positive in `unnecessary_unwrap` lint when checks are done in macro parameters.
2020-05-02 15:59:18 +00:00
bors
60538d6c8e Auto merge of #5559 - alex-700:fix-while-let-on-iterator-fp, r=flip1995
Fix FP on while-let-on-iterator

- fix `is_refutable` for slice patterns
- fix `is_refutable` for bindings
- add some TODO-s for cases, which can not be fixed easily

fixes #3780

changelog: fix FP on while-let-on-iterator for arrays and bindings
2020-05-02 15:30:58 +00:00
CrazyRoka
de58c5644d Changed RANGE_FULL constant in utils 2020-05-02 17:37:03 +03:00
bors
cc9088f287 Auto merge of #5550 - ebroto:manual_non_exhaustive, r=flip1995
Implement the manual_non_exhaustive lint

Some implementation notes:
* Not providing automatic fixups because additional changes may be needed in other parts of the code, e.g. when constructing a struct.
* Even though the attribute is valid on enum variants, it's not possible to use the manual implementation of the pattern because the visibility is always public, so the lint ignores enum variants.
* Unit structs are also ignored, it's not possible to implement the pattern manually without fields.
* The attribute is not accepted in unions, so those are ignored too.
* Even though the original issue did not mention it, tuple structs are also linted because it's possible to apply the pattern manually.

changelog: Added the manual non-exhaustive implementation lint

Closes #2017
2020-05-02 13:53:39 +00:00
CrazyRoka
e7138e0629 Fix match on vec items: match on vec[..]
- Added new tests
- Fixed false positive when matching on full range, which will never panic
2020-05-02 14:25:45 +03:00
Aleksei Latyshev
d0c1f8ada2
fix fp on while-let-on-iterator
- fix `is_refutable` for slice patterns
- fix `is_refutable` for bindings
- add some TODO-s for cases, which can not be fixed easily
2020-05-02 14:21:29 +03:00