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

for bindings in macros can shadow function args #14597

Closed
kmcallister opened this issue Jun 2, 2014 · 1 comment
Closed

for bindings in macros can shadow function args #14597

kmcallister opened this issue Jun 2, 2014 · 1 comment

Comments

@kmcallister
Copy link
Contributor

#![feature(macro_rules)]

macro_rules! print_five_times( ($e:expr) => (
    for i in range(0, 5u) {
        println!("{:u}: {}", i, $e);
    }
))

fn f(i: &'static str) {
    print_five_times!(i);
}

fn main() {
    f("Hello, world!");
}

produces

0: 0
1: 1
2: 2
3: 3
4: 4

Renaming f's argument to x produces the expected

0: Hello, world!
1: Hello, world!
2: Hello, world!
3: Hello, world!
4: Hello, world!

Interestingly, so does

fn f(x: &'static str) {
    let i = x;       
    print_five_times!(i);
}

rustc 0.11.0-pre (81c0223 2014-05-29 16:41:42 -0700)
host: x86_64-unknown-linux-gnu

@alexcrichton
Copy link
Member

Closing as a dupe of either #9383 or #9384

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