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

Macros with path fragments fail to expand if the path has a non-turbofish generic #5357

Closed
mrobakowski opened this issue May 12, 2020 · 0 comments · Fixed by #5359
Closed
Labels
bug subsystem::macros Issues related to macros

Comments

@mrobakowski
Copy link
Contributor

Environment

  • IntelliJ Rust plugin version: 0.2.121.3059-201-stable
  • Rust toolchain version: 1.45.0-nightly
  • IDE name and version: CLion 2020.1
  • Operating system: NixOS 20.03

Problem description

When you have a macro_rules! macro with a path fragment $x:path, the macro fails to expand if you pass a path containing a non-turbofish generic (i.e. Foo<T> instead of Foo::<T>) to it. I only checked with the experimental macro expander. I do not know how the classic one behaves.

It seems like the macro expander uses an incorrect grammar for the path fragments. According to the rust reference the :: before generic args should be optional.

Steps to reproduce

Minimal-ish example:

trait Foo<T> {}

macro_rules! foo {
    ($p:path) => {
        struct Bar<P: $p> {
            inner: P,
        }
    };
}

foo!(u32); // able to expand
foo!(Foo::<u32>); // able to expand
foo!(Foo<u32>); // ERROR: Failed to expand the macro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug subsystem::macros Issues related to macros
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants