mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 00:03:43 +00:00
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.
This commit is contained in:
parent
460e2659f1
commit
0d85d7e60f
@ -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
|
||||
);
|
||||
},
|
||||
);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user