Add two more tests, allow 2 other lints.

This commit is contained in:
Philipp Hansch 2019-08-21 07:43:42 +02:00
parent 84716e49f0
commit 436d429d27
No known key found for this signature in database
GPG Key ID: 82AA61CAA11397E6
2 changed files with 25 additions and 11 deletions

View File

@ -1,5 +1,6 @@
#![warn(clippy::all)] #![warn(clippy::all)]
#![warn(clippy::redundant_pattern_matching)] #![warn(clippy::redundant_pattern_matching)]
#![allow(clippy::unit_arg, clippy::let_unit_value)]
fn main() { fn main() {
if let Ok(_) = Ok::<i32, i32>(42) {} if let Ok(_) = Ok::<i32, i32>(42) {}
@ -61,8 +62,17 @@ fn main() {
let _ = does_something(); let _ = does_something();
let _ = returns_unit(); let _ = returns_unit();
let opt = Some(false);
let x = if let Some(_) = opt { true } else { false };
takes_bool(x);
let y = if let Some(_) = opt {};
takes_unit(y);
} }
fn takes_bool(x: bool) {}
fn takes_unit(x: ()) {}
fn does_something() -> bool { fn does_something() -> bool {
if let Ok(_) = Ok::<i32, i32>(4) { if let Ok(_) = Ok::<i32, i32>(4) {
true true

View File

@ -79,10 +79,10 @@ LL | | };
| |_____^ help: try this: `None::<()>.is_none()` | |_____^ help: try this: `None::<()>.is_none()`
error: redundant pattern matching, consider using `is_none()` error: redundant pattern matching, consider using `is_none()`
--> $DIR/redundant_pattern_matching.rs:56:15 --> $DIR/redundant_pattern_matching.rs:56:13
| |
LL | let foo = match None::<()> { LL | let _ = match None::<()> {
| _______________^ | _____________^
LL | | Some(_) => false, LL | | Some(_) => false,
LL | | None => true, LL | | None => true,
LL | | }; LL | | };
@ -94,16 +94,20 @@ error: redundant pattern matching, consider using `is_ok()`
LL | let _ = if let Ok(_) = Ok::<usize, ()>(4) { true } else { false }; LL | let _ = if let Ok(_) = Ok::<usize, ()>(4) { true } else { false };
| -------^^^^^--------------------------------------------- help: try this: `Ok::<usize, ()>(4).is_ok()` | -------^^^^^--------------------------------------------- help: try this: `Ok::<usize, ()>(4).is_ok()`
error: this let-binding has unit value error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching.rs:64:5 --> $DIR/redundant_pattern_matching.rs:67:20
| |
LL | let _ = returns_unit(); LL | let x = if let Some(_) = opt { true } else { false };
| ^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `returns_unit();` | -------^^^^^^^------------------------------ help: try this: `opt.is_some()`
error: redundant pattern matching, consider using `is_some()`
--> $DIR/redundant_pattern_matching.rs:69:20
| |
= note: `-D clippy::let-unit-value` implied by `-D warnings` LL | let y = if let Some(_) = opt {};
| -------^^^^^^^--------- help: try this: `opt.is_some()`
error: redundant pattern matching, consider using `is_ok()` error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching.rs:68:12 --> $DIR/redundant_pattern_matching.rs:77:12
| |
LL | if let Ok(_) = Ok::<i32, i32>(4) { LL | if let Ok(_) = Ok::<i32, i32>(4) {
| _____- ^^^^^ | _____- ^^^^^
@ -114,7 +118,7 @@ LL | | }
| |_____- help: try this: `Ok::<i32, i32>(4).is_ok()` | |_____- help: try this: `Ok::<i32, i32>(4).is_ok()`
error: redundant pattern matching, consider using `is_ok()` error: redundant pattern matching, consider using `is_ok()`
--> $DIR/redundant_pattern_matching.rs:76:12 --> $DIR/redundant_pattern_matching.rs:85:12
| |
LL | if let Ok(_) = Ok::<i32, i32>(4) { LL | if let Ok(_) = Ok::<i32, i32>(4) {
| _____- ^^^^^ | _____- ^^^^^
@ -124,5 +128,5 @@ LL | | false
LL | | }; LL | | };
| |_____- help: try this: `Ok::<i32, i32>(4).is_ok()` | |_____- help: try this: `Ok::<i32, i32>(4).is_ok()`
error: aborting due to 15 previous errors error: aborting due to 16 previous errors