Skip to content

Commit 3d16c22

Browse files
Be more hygenic with spans
1 parent 52c9906 commit 3d16c22

File tree

5 files changed

+181
-266
lines changed

5 files changed

+181
-266
lines changed

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -821,16 +821,17 @@ fn non_exhaustive_match<'p, 'tcx>(
821821
));
822822
}
823823
[only] => {
824-
let pre_indentation = if let (Some(snippet), true) = (
825-
sm.indentation_before(only.span),
826-
sm.is_multiline(sp.shrink_to_hi().with_hi(only.span.lo())),
827-
) {
828-
format!("\n{}", snippet)
824+
let (pre_indentation, is_multiline) = if let Some(snippet) = sm.indentation_before(only.span)
825+
&& let Ok(with_trailing) = sm.span_extend_while(only.span, |c| c.is_whitespace() || c == ',')
826+
&& sm.is_multiline(with_trailing)
827+
{
828+
(format!("\n{}", snippet), true)
829829
} else {
830-
" ".to_string()
830+
(" ".to_string(), false)
831831
};
832832
let comma = if matches!(only.body.kind, hir::ExprKind::Block(..))
833833
&& only.span.eq_ctxt(only.body.span)
834+
&& is_multiline
834835
{
835836
""
836837
} else {

0 commit comments

Comments
 (0)