File tree Expand file tree Collapse file tree 2 files changed +30
-32
lines changed Expand file tree Collapse file tree 2 files changed +30
-32
lines changed Original file line number Diff line number Diff line change 1- use clippy_utils:: diagnostics:: { span_lint_and_sugg, span_lint_and_then } ;
1+ use clippy_utils:: diagnostics:: span_lint_and_sugg;
22use clippy_utils:: source:: { HasSession , snippet_with_applicability} ;
33use clippy_utils:: { eq_expr_value, span_contains_comment} ;
44use 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)
Original file line number Diff line number Diff line change @@ -12,9 +12,9 @@ LL | | }
1212help: remove the condition
1313 |
1414LL ~
15- LL |
16- LL | return;
17- LL ~
15+ LL +
16+ LL + return;
17+ LL +
1818 |
1919
2020error: condition duplicates match guard
@@ -29,9 +29,9 @@ LL | | }
2929help: remove the condition
3030 |
3131LL ~
32- LL |
33- LL | return;
34- LL ~
32+ LL +
33+ LL + return;
34+ LL +
3535 |
3636
3737error: condition duplicates match guard
@@ -46,9 +46,9 @@ LL | | }
4646help: remove the condition
4747 |
4848LL ~
49- LL |
50- LL | return;
51- LL ~
49+ LL +
50+ LL + return;
51+ LL +
5252 |
5353
5454error: condition duplicates match guard
@@ -63,9 +63,9 @@ LL | | }
6363help: remove the condition
6464 |
6565LL ~
66- LL |
67- LL | return;
68- LL ~
66+ LL +
67+ LL + return;
68+ LL +
6969 |
7070
7171error: condition duplicates match guard
@@ -81,10 +81,10 @@ LL | | */}
8181help: remove the condition
8282 |
8383LL ~
84- LL | /*before*/
85- LL | return;
86- LL | /* after
87- LL ~ */
84+ LL + /*before*/
85+ LL + return;
86+ LL + /* after
87+ LL + */
8888 |
8989
9090error: condition duplicates match guard
You can’t perform that action at this time.
0 commit comments