For the code:
macro_rules! foo {
($something:expr invalid) => {{
// ...
}};
}
macro_rules! bar {
($something:stmt invalid) => {{
// ...
}};
}
fn main() {
foo!(true invalid);
bar!(true invalid);
}
The compiler would give the following errors for this
error: `$something:expr` is followed by `invalid`, which is not allowed for `expr` fragments
--> <anon>:2:22
2 |> ($something:expr invalid) => {{
|> ^^^^^^^
error: `$something:stmt` is followed by `invalid`, which is not allowed for `stmt` fragments
--> <anon>:8:22
8 |> ($something:stmt invalid) => {{
|>
I think it would be better if the error clarified that expr/stmt in macros can may only be followed by one of: => , ;
I'm working on cleaning up the follow set checker to make this easier.
cc @LeoTestard
@durka Did that cleanup ever happen? The errors are still the same today.
Um... I have no idea what I was planning to do.
What should be done (IMO) is to refactor is_in_follow() so that instead of a match, it uses a map from &str to some kind of FollowSet type which is a list of tokens/idents and also has a Display impl, so then the error can do:
format!("{} cannot be followed by {} -- the follow set is {}",
frag_spec, actual_token, follow_sets[frag_spec])
Issue triage: Issue still present, and still very annoying. This should probably be labeled Easy and Compliler-Errors.
Most helpful comment
Issue triage: Issue still present, and still very annoying. This should probably be labeled
EasyandCompliler-Errors.