-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Nested macro invocation doesn't follow proper scoping rules #9323
Comments
cc @jbclements |
Yes, this is definitely a bug. The bar! macro should expand into a use of the outer foo! macro, not the inner one; this otherwise subverts the definition of the bar! macro completely. Put differently, it violates the macro-writer's bill of rights (yes, that's a thing. though I may be mis-using the term). The solution? Hygiene for macro names. One thing at a time... @huonw , thanks for the cc: ! |
@kballard Are you able to confirm if this is still valid with the latest Rust? Your original code block doesn't compile currently. |
@frewsxcv It's still broken. I just updated the original code block with something that compiles. |
I think this example is related: macro_rules! foo {
($v:ident) => (
let $v = 3;
println!("{}", $v); // If you comment this then it's fine.
);
}
fn main() {
foo!(x);
println!("{}", x);
} |
@Ryman No... I think that's a different problem. Can you file a separate issue for that, and send me mail when you're done? (BTW, be sure to include the expected and actual behavior when you do.) |
@jbclements Opened #26223 |
Triage: same error today, in that it prints |
Triage: |
This is expected behavior for Macros 2.0 ( #![feature(decl_macro)]
fn main() {
macro foo{
() => (println!("outer"))
}
{
macro bar{
() => (foo!())
}
{
macro foo{
() => (println!("inner"))
}
bar!()
}
}
} Declarative macros 2.0 are deeply unstable and |
Rustup r? `@ghost` changelog: none
When one macro invokes another macro, it always looks up the nested macro from the point of the outer invocation, instead of from the point of the macro definition. I don't know if this is intentional.
Example:
If these were functions, it would print
outer
, but instead it printsinner
.The text was updated successfully, but these errors were encountered: