mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
[redundant_pattern_matching
]: don't lint if if guards are present
This commit is contained in:
parent
568ccf3fc8
commit
c26801ee92
4 changed files with 41 additions and 30 deletions
|
@ -199,8 +199,11 @@ fn find_sugg_for_if_let<'tcx>(
|
|||
}
|
||||
|
||||
pub(super) fn check_match<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, op: &Expr<'_>, arms: &[Arm<'_>]) {
|
||||
if arms.len() == 2 {
|
||||
let node_pair = (&arms[0].pat.kind, &arms[1].pat.kind);
|
||||
if let [arm1, arm2] = arms
|
||||
&& arm1.guard.is_none()
|
||||
&& arm2.guard.is_none()
|
||||
{
|
||||
let node_pair = (&arm1.pat.kind, &arm2.pat.kind);
|
||||
|
||||
if let Some(good_method) = found_good_method(cx, arms, node_pair) {
|
||||
let span = is_expn_of(expr.span, "matches").unwrap_or(expr.span.to(op.span));
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
clippy::if_same_then_else
|
||||
)]
|
||||
|
||||
fn issue_11174<T>(boolean: bool, maybe_some: Option<T>) -> bool {
|
||||
matches!(maybe_some, None if !boolean)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if None::<()>.is_none() {}
|
||||
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
clippy::if_same_then_else
|
||||
)]
|
||||
|
||||
fn issue_11174<T>(boolean: bool, maybe_some: Option<T>) -> bool {
|
||||
matches!(maybe_some, None if !boolean)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
if let None = None::<()> {}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:15:12
|
||||
--> $DIR/redundant_pattern_matching_option.rs:19:12
|
||||
|
|
||||
LL | if let None = None::<()> {}
|
||||
| -------^^^^------------- help: try: `if None::<()>.is_none()`
|
||||
|
@ -7,43 +7,43 @@ LL | if let None = None::<()> {}
|
|||
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:17:12
|
||||
--> $DIR/redundant_pattern_matching_option.rs:21:12
|
||||
|
|
||||
LL | if let Some(_) = Some(42) {}
|
||||
| -------^^^^^^^----------- help: try: `if Some(42).is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:19:12
|
||||
--> $DIR/redundant_pattern_matching_option.rs:23:12
|
||||
|
|
||||
LL | if let Some(_) = Some(42) {
|
||||
| -------^^^^^^^----------- help: try: `if Some(42).is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:25:15
|
||||
--> $DIR/redundant_pattern_matching_option.rs:29:15
|
||||
|
|
||||
LL | while let Some(_) = Some(42) {}
|
||||
| ----------^^^^^^^----------- help: try: `while Some(42).is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:27:15
|
||||
--> $DIR/redundant_pattern_matching_option.rs:31:15
|
||||
|
|
||||
LL | while let None = Some(42) {}
|
||||
| ----------^^^^----------- help: try: `while Some(42).is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:29:15
|
||||
--> $DIR/redundant_pattern_matching_option.rs:33:15
|
||||
|
|
||||
LL | while let None = None::<()> {}
|
||||
| ----------^^^^------------- help: try: `while None::<()>.is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:32:15
|
||||
--> $DIR/redundant_pattern_matching_option.rs:36:15
|
||||
|
|
||||
LL | while let Some(_) = v.pop() {
|
||||
| ----------^^^^^^^---------- help: try: `while v.pop().is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:40:5
|
||||
--> $DIR/redundant_pattern_matching_option.rs:44:5
|
||||
|
|
||||
LL | / match Some(42) {
|
||||
LL | | Some(_) => true,
|
||||
|
@ -52,7 +52,7 @@ LL | | };
|
|||
| |_____^ help: try: `Some(42).is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:45:5
|
||||
--> $DIR/redundant_pattern_matching_option.rs:49:5
|
||||
|
|
||||
LL | / match None::<()> {
|
||||
LL | | Some(_) => false,
|
||||
|
@ -61,7 +61,7 @@ LL | | };
|
|||
| |_____^ help: try: `None::<()>.is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:50:13
|
||||
--> $DIR/redundant_pattern_matching_option.rs:54:13
|
||||
|
|
||||
LL | let _ = match None::<()> {
|
||||
| _____________^
|
||||
|
@ -71,55 +71,55 @@ LL | | };
|
|||
| |_____^ help: try: `None::<()>.is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:56:20
|
||||
--> $DIR/redundant_pattern_matching_option.rs:60:20
|
||||
|
|
||||
LL | let _ = if let Some(_) = opt { true } else { false };
|
||||
| -------^^^^^^^------ help: try: `if opt.is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:62:20
|
||||
--> $DIR/redundant_pattern_matching_option.rs:66:20
|
||||
|
|
||||
LL | let _ = if let Some(_) = gen_opt() {
|
||||
| -------^^^^^^^------------ help: try: `if gen_opt().is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:64:19
|
||||
--> $DIR/redundant_pattern_matching_option.rs:68:19
|
||||
|
|
||||
LL | } else if let None = gen_opt() {
|
||||
| -------^^^^------------ help: try: `if gen_opt().is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:70:12
|
||||
--> $DIR/redundant_pattern_matching_option.rs:74:12
|
||||
|
|
||||
LL | if let Some(..) = gen_opt() {}
|
||||
| -------^^^^^^^^------------ help: try: `if gen_opt().is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:85:12
|
||||
--> $DIR/redundant_pattern_matching_option.rs:89:12
|
||||
|
|
||||
LL | if let Some(_) = Some(42) {}
|
||||
| -------^^^^^^^----------- help: try: `if Some(42).is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:87:12
|
||||
--> $DIR/redundant_pattern_matching_option.rs:91:12
|
||||
|
|
||||
LL | if let None = None::<()> {}
|
||||
| -------^^^^------------- help: try: `if None::<()>.is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:89:15
|
||||
--> $DIR/redundant_pattern_matching_option.rs:93:15
|
||||
|
|
||||
LL | while let Some(_) = Some(42) {}
|
||||
| ----------^^^^^^^----------- help: try: `while Some(42).is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:91:15
|
||||
--> $DIR/redundant_pattern_matching_option.rs:95:15
|
||||
|
|
||||
LL | while let None = None::<()> {}
|
||||
| ----------^^^^------------- help: try: `while None::<()>.is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:93:5
|
||||
--> $DIR/redundant_pattern_matching_option.rs:97:5
|
||||
|
|
||||
LL | / match Some(42) {
|
||||
LL | | Some(_) => true,
|
||||
|
@ -128,7 +128,7 @@ LL | | };
|
|||
| |_____^ help: try: `Some(42).is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:98:5
|
||||
--> $DIR/redundant_pattern_matching_option.rs:102:5
|
||||
|
|
||||
LL | / match None::<()> {
|
||||
LL | | Some(_) => false,
|
||||
|
@ -137,19 +137,19 @@ LL | | };
|
|||
| |_____^ help: try: `None::<()>.is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:106:12
|
||||
--> $DIR/redundant_pattern_matching_option.rs:110:12
|
||||
|
|
||||
LL | if let None = *(&None::<()>) {}
|
||||
| -------^^^^----------------- help: try: `if (&None::<()>).is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:107:12
|
||||
--> $DIR/redundant_pattern_matching_option.rs:111:12
|
||||
|
|
||||
LL | if let None = *&None::<()> {}
|
||||
| -------^^^^--------------- help: try: `if (&None::<()>).is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:113:5
|
||||
--> $DIR/redundant_pattern_matching_option.rs:117:5
|
||||
|
|
||||
LL | / match x {
|
||||
LL | | Some(_) => true,
|
||||
|
@ -158,7 +158,7 @@ LL | | };
|
|||
| |_____^ help: try: `x.is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:118:5
|
||||
--> $DIR/redundant_pattern_matching_option.rs:122:5
|
||||
|
|
||||
LL | / match x {
|
||||
LL | | None => true,
|
||||
|
@ -167,7 +167,7 @@ LL | | };
|
|||
| |_____^ help: try: `x.is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:123:5
|
||||
--> $DIR/redundant_pattern_matching_option.rs:127:5
|
||||
|
|
||||
LL | / match x {
|
||||
LL | | Some(_) => false,
|
||||
|
@ -176,7 +176,7 @@ LL | | };
|
|||
| |_____^ help: try: `x.is_none()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:128:5
|
||||
--> $DIR/redundant_pattern_matching_option.rs:132:5
|
||||
|
|
||||
LL | / match x {
|
||||
LL | | None => false,
|
||||
|
@ -185,13 +185,13 @@ LL | | };
|
|||
| |_____^ help: try: `x.is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_some()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:143:13
|
||||
--> $DIR/redundant_pattern_matching_option.rs:147:13
|
||||
|
|
||||
LL | let _ = matches!(x, Some(_));
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try: `x.is_some()`
|
||||
|
||||
error: redundant pattern matching, consider using `is_none()`
|
||||
--> $DIR/redundant_pattern_matching_option.rs:145:13
|
||||
--> $DIR/redundant_pattern_matching_option.rs:149:13
|
||||
|
|
||||
LL | let _ = matches!(x, None);
|
||||
| ^^^^^^^^^^^^^^^^^ help: try: `x.is_none()`
|
||||
|
|
Loading…
Reference in a new issue