Skip to content

Commit 33f92c6

Browse files
committed
add a sanity check about the block starting and ending with curlies
1 parent 630833e commit 33f92c6

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

clippy_lints/src/duplicate_match_guards.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::source::{HasSession, indent_of, reindent_multiline, snippet_with_applicability, trim_span};
2+
use clippy_utils::source::{
3+
HasSession, SpanRangeExt, indent_of, reindent_multiline, snippet_with_applicability, trim_span,
4+
};
35
use clippy_utils::{eq_expr_value, span_contains_comment};
46
use rustc_errors::Applicability;
57
use rustc_hir::{Arm, ExprKind};
@@ -103,6 +105,16 @@ impl<'tcx> LateLintPass<'tcx> for DuplicateMatchGuards {
103105
// ```
104106
//
105107
// the arm body already has curlies, so we can remove the ones around `then`
108+
109+
if !then
110+
.span
111+
.check_source_text(cx, |s| s.starts_with('{') && s.ends_with('}'))
112+
{
113+
// despite being a block, `then` somehow does not start and end with curlies
114+
// weird, but okay
115+
return;
116+
}
117+
106118
then.span
107119
.with_lo(then.span.lo() + BytePos(1))
108120
.with_hi(then.span.hi() - BytePos(1))

0 commit comments

Comments
 (0)