Skip to content

Commit 0da4285

Browse files
committed
add a sanity check about the block starting and ending with curlies
1 parent ddf3d64 commit 0da4285

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

clippy_lints/src/duplicate_match_guards.rs

Lines changed: 10 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,13 @@ 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.span.check_source_text(cx, |s| s.starts_with('{') && s.ends_with('}')) {
110+
// despite being a block, `then` somehow does not start and end with curlies
111+
// weird, but okay
112+
return;
113+
}
114+
106115
then.span
107116
.with_lo(then.span.lo() + BytePos(1))
108117
.with_hi(then.span.hi() - BytePos(1))

0 commit comments

Comments
 (0)