Open
Description
I tried this code:
struct Struct {
field: i32,
}
// Clearly patterns followed by a `:`
fn test(
_: Struct,
Struct { .. }: Struct,
Struct { field }: Struct,
Struct { field: _ }: Struct,
Struct { field: aaaa }: Struct,
) {
let _: Struct = panic!();
}
macro_rules! test {
// This is allowed for both `let` and function arguments.
// But not allowed for macros...
(let $p:pat : $T:ty = $e:expr) => {}
}
(play)
I expected this code to compile, instead, it fails with the following error:
error: `$p:pat` is followed by `:`, which is not allowed for `pat` fragments
--> src/main.rs:20:17
|
20 | (let $p:pat : $T:ty = $e:expr) => {}
| ^ not allowed after `pat` fragments
|
= note: allowed there are: `=>`, `,`, `=`, `|`, `if` or `in`
It's very weird that the language uses patterns followed by a :
, but macros-by-example (aka macro_rules!
, declarative macros, etc) can't parse it.
Meta
rustc --version --verbose
:
rustc 1.56.0-nightly (2827db2b1 2021-08-01)
binary: rustc
commit-hash: 2827db2b137e899242e81f1beea39ae26e245153
commit-date: 2021-08-01
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1