You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
structStruct{field:i32,}// Clearly patterns followed by a `:`fntest(
_: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) => {}}
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.
The allowed list of tokens after certain fragments is very conservative to avoid making too many promises about the syntax, but they can be extended carefully. It'd require an FCP though.
I know this decision was made deliberately. I can't find where it was (might've been back in the IRC days?), but when I brought it up ages ago, the counter-argument was that we may one day want arg: T to be a pattern, in which case $pat should be expected to match the whole thing.
The way that | patterns have been implemented suggests, however, that perhaps we could still have our cake and eat it too? Basically, if it could be demonstrated that an Edition could be used to smoothly transition from a $pat that matches the pat in pat: Type, to one that matches the whole thing...
I tried this code:
(play)
I expected this code to compile, instead, it fails with the following error:
It's very weird that the language uses patterns followed by a
:
, but macros-by-example (akamacro_rules!
, declarative macros, etc) can't parse it.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: