forked from rust-lang/rust-clippy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix suggestions for redundant_pattern_matching
Fixes the problem displayed in rust-lang#4344 (comment). We now append `{}` to the suggestion so that the conditional has the correct syntax again. (If we were to _remove_ the `if` instead, it would trigger the `unused_must_use` warning for `#[must_use]` types.
- Loading branch information
Showing
4 changed files
with
84 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::all)] | ||
#![warn(clippy::redundant_pattern_matching)] | ||
|
||
fn main() { | ||
if Ok::<i32, i32>(42).is_ok() {} | ||
|
||
if Err::<i32, i32>(42).is_err() {} | ||
|
||
if None::<()>.is_none() {} | ||
|
||
if Some(42).is_some() {} | ||
|
||
if Ok::<i32, i32>(42).is_ok() {} | ||
|
||
if Err::<i32, i32>(42).is_err() {} | ||
|
||
if None::<i32>.is_none() {} | ||
|
||
if Some(42).is_some() {} | ||
|
||
if let Ok(x) = Ok::<i32, i32>(42) { | ||
println!("{}", x); | ||
} | ||
|
||
if Ok::<i32, i32>(42).is_ok() {}; | ||
|
||
if Ok::<i32, i32>(42).is_err() {}; | ||
|
||
if Err::<i32, i32>(42).is_err() {}; | ||
|
||
if Err::<i32, i32>(42).is_ok() {}; | ||
|
||
if Some(42).is_some() {}; | ||
|
||
if None::<()>.is_none() {}; | ||
|
||
let bla: Result<usize, ()> = Ok(4); | ||
if bla.is_ok() {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,93 @@ | ||
error: redundant pattern matching, consider using `is_ok()` | ||
--> $DIR/redundant_pattern_matching.rs:5:12 | ||
--> $DIR/redundant_pattern_matching.rs:7:12 | ||
| | ||
LL | if let Ok(_) = Ok::<i32, i32>(42) {} | ||
| -------^^^^^------------------------ help: try this: `if Ok::<i32, i32>(42).is_ok()` | ||
| -------^^^^^------------------------ help: try this: `if Ok::<i32, i32>(42).is_ok() {}` | ||
| | ||
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` | ||
|
||
error: redundant pattern matching, consider using `is_err()` | ||
--> $DIR/redundant_pattern_matching.rs:7:12 | ||
--> $DIR/redundant_pattern_matching.rs:9:12 | ||
| | ||
LL | if let Err(_) = Err::<i32, i32>(42) {} | ||
| -------^^^^^^------------------------- help: try this: `if Err::<i32, i32>(42).is_err()` | ||
| -------^^^^^^------------------------- help: try this: `if Err::<i32, i32>(42).is_err() {}` | ||
|
||
error: redundant pattern matching, consider using `is_none()` | ||
--> $DIR/redundant_pattern_matching.rs:9:12 | ||
--> $DIR/redundant_pattern_matching.rs:11:12 | ||
| | ||
LL | if let None = None::<()> {} | ||
| -------^^^^---------------- help: try this: `if None::<()>.is_none()` | ||
| -------^^^^---------------- help: try this: `if None::<()>.is_none() {}` | ||
|
||
error: redundant pattern matching, consider using `is_some()` | ||
--> $DIR/redundant_pattern_matching.rs:11:12 | ||
--> $DIR/redundant_pattern_matching.rs:13:12 | ||
| | ||
LL | if let Some(_) = Some(42) {} | ||
| -------^^^^^^^-------------- help: try this: `if Some(42).is_some()` | ||
| -------^^^^^^^-------------- help: try this: `if Some(42).is_some() {}` | ||
|
||
error: redundant pattern matching, consider using `is_ok()` | ||
--> $DIR/redundant_pattern_matching.rs:25:5 | ||
--> $DIR/redundant_pattern_matching.rs:27:5 | ||
| | ||
LL | / match Ok::<i32, i32>(42) { | ||
LL | | Ok(_) => true, | ||
LL | | Err(_) => false, | ||
LL | | }; | ||
| |_____^ help: try this: `Ok::<i32, i32>(42).is_ok()` | ||
| |_____^ help: try this: `if Ok::<i32, i32>(42).is_ok() {}` | ||
|
||
error: redundant pattern matching, consider using `is_err()` | ||
--> $DIR/redundant_pattern_matching.rs:30:5 | ||
--> $DIR/redundant_pattern_matching.rs:32:5 | ||
| | ||
LL | / match Ok::<i32, i32>(42) { | ||
LL | | Ok(_) => false, | ||
LL | | Err(_) => true, | ||
LL | | }; | ||
| |_____^ help: try this: `Ok::<i32, i32>(42).is_err()` | ||
| |_____^ help: try this: `if Ok::<i32, i32>(42).is_err() {}` | ||
|
||
error: redundant pattern matching, consider using `is_err()` | ||
--> $DIR/redundant_pattern_matching.rs:35:5 | ||
--> $DIR/redundant_pattern_matching.rs:37:5 | ||
| | ||
LL | / match Err::<i32, i32>(42) { | ||
LL | | Ok(_) => false, | ||
LL | | Err(_) => true, | ||
LL | | }; | ||
| |_____^ help: try this: `Err::<i32, i32>(42).is_err()` | ||
| |_____^ help: try this: `if Err::<i32, i32>(42).is_err() {}` | ||
|
||
error: redundant pattern matching, consider using `is_ok()` | ||
--> $DIR/redundant_pattern_matching.rs:40:5 | ||
--> $DIR/redundant_pattern_matching.rs:42:5 | ||
| | ||
LL | / match Err::<i32, i32>(42) { | ||
LL | | Ok(_) => true, | ||
LL | | Err(_) => false, | ||
LL | | }; | ||
| |_____^ help: try this: `Err::<i32, i32>(42).is_ok()` | ||
| |_____^ help: try this: `if Err::<i32, i32>(42).is_ok() {}` | ||
|
||
error: redundant pattern matching, consider using `is_some()` | ||
--> $DIR/redundant_pattern_matching.rs:45:5 | ||
--> $DIR/redundant_pattern_matching.rs:47:5 | ||
| | ||
LL | / match Some(42) { | ||
LL | | Some(_) => true, | ||
LL | | None => false, | ||
LL | | }; | ||
| |_____^ help: try this: `Some(42).is_some()` | ||
| |_____^ help: try this: `if Some(42).is_some() {}` | ||
|
||
error: redundant pattern matching, consider using `is_none()` | ||
--> $DIR/redundant_pattern_matching.rs:50:5 | ||
--> $DIR/redundant_pattern_matching.rs:52:5 | ||
| | ||
LL | / match None::<()> { | ||
LL | | Some(_) => false, | ||
LL | | None => true, | ||
LL | | }; | ||
| |_____^ help: try this: `None::<()>.is_none()` | ||
| |_____^ help: try this: `if None::<()>.is_none() {}` | ||
|
||
error: redundant pattern matching, consider using `is_ok()` | ||
--> $DIR/redundant_pattern_matching.rs:58:12 | ||
| | ||
LL | if let Ok(_) = bla { | ||
| _____- ^^^^^ | ||
LL | | true | ||
LL | | } else { | ||
LL | | false | ||
LL | | }; | ||
| |_____- help: try this: `if bla.is_ok() {}` | ||
|
||
error: aborting due to 10 previous errors | ||
error: aborting due to 11 previous errors | ||
|