diff options
| author | disco07 <koneenok@outlook.fr> | 2023-05-09 20:50:47 +0200 |
|---|---|---|
| committer | disco07 <koneenok@outlook.fr> | 2023-05-09 20:50:47 +0200 |
| commit | 342ce3da05eea9f119ecf367052d681a386b1761 (patch) | |
| tree | 9c87a56e3139a177877f7bd64504966125ec653a | |
| parent | fb6bf1ebf66497386ea4c90a953b7b287ae19706 (diff) | |
| download | rust-342ce3da05eea9f119ecf367052d681a386b1761.tar.gz rust-342ce3da05eea9f119ecf367052d681a386b1761.zip | |
fix reviewer comments
| -rw-r--r-- | clippy_lints/src/matches/match_like_matches.rs | 7 | ||||
| -rw-r--r-- | clippy_lints/src/matches/redundant_pattern_match.rs | 6 | ||||
| -rw-r--r-- | tests/ui/redundant_pattern_matching_option.fixed | 13 | ||||
| -rw-r--r-- | tests/ui/redundant_pattern_matching_option.rs | 25 | ||||
| -rw-r--r-- | tests/ui/redundant_pattern_matching_option.stderr | 48 | ||||
| -rw-r--r-- | tests/ui/redundant_pattern_matching_result.fixed | 7 | ||||
| -rw-r--r-- | tests/ui/redundant_pattern_matching_result.rs | 15 | ||||
| -rw-r--r-- | tests/ui/redundant_pattern_matching_result.stderr | 18 |
8 files changed, 47 insertions, 92 deletions
diff --git a/clippy_lints/src/matches/match_like_matches.rs b/clippy_lints/src/matches/match_like_matches.rs index 438d1437562..0064619ef89 100644 --- a/clippy_lints/src/matches/match_like_matches.rs +++ b/clippy_lints/src/matches/match_like_matches.rs @@ -183,12 +183,9 @@ fn find_bool_lit(ex: &ExprKind<'_>) -> Option<bool> { fn is_some(path_kind: PatKind<'_>) -> bool { match path_kind { - PatKind::TupleStruct(QPath::Resolved(_, path), patterns, _) if is_wild(&patterns[0]) => { + PatKind::TupleStruct(QPath::Resolved(_, path), [first, ..], _) if is_wild(first) => { let name = path.segments[0].ident; - if name.name == rustc_span::sym::Some { - return true; - } - false + name.name == rustc_span::sym::Some }, _ => false, } diff --git a/clippy_lints/src/matches/redundant_pattern_match.rs b/clippy_lints/src/matches/redundant_pattern_match.rs index 28478987821..7a06443f5d9 100644 --- a/clippy_lints/src/matches/redundant_pattern_match.rs +++ b/clippy_lints/src/matches/redundant_pattern_match.rs @@ -188,9 +188,8 @@ 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); - let found_good_method = found_good_method(cx, arms, node_pair); - if let Some(good_method) = found_good_method { + if let Some(good_method) = found_good_method(cx, arms, node_pair) { let span = expr.span.to(op.span); let result_expr = match &op.kind { ExprKind::AddrOf(_, _, borrowed) => borrowed, @@ -310,6 +309,9 @@ fn get_good_method<'a>(cx: &LateContext<'_>, arms: &[Arm<'_>], path_left: &QPath "Ok" => { find_good_method_for_matches_macro(cx, arms, path_left, Item::Lang(ResultOk), "is_ok()", "is_err()") }, + "Err" => { + find_good_method_for_matches_macro(cx, arms, path_left, Item::Lang(ResultErr), "is_err()", "is_ok()") + }, "Some" => find_good_method_for_matches_macro( cx, arms, diff --git a/tests/ui/redundant_pattern_matching_option.fixed b/tests/ui/redundant_pattern_matching_option.fixed index c22a4d7456e..2f907f7ae3d 100644 --- a/tests/ui/redundant_pattern_matching_option.fixed +++ b/tests/ui/redundant_pattern_matching_option.fixed @@ -95,15 +95,12 @@ fn issue10726() { Some(42).is_none(); - Some(42).is_none(); - - Some(42).is_some(); - - None::<()>.is_none(); - - None::<()>.is_none(); + None::<()>.is_some(); None::<()>.is_none(); - None::<()>.is_some(); + match Some(42) { + Some(21) => true, + _ => false, + }; } diff --git a/tests/ui/redundant_pattern_matching_option.rs b/tests/ui/redundant_pattern_matching_option.rs index cd96e0d29a5..5e80a2b384b 100644 --- a/tests/ui/redundant_pattern_matching_option.rs +++ b/tests/ui/redundant_pattern_matching_option.rs @@ -112,28 +112,13 @@ fn issue10726() { }; match Some(42) { - Some(_) => false, - _ => true, - }; - - match Some(42) { None => true, _ => false, }; - match Some(42) { - None => false, - _ => true, - }; - match None::<()> { - Some(_) => false, - _ => true, - }; - - match None::<()> { - Some(_) => false, - _ => true, + Some(_) => true, + _ => false, }; match None::<()> { @@ -141,8 +126,8 @@ fn issue10726() { _ => false, }; - match None::<()> { - None => false, - _ => true, + match Some(42) { + Some(21) => true, + _ => false, }; } diff --git a/tests/ui/redundant_pattern_matching_option.stderr b/tests/ui/redundant_pattern_matching_option.stderr index d397297074b..97de2f1c86f 100644 --- a/tests/ui/redundant_pattern_matching_option.stderr +++ b/tests/ui/redundant_pattern_matching_option.stderr @@ -161,49 +161,22 @@ error: redundant pattern matching, consider using `is_none()` --> $DIR/redundant_pattern_matching_option.rs:114:5 | LL | / match Some(42) { -LL | | Some(_) => false, -LL | | _ => true, -LL | | }; - | |_____^ help: try this: `Some(42).is_none()` - -error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:119:5 - | -LL | / match Some(42) { LL | | None => true, LL | | _ => false, LL | | }; | |_____^ help: try this: `Some(42).is_none()` error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:124:5 - | -LL | / match Some(42) { -LL | | None => false, -LL | | _ => true, -LL | | }; - | |_____^ help: try this: `Some(42).is_some()` - -error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:129:5 - | -LL | / match None::<()> { -LL | | Some(_) => false, -LL | | _ => true, -LL | | }; - | |_____^ help: try this: `None::<()>.is_none()` - -error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:134:5 + --> $DIR/redundant_pattern_matching_option.rs:119:5 | LL | / match None::<()> { -LL | | Some(_) => false, -LL | | _ => true, +LL | | Some(_) => true, +LL | | _ => false, LL | | }; - | |_____^ help: try this: `None::<()>.is_none()` + | |_____^ help: try this: `None::<()>.is_some()` error: redundant pattern matching, consider using `is_none()` - --> $DIR/redundant_pattern_matching_option.rs:139:5 + --> $DIR/redundant_pattern_matching_option.rs:124:5 | LL | / match None::<()> { LL | | None => true, @@ -211,14 +184,5 @@ LL | | _ => false, LL | | }; | |_____^ help: try this: `None::<()>.is_none()` -error: redundant pattern matching, consider using `is_some()` - --> $DIR/redundant_pattern_matching_option.rs:144:5 - | -LL | / match None::<()> { -LL | | None => false, -LL | | _ => true, -LL | | }; - | |_____^ help: try this: `None::<()>.is_some()` - -error: aborting due to 30 previous errors +error: aborting due to 26 previous errors diff --git a/tests/ui/redundant_pattern_matching_result.fixed b/tests/ui/redundant_pattern_matching_result.fixed index a51e14a5b56..a242c38e833 100644 --- a/tests/ui/redundant_pattern_matching_result.fixed +++ b/tests/ui/redundant_pattern_matching_result.fixed @@ -114,7 +114,12 @@ fn issue10726() { Ok::<i32, i32>(42).is_err(); + Err::<i32, i32>(42).is_ok(); + Err::<i32, i32>(42).is_err(); - Err::<i32, i32>(42).is_ok(); + match Ok::<i32, i32>(42) { + Ok(21) => true, + _ => false, + }; } diff --git a/tests/ui/redundant_pattern_matching_result.rs b/tests/ui/redundant_pattern_matching_result.rs index 709e3d526a8..a4b0673ae5b 100644 --- a/tests/ui/redundant_pattern_matching_result.rs +++ b/tests/ui/redundant_pattern_matching_result.rs @@ -134,17 +134,22 @@ fn issue10726() { }; match Ok::<i32, i32>(42) { - Ok(_) => false, - _ => true, + Err(_) => true, + _ => false, }; match Err::<i32, i32>(42) { - Ok(_) => false, - _ => true, + Ok(_) => true, + _ => false, }; match Err::<i32, i32>(42) { - Ok(_) => true, + Err(_) => true, + _ => false, + }; + + match Ok::<i32, i32>(42) { + Ok(21) => true, _ => false, }; } diff --git a/tests/ui/redundant_pattern_matching_result.stderr b/tests/ui/redundant_pattern_matching_result.stderr index 0e8a983bf44..151a7440251 100644 --- a/tests/ui/redundant_pattern_matching_result.stderr +++ b/tests/ui/redundant_pattern_matching_result.stderr @@ -163,28 +163,28 @@ error: redundant pattern matching, consider using `is_err()` --> $DIR/redundant_pattern_matching_result.rs:136:5 | LL | / match Ok::<i32, i32>(42) { -LL | | Ok(_) => false, -LL | | _ => true, +LL | | Err(_) => true, +LL | | _ => false, LL | | }; | |_____^ help: try this: `Ok::<i32, i32>(42).is_err()` -error: redundant pattern matching, consider using `is_err()` +error: redundant pattern matching, consider using `is_ok()` --> $DIR/redundant_pattern_matching_result.rs:141:5 | LL | / match Err::<i32, i32>(42) { -LL | | Ok(_) => false, -LL | | _ => true, +LL | | Ok(_) => true, +LL | | _ => false, LL | | }; - | |_____^ help: try this: `Err::<i32, i32>(42).is_err()` + | |_____^ help: try this: `Err::<i32, i32>(42).is_ok()` -error: redundant pattern matching, consider using `is_ok()` +error: redundant pattern matching, consider using `is_err()` --> $DIR/redundant_pattern_matching_result.rs:146:5 | LL | / match Err::<i32, i32>(42) { -LL | | Ok(_) => true, +LL | | Err(_) => true, LL | | _ => false, LL | | }; - | |_____^ help: try this: `Err::<i32, i32>(42).is_ok()` + | |_____^ help: try this: `Err::<i32, i32>(42).is_err()` error: aborting due to 26 previous errors |
