1
Fork 0

Only omit trailing comma if block doesn't come from macro expansion

This commit is contained in:
Michael Goulet 2022-06-19 16:27:26 -07:00
parent 2b646bd533
commit 2c3bb42ebd
4 changed files with 50 additions and 4 deletions

View file

@ -829,7 +829,13 @@ fn non_exhaustive_match<'p, 'tcx>(
} else {
" ".to_string()
};
let comma = if matches!(only.body.kind, hir::ExprKind::Block(..)) { "" } else { "," };
let comma = if matches!(only.body.kind, hir::ExprKind::Block(..))
&& only.span.ctxt() == only.body.span.ctxt()
{
""
} else {
","
};
suggestion = Some((
only.span.shrink_to_hi(),
format!("{}{}{} => todo!()", comma, pre_indentation, pattern),
@ -837,8 +843,13 @@ fn non_exhaustive_match<'p, 'tcx>(
}
[.., prev, last] if prev.span.ctxt() == last.span.ctxt() => {
if let Ok(snippet) = sm.span_to_snippet(prev.span.between(last.span)) {
let comma =
if matches!(last.body.kind, hir::ExprKind::Block(..)) { "" } else { "," };
let comma = if matches!(last.body.kind, hir::ExprKind::Block(..))
&& last.span.ctxt() == last.body.span.ctxt()
{
""
} else {
","
};
suggestion = Some((
last.span.shrink_to_hi(),
format!(