Closed
Description
Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=b417dca9b7f8cab72fc583d6a97f97de
macro_rules! m {
() => {
{}
};
}
enum Enum { A, B }
fn main() {
match Enum::A {
Enum::A => m!()
}
}
The current output is:
error[E0004]: non-exhaustive patterns: `B` not covered
--> src/main.rs:10:11
|
10 | match Enum::A {
| ^^^^^^^ pattern `B` not covered
|
note: `Enum` defined here
--> src/main.rs:7:16
|
7 | 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
|
11 ~ Enum::A => m!()
12 + B => todo!()
|
Rustc's suggested fix is:
match Enum::A {
Enum::A => m!()
B => todo!()
}
which is not valid syntax:
error: expected one of `,`, `.`, `?`, `}`, or an operator, found `B`
--> src/main.rs:12:9
|
11 | Enum::A => m!()
| -- - expected one of `,`, `.`, `?`, `}`, or an operator
| |
| while parsing the `match` arm starting here
12 | B => todo!()
| ^ unexpected token
The diagnostic appears to be getting misled by the fact that m!()
expands to a braced block, which would not ordinarily require a trailing comma if written inline in the match arm. The diagnostic correctly suggests the comma if the macro expands to something different than a braced block.
macro_rules! m {
() => {
()
};
}
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
11 ~ Enum::A => m!(),
12 + B => todo!()
|