Skip to content

Commit 28081e6

Browse files
committed
simplify back to single-part suggestion
previously, we suggested removing: - everything from the start of `arm_body_expr` to the start of `then` - and everything from the end of `then` to the end of `arm_body_expr` but that should be the same as just replacing `arm_body_expr` with `then` we seem to get some more lines with trailing spaces, but that's probably not that big of a deal...
1 parent fa9a862 commit 28081e6

File tree

2 files changed

+30
-32
lines changed

2 files changed

+30
-32
lines changed

clippy_lints/src/duplicate_match_guards.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
1+
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::{HasSession, snippet_with_applicability};
33
use clippy_utils::{eq_expr_value, span_contains_comment};
44
use rustc_errors::Applicability;
@@ -111,25 +111,23 @@ impl<'tcx> LateLintPass<'tcx> for DuplicateMatchGuards {
111111
return;
112112
}
113113

114-
span_lint_and_then(
114+
let sugg = snippet_with_applicability(
115+
cx,
116+
then.span
117+
.with_lo(then.span.lo() + BytePos(1))
118+
.with_hi(then.span.hi() - BytePos(1)),
119+
"..",
120+
&mut applicability,
121+
);
122+
123+
span_lint_and_sugg(
115124
cx,
116125
DUPLICATE_MATCH_GUARDS,
117126
arm_body_expr.span,
118127
"condition duplicates match guard",
119-
|diag| {
120-
diag.multipart_suggestion_verbose(
121-
"remove the condition",
122-
vec![
123-
// <pat> if <guard> => { if <cond> { <then_without_curlies> } }
124-
// ^^^^^^^^^^^
125-
(arm_body_expr.span.with_hi(then.span.lo() + BytePos(1)), String::new()),
126-
// <pat> if <guard> => { if <cond> { <then_without_curlies> } }
127-
// ^^
128-
(arm_body_expr.span.with_lo(then.span.hi() - BytePos(1)), String::new()),
129-
],
130-
applicability,
131-
);
132-
},
128+
"remove the condition",
129+
sugg.to_string(),
130+
applicability,
133131
);
134132
} else {
135133
// the uncommon case (rusfmt would add the braces here automatically)

tests/ui/duplicate_match_guards.stderr

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ LL | | }
1212
help: remove the condition
1313
|
1414
LL ~
15-
LL |
16-
LL | return;
17-
LL ~
15+
LL +
16+
LL + return;
17+
LL +
1818
|
1919

2020
error: condition duplicates match guard
@@ -29,9 +29,9 @@ LL | | }
2929
help: remove the condition
3030
|
3131
LL ~
32-
LL |
33-
LL | return;
34-
LL ~
32+
LL +
33+
LL + return;
34+
LL +
3535
|
3636

3737
error: condition duplicates match guard
@@ -46,9 +46,9 @@ LL | | }
4646
help: remove the condition
4747
|
4848
LL ~
49-
LL |
50-
LL | return;
51-
LL ~
49+
LL +
50+
LL + return;
51+
LL +
5252
|
5353

5454
error: condition duplicates match guard
@@ -63,9 +63,9 @@ LL | | }
6363
help: remove the condition
6464
|
6565
LL ~
66-
LL |
67-
LL | return;
68-
LL ~
66+
LL +
67+
LL + return;
68+
LL +
6969
|
7070

7171
error: condition duplicates match guard
@@ -81,10 +81,10 @@ LL | | */}
8181
help: remove the condition
8282
|
8383
LL ~
84-
LL | /*before*/
85-
LL | return;
86-
LL | /* after
87-
LL ~ */
84+
LL + /*before*/
85+
LL + return;
86+
LL + /* after
87+
LL + */
8888
|
8989

9090
error: condition duplicates match guard

0 commit comments

Comments
 (0)