fix
This commit is contained in:
parent
f7e2cb4470
commit
459821b191
@ -66,7 +66,9 @@ fn check_all_arms(cx: &LateContext<'_>, match_expr: &Expr<'_>, arms: &[Arm<'_>])
|
||||
for arm in arms {
|
||||
let arm_expr = peel_blocks_with_stmt(arm.body);
|
||||
if let PatKind::Wild = arm.pat.kind {
|
||||
return eq_expr_value(cx, match_expr, strip_return(arm_expr));
|
||||
if !eq_expr_value(cx, match_expr, strip_return(arm_expr)) {
|
||||
return false;
|
||||
}
|
||||
} else if !pat_same_as_expr(arm.pat, arm_expr) {
|
||||
return false;
|
||||
}
|
||||
|
@ -207,4 +207,30 @@ impl Tr for Result<i32, i32> {
|
||||
}
|
||||
}
|
||||
|
||||
mod issue9084 {
|
||||
fn wildcard_if() {
|
||||
let some_bool = true;
|
||||
let e = Some(1);
|
||||
|
||||
// should lint
|
||||
let _ = e;
|
||||
|
||||
// should lint
|
||||
let _ = e;
|
||||
|
||||
// should not lint
|
||||
let _ = match e {
|
||||
_ if some_bool => e,
|
||||
_ => Some(2),
|
||||
};
|
||||
|
||||
// should not lint
|
||||
let _ = match e {
|
||||
Some(i) => Some(i + 1),
|
||||
_ if some_bool => e,
|
||||
_ => e,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -244,4 +244,37 @@ impl Tr for Result<i32, i32> {
|
||||
}
|
||||
}
|
||||
|
||||
mod issue9084 {
|
||||
fn wildcard_if() {
|
||||
let some_bool = true;
|
||||
let e = Some(1);
|
||||
|
||||
// should lint
|
||||
let _ = match e {
|
||||
_ if some_bool => e,
|
||||
_ => e,
|
||||
};
|
||||
|
||||
// should lint
|
||||
let _ = match e {
|
||||
Some(i) => Some(i),
|
||||
_ if some_bool => e,
|
||||
_ => e,
|
||||
};
|
||||
|
||||
// should not lint
|
||||
let _ = match e {
|
||||
_ if some_bool => e,
|
||||
_ => Some(2),
|
||||
};
|
||||
|
||||
// should not lint
|
||||
let _ = match e {
|
||||
Some(i) => Some(i + 1),
|
||||
_ if some_bool => e,
|
||||
_ => e,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -109,5 +109,26 @@ LL | | Complex::D(E::VariantB(ea, eb), b) => Complex::D(E::VariantB(
|
||||
LL | | };
|
||||
| |_________^ help: replace it with: `ce`
|
||||
|
||||
error: aborting due to 11 previous errors
|
||||
error: this match expression is unnecessary
|
||||
--> $DIR/needless_match.rs:252:17
|
||||
|
|
||||
LL | let _ = match e {
|
||||
| _________________^
|
||||
LL | | _ if some_bool => e,
|
||||
LL | | _ => e,
|
||||
LL | | };
|
||||
| |_________^ help: replace it with: `e`
|
||||
|
||||
error: this match expression is unnecessary
|
||||
--> $DIR/needless_match.rs:258:17
|
||||
|
|
||||
LL | let _ = match e {
|
||||
| _________________^
|
||||
LL | | Some(i) => Some(i),
|
||||
LL | | _ if some_bool => e,
|
||||
LL | | _ => e,
|
||||
LL | | };
|
||||
| |_________^ help: replace it with: `e`
|
||||
|
||||
error: aborting due to 13 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user