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

Why I can not attempted to repeat an expression #48037

Closed
3442853561 opened this issue Feb 6, 2018 · 1 comment
Closed

Why I can not attempted to repeat an expression #48037

3442853561 opened this issue Feb 6, 2018 · 1 comment

Comments

@3442853561
Copy link
Contributor

3442853561 commented Feb 6, 2018

This can run:

macro_rules! foo {
    ($name: ident) => {
        macro_rules! $name {
            ($x: tt) => {
                println!($x);
            }
        }
    }
}

fn main() {
    foo!(bar);
    bar!("test");
}

However, this can not:

macro_rules! foo {
    ($name: ident) => {
        macro_rules! $name {
            ($($x: tt),*) => {
                println!($($x),*);
            }
        }
    }
}

fn main() {
    foo!(bar);
    bar!("test");
}
@TimNN
Copy link
Contributor

TimNN commented Feb 6, 2018

This is a known limitation of macro_rules!: The macro parse thinks that the pattern in $name is a replacement in foo, in which case the error message would be correct.

Closing as a duplicate of #35853.

@TimNN TimNN closed this as completed Feb 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants