Skip to content

Commit 0d85d7e

Browse files
committed
Fix suggestions for redundant_pattern_matching
Fixes the problem displayed in rust-lang/rust-clippy#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.
1 parent 460e265 commit 0d85d7e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

clippy_lints/src/redundant_pattern_matching.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ fn find_sugg_for_if_let<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr,
9090
db.span_suggestion(
9191
span,
9292
"try this",
93-
format!("if {}.{}", snippet(cx, op.span, "_"), good_method),
94-
Applicability::MachineApplicable, // snippet
93+
format!("{}.{}", snippet(cx, op.span, "_"), good_method),
94+
Applicability::MaybeIncorrect, // snippet
9595
);
9696
},
9797
);
@@ -154,7 +154,7 @@ fn find_sugg_for_match<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, o
154154
span,
155155
"try this",
156156
format!("{}.{}", snippet(cx, op.span, "_"), good_method),
157-
Applicability::MachineApplicable, // snippet
157+
Applicability::MaybeIncorrect, // snippet
158158
);
159159
},
160160
);

tests/ui/redundant_pattern_matching.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ error: redundant pattern matching, consider using `is_ok()`
22
--> $DIR/redundant_pattern_matching.rs:5:12
33
|
44
LL | if let Ok(_) = Ok::<i32, i32>(42) {}
5-
| -------^^^^^------------------------ help: try this: `if Ok::<i32, i32>(42).is_ok()`
5+
| -------^^^^^------------------------ help: try this: `Ok::<i32, i32>(42).is_ok()`
66
|
77
= note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
88

99
error: redundant pattern matching, consider using `is_err()`
1010
--> $DIR/redundant_pattern_matching.rs:7:12
1111
|
1212
LL | if let Err(_) = Err::<i32, i32>(42) {}
13-
| -------^^^^^^------------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
13+
| -------^^^^^^------------------------- help: try this: `Err::<i32, i32>(42).is_err()`
1414

1515
error: redundant pattern matching, consider using `is_none()`
1616
--> $DIR/redundant_pattern_matching.rs:9:12
1717
|
1818
LL | if let None = None::<()> {}
19-
| -------^^^^---------------- help: try this: `if None::<()>.is_none()`
19+
| -------^^^^---------------- help: try this: `None::<()>.is_none()`
2020

2121
error: redundant pattern matching, consider using `is_some()`
2222
--> $DIR/redundant_pattern_matching.rs:11:12
2323
|
2424
LL | if let Some(_) = Some(42) {}
25-
| -------^^^^^^^-------------- help: try this: `if Some(42).is_some()`
25+
| -------^^^^^^^-------------- help: try this: `Some(42).is_some()`
2626

2727
error: redundant pattern matching, consider using `is_ok()`
2828
--> $DIR/redundant_pattern_matching.rs:25:5

0 commit comments

Comments
 (0)