Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upNo macro hygiene for items #19700
Comments
This comment has been minimized.
This comment has been minimized.
|
Actually, identifiers are protected by hygiene (and will not capture any scope unless the identifier is passed down), but function identifiers aren't. Macros only deal with token trees -- I'm not sure how to manipulate tts to generically refer to a function defined in another crate that may or may not have a different name. |
This comment has been minimized.
This comment has been minimized.
|
Only let-bound identifiers are safe. Functions, imports, and statics all have this same issue. The following still fails, though not because of functions: #![feature(macro_rules)]
static BLAHBLAH: bool = true;
macro_rules! bar(
() => ({
BLAHBLAH
})
)
#[cfg(test)]
mod test {
static BLAHBLAH: bool = false;
#[test]
fn test() {
assert!(bar!());
}
} |
kmcallister
added
the
A-macros
label
Jan 17, 2015
kmcallister
changed the title
Macros are Not Lexical
No macro hygiene for items
Jan 17, 2015
This comment has been minimized.
This comment has been minimized.
|
This is unfortunate, but it's the documented behavior of See #22462 for a specific manifestation of this problem that I think we can mitigate in time. |
kmcallister
closed this
Mar 3, 2015
This comment has been minimized.
This comment has been minimized.
|
I don't understand why this issue is closed. You're acknowledging it as something that should be fixed so shouldn't it be left open? |
This comment has been minimized.
This comment has been minimized.
|
This aspect of We will at some point introduce a new macro system, first in Rust nightlies, then in some stable Rust 1.x. This would happen through the RFC process. It would coexist with the current Until there's a full RFC, we can discuss this further on rust-lang/rfcs#440. |
maxsnew commentedDec 10, 2014
Uses of identifiers in a macro expansion refer to identifiers in the macro use-site and not the macro-definition site, effectively giving macros dynamic scope.
Minimal example:
Testing this program will result in a test failure because when
bar!()expands tofoo()thefoois thefooin the test submodule, whereas it should refer to thefooin the top-level module wherebar!was defined.This paper is a good resource for implementing this: http://www.cs.utah.edu/plt/publications/macromod.pdf