Skip to content

Commit

Permalink
Fix suggestions for redundant_pattern_matching
Browse files Browse the repository at this point in the history
Fixes the problem displayed in rust-lang#4344 (comment).

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.
  • Loading branch information
phansch committed Aug 8, 2019
1 parent ea26a95 commit 42204b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions clippy_lints/src/redundant_pattern_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
},
);
Expand Down Expand Up @@ -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
);
},
);
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/redundant_pattern_matching.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ 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`

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
Expand Down

0 comments on commit 42204b6

Please sign in to comment.