Skip to content

Commit

Permalink
Be more hygenic with spans
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 19, 2022
1 parent 52c9906 commit 3d16c22
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 266 deletions.
13 changes: 7 additions & 6 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,16 +821,17 @@ fn non_exhaustive_match<'p, 'tcx>(
));
}
[only] => {
let pre_indentation = if let (Some(snippet), true) = (
sm.indentation_before(only.span),
sm.is_multiline(sp.shrink_to_hi().with_hi(only.span.lo())),
) {
format!("\n{}", snippet)
let (pre_indentation, is_multiline) = if let Some(snippet) = sm.indentation_before(only.span)
&& let Ok(with_trailing) = sm.span_extend_while(only.span, |c| c.is_whitespace() || c == ',')
&& sm.is_multiline(with_trailing)
{
(format!("\n{}", snippet), true)
} else {
" ".to_string()
(" ".to_string(), false)
};
let comma = if matches!(only.body.kind, hir::ExprKind::Block(..))
&& only.span.eq_ctxt(only.body.span)
&& is_multiline
{
""
} else {
Expand Down
Loading

0 comments on commit 3d16c22

Please sign in to comment.