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 can fail to resolve an identifier rebinded in local scope. #26223

Closed
Ryman opened this issue Jun 11, 2015 · 3 comments
Closed

Macros can fail to resolve an identifier rebinded in local scope. #26223

Ryman opened this issue Jun 11, 2015 · 3 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@Ryman
Copy link
Contributor

Ryman commented Jun 11, 2015

Unsure of a better title for this, but I don't see why it's invalid to do. It makes adding some additional debug logging inside macros quite tedious. This example is a simple modification of one of the macros defined in the rust book (just above the introduction to recursive macros).

macro_rules! foo {
    ($v:ident) => (
        let $v = 3;
        println!("{}", $v); // If you comment this then it's fine.
    );
}

fn main() {
    foo!(x);
    println!("{}", x);
}

Expected:
print 3 (the value of x) twice

Actual:

<anon>:4:24: 4:26 error: unresolved name `x`
<anon>:4         println!("{}", $v); // If you comment this then it's fine.
                                ^~
note: in expansion of format_args!
<std macros>:2:25: 2:56 note: expansion site
<std macros>:1:1: 2:62 note: in expansion of print!
<std macros>:3:1: 3:54 note: expansion site
<std macros>:1:1: 3:58 note: in expansion of println!
<anon>:4:9: 4:27 note: expansion site
<anon>:1:1: 6:2 note: in expansion of foo!
<anon>:9:5: 9:13 note: expansion site

playpen link
cc @jbclements

@jbclements
Copy link
Contributor

Yes, this looks totally broken to me.

@steveklabnik steveklabnik added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Jun 15, 2015
@jseyfried
Copy link
Contributor

This was fixed in #32923.

@TimNN
Copy link
Contributor

TimNN commented Sep 16, 2016

Closing, since this has been fixed.

@TimNN TimNN closed this as completed Sep 16, 2016
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

No branches or pull requests

5 participants