Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify that expr/stmt in macros can may only be followed by one of: => , ; #34069

Closed
dashed opened this issue Jun 4, 2016 · 6 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug.

Comments

@dashed
Copy link

dashed commented Jun 4, 2016

For the code:

macro_rules! foo {
    ($something:expr invalid) => {{
        // ...
    }};
}

macro_rules! bar {
    ($something:stmt invalid) => {{
        // ...
    }};
}

fn main() {
    foo!(true invalid);
    bar!(true invalid);
}

https://is.gd/TFIoq1

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: => , ;

@durka
Copy link
Contributor

durka commented Jun 4, 2016

I'm working on cleaning up the follow set checker to make this easier.

@pnkfelix
Copy link
Member

pnkfelix commented Jun 6, 2016

cc @LeoTestard

@pnkfelix pnkfelix added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Jun 6, 2016
@Mark-Simulacrum
Copy link
Member

@durka Did that cleanup ever happen? The errors are still the same today.

@durka
Copy link
Contributor

durka commented May 4, 2017

Um... I have no idea what I was planning to do.

@durka
Copy link
Contributor

durka commented May 4, 2017

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])

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 25, 2017
@Phlosioneer
Copy link
Contributor

Issue triage: Issue still present, and still very annoying. This should probably be labeled Easy and Compliler-Errors.

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 24, 2018
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 25, 2018
kennytm added a commit to kennytm/rust that referenced this issue Oct 26, 2018
kennytm added a commit to kennytm/rust that referenced this issue Oct 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

6 participants