forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#6339 - CDirkx:redundant-pattern-match-poll, r…
…=ebroto Change `redundant_pattern_matching` to also lint `std::task::Poll` `reduntant_pattern_matching` currently lints pattern matching on `Option` and `Result` where the `is_variant` utility methods could be used instead: `is_some`, `is_none`, `is_ok`, `is_err`. This PR extends this behaviour to `std::task::Poll`, suggesting the methods `is_pending` and `is_ready`. Motivation: The current description of `redundant_pattern_matching` mentions > It's more concise and clear to just use the proper utility function which in my mind applies to `Poll` as well. changelog: Enhance [`redundant_pattern_matching`] to also lint on `std::task::Poll`
- Loading branch information
Showing
11 changed files
with
364 additions
and
60 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
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
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,73 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::all)] | ||
#![warn(clippy::redundant_pattern_matching)] | ||
#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)] | ||
|
||
use std::task::Poll::{self, Pending, Ready}; | ||
|
||
fn main() { | ||
if Pending::<()>.is_pending() {} | ||
|
||
if Ready(42).is_ready() {} | ||
|
||
if Ready(42).is_ready() { | ||
foo(); | ||
} else { | ||
bar(); | ||
} | ||
|
||
while Ready(42).is_ready() {} | ||
|
||
while Ready(42).is_pending() {} | ||
|
||
while Pending::<()>.is_pending() {} | ||
|
||
if Pending::<i32>.is_pending() {} | ||
|
||
if Ready(42).is_ready() {} | ||
|
||
Ready(42).is_ready(); | ||
|
||
Pending::<()>.is_pending(); | ||
|
||
let _ = Pending::<()>.is_pending(); | ||
|
||
let poll = Ready(false); | ||
let x = if poll.is_ready() { true } else { false }; | ||
takes_poll(x); | ||
|
||
poll_const(); | ||
|
||
let _ = if gen_poll().is_ready() { | ||
1 | ||
} else if gen_poll().is_pending() { | ||
2 | ||
} else { | ||
3 | ||
}; | ||
} | ||
|
||
fn gen_poll() -> Poll<()> { | ||
Pending | ||
} | ||
|
||
fn takes_poll(_: bool) {} | ||
|
||
fn foo() {} | ||
|
||
fn bar() {} | ||
|
||
const fn poll_const() { | ||
if Ready(42).is_ready() {} | ||
|
||
if Pending::<()>.is_pending() {} | ||
|
||
while Ready(42).is_ready() {} | ||
|
||
while Pending::<()>.is_pending() {} | ||
|
||
Ready(42).is_ready(); | ||
|
||
Pending::<()>.is_pending(); | ||
} |
Oops, something went wrong.