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

Spurious local ambiguity error after empty $($ident),* #34030

Closed
chris-morgan opened this issue Jun 2, 2016 · 2 comments · Fixed by #42913
Closed

Spurious local ambiguity error after empty $($ident),* #34030

chris-morgan opened this issue Jun 2, 2016 · 2 comments · Fixed by #42913
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@chris-morgan
Copy link
Member

chris-morgan commented Jun 2, 2016

macro_rules! foo {
    ($($t:ident),*/) => {()};
}

fn main() {
    foo!(a, b/);  // works fine
    foo!(a/);     // works fine
    foo!(/);      // local ambiguity error ☹
}
error: local ambiguity: multiple parsing options: built-in NTs ident ('t') or 1 other option.
 --> <anon>:8:10
8 |>     foo!(/);
  |>          ^

In this case, it should be looking for an ident or a /, in which there is no ambiguity.

All channels are affected.

This is affecting my ability to write macros accepting generics using angle brackets, e.g. $ty:ident<$($x:ident),*>, with a supporting pattern to turn Foo into Foo<>.

May be related to #24827.

@durka
Copy link
Contributor

durka commented Jun 2, 2016

In theory there is no ambiguity because an ident can't start with <. As far as I can tell the macro evaluator doesn't reason about this at all. It sure is annoying and I hope it can be fixed. I suppose it introduces a forwards compatibility consideration, just like follow sets: if we let macros distinguish between < and :ident, then < can never be added to the ident grammar.

@chris-morgan
Copy link
Member Author

@durka: the error is spurious; this is definitely a bug. The issue is purely when the repeating group is empty. Hence foo!(a/); working.

@apasel422 apasel422 added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Jun 3, 2016
kennytm added a commit to kennytm/rust that referenced this issue Jul 7, 2017
bors added a commit that referenced this issue Jul 11, 2017
…seyfried

Only match a fragment specifier the if it starts with certain tokens.

When trying to match a fragment specifier, we first predict whether the current token can be matched at all. If it cannot be matched, don't bother to push the Earley item to `bb_eis`. This can fix a lot of issues which otherwise requires full backtracking (#42838).

In this PR the prediction treatment is not done for `:item`, `:stmt` and `:tt`, but it could be expanded in the future.

Fixes #24189.
Fixes #26444.
Fixes #27832.
Fixes #34030.
Fixes #35650.
Fixes #39964.
Fixes the 4th comment in #40569.
Fixes the issue blocking #40984.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants