Skip to content

Commit 6bc53b7

Browse files
committed
dedent the suggestion
1 parent 4047ad9 commit 6bc53b7

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

clippy_lints/src/duplicate_match_guards.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::source::{HasSession, snippet_with_applicability};
2+
use clippy_utils::source::{HasSession, indent_of, reindent_multiline, snippet_with_applicability};
33
use clippy_utils::{eq_expr_value, span_contains_comment};
44
use rustc_errors::Applicability;
55
use rustc_hir::{Arm, ExprKind};
@@ -121,13 +121,33 @@ impl<'tcx> LateLintPass<'tcx> for DuplicateMatchGuards {
121121

122122
let sugg = snippet_with_applicability(cx, sugg_span, "..", &mut applicability);
123123

124+
// we want to bring `then_without_curlies` to the level of indentation that
125+
// `arm_body_expr` used to be at
126+
//
127+
// <pat> if <guard> => {
128+
// if <cond> {
129+
// then
130+
// without
131+
// curlies
132+
// }
133+
// }
134+
//
135+
// <pat> if <guard> => {
136+
// then
137+
// without
138+
// curlies
139+
// }
140+
//
141+
let indent = indent_of(cx, arm_body_expr.span);
142+
let sugg = reindent_multiline(&sugg, false, indent);
143+
124144
span_lint_and_sugg(
125145
cx,
126146
DUPLICATE_MATCH_GUARDS,
127147
arm_body_expr.span,
128148
"condition duplicates match guard",
129149
"remove the condition",
130-
sugg.to_string(),
150+
sugg,
131151
applicability,
132152
);
133153
}

0 commit comments

Comments
 (0)