提交 2c3bb42e 编写于 作者: M Michael Goulet

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

上级 2b646bd5
...@@ -829,7 +829,13 @@ fn non_exhaustive_match<'p, 'tcx>( ...@@ -829,7 +829,13 @@ fn non_exhaustive_match<'p, 'tcx>(
} else { } else {
" ".to_string() " ".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(( suggestion = Some((
only.span.shrink_to_hi(), only.span.shrink_to_hi(),
format!("{}{}{} => todo!()", comma, pre_indentation, pattern), format!("{}{}{} => todo!()", comma, pre_indentation, pattern),
...@@ -837,8 +843,13 @@ fn non_exhaustive_match<'p, 'tcx>( ...@@ -837,8 +843,13 @@ fn non_exhaustive_match<'p, 'tcx>(
} }
[.., prev, last] if prev.span.ctxt() == last.span.ctxt() => { [.., prev, last] if prev.span.ctxt() == last.span.ctxt() => {
if let Ok(snippet) = sm.span_to_snippet(prev.span.between(last.span)) { if let Ok(snippet) = sm.span_to_snippet(prev.span.between(last.span)) {
let comma = let comma = if matches!(last.body.kind, hir::ExprKind::Block(..))
if matches!(last.body.kind, hir::ExprKind::Block(..)) { "" } else { "," }; && last.span.ctxt() == last.body.span.ctxt()
{
""
} else {
","
};
suggestion = Some(( suggestion = Some((
last.span.shrink_to_hi(), last.span.shrink_to_hi(),
format!( format!(
......
macro_rules! m {
() => {
{}
};
}
enum Enum { A, B }
fn main() {
match Enum::A {
//~^ ERROR non-exhaustive patterns
Enum::A => m!()
}
}
error[E0004]: non-exhaustive patterns: `B` not covered
--> $DIR/issue-94866.rs:10:11
|
LL | match Enum::A {
| ^^^^^^^ pattern `B` not covered
|
note: `Enum` defined here
--> $DIR/issue-94866.rs:7:16
|
LL | enum Enum { A, B }
| ---- ^ not covered
= note: the matched value is of type `Enum`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
LL ~ Enum::A => m!(),
LL + B => todo!()
|
error: aborting due to previous error
For more information about this error, try `rustc --explain E0004`.
...@@ -12,7 +12,7 @@ LL | struct Foo(isize, isize); ...@@ -12,7 +12,7 @@ LL | struct Foo(isize, isize);
= note: the matched value is of type `Foo` = note: the matched value is of type `Foo`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
| |
LL ~ Foo(2, b) => println!("{}", b) LL ~ Foo(2, b) => println!("{}", b),
LL + Foo(_, _) => todo!() LL + Foo(_, _) => todo!()
| |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册