about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Hansch <dev@phansch.net>2019-08-07 20:34:23 +0200
committerPhilipp Hansch <dev@phansch.net>2019-08-21 07:29:44 +0200
commit0d85d7e60f393563d717d86fbef05f7309923a08 (patch)
tree5d6a39f7e7552821cb1d5cb79111c83f545afadc
parent460e2659f1365fd987c2aad3433855ef24f1b700 (diff)
downloadrust-0d85d7e60f393563d717d86fbef05f7309923a08.tar.gz
rust-0d85d7e60f393563d717d86fbef05f7309923a08.zip
Fix suggestions for redundant_pattern_matching
Fixes the problem displayed in https://github.com/rust-lang/rust-clippy/issues/4344#issuecomment-519206388.

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.
-rw-r--r--clippy_lints/src/redundant_pattern_matching.rs6
-rw-r--r--tests/ui/redundant_pattern_matching.stderr8
2 files changed, 7 insertions, 7 deletions
diff --git a/clippy_lints/src/redundant_pattern_matching.rs b/clippy_lints/src/redundant_pattern_matching.rs
index ce33ebf87ba..68862f838cb 100644
--- a/clippy_lints/src/redundant_pattern_matching.rs
+++ b/clippy_lints/src/redundant_pattern_matching.rs
@@ -90,8 +90,8 @@ fn find_sugg_for_if_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr,
                 db.span_suggestion(
                     span,
                     "try this",
-                    format!("if {}.{}", snippet(cx, op.span, "_"), good_method),
-                    Applicability::MachineApplicable, // snippet
+                    format!("{}.{}", snippet(cx, op.span, "_"), good_method),
+                    Applicability::MaybeIncorrect, // snippet
                 );
             },
         );
@@ -154,7 +154,7 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, o
                         span,
                         "try this",
                         format!("{}.{}", snippet(cx, op.span, "_"), good_method),
-                        Applicability::MachineApplicable, // snippet
+                        Applicability::MaybeIncorrect, // snippet
                     );
                 },
             );
diff --git a/tests/ui/redundant_pattern_matching.stderr b/tests/ui/redundant_pattern_matching.stderr
index baed95d6f2e..a904c5ceb9d 100644
--- a/tests/ui/redundant_pattern_matching.stderr
+++ b/tests/ui/redundant_pattern_matching.stderr
@@ -2,7 +2,7 @@ error: redundant pattern matching, consider using `is_ok()`
   --> $DIR/redundant_pattern_matching.rs:5:12
    |
 LL |     if let Ok(_) = Ok::<i32, i32>(42) {}
-   |     -------^^^^^------------------------ help: try this: `if Ok::<i32, i32>(42).is_ok()`
+   |     -------^^^^^------------------------ help: try this: `Ok::<i32, i32>(42).is_ok()`
    |
    = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
 
@@ -10,19 +10,19 @@ error: redundant pattern matching, consider using `is_err()`
   --> $DIR/redundant_pattern_matching.rs:7:12
    |
 LL |     if let Err(_) = Err::<i32, i32>(42) {}
-   |     -------^^^^^^------------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
+   |     -------^^^^^^------------------------- help: try this: `Err::<i32, i32>(42).is_err()`
 
 error: redundant pattern matching, consider using `is_none()`
   --> $DIR/redundant_pattern_matching.rs:9:12
    |
 LL |     if let None = None::<()> {}
-   |     -------^^^^---------------- help: try this: `if None::<()>.is_none()`
+   |     -------^^^^---------------- help: try this: `None::<()>.is_none()`
 
 error: redundant pattern matching, consider using `is_some()`
   --> $DIR/redundant_pattern_matching.rs:11:12
    |
 LL |     if let Some(_) = Some(42) {}
-   |     -------^^^^^^^-------------- help: try this: `if Some(42).is_some()`
+   |     -------^^^^^^^-------------- help: try this: `Some(42).is_some()`
 
 error: redundant pattern matching, consider using `is_ok()`
   --> $DIR/redundant_pattern_matching.rs:25:5