-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Weirdness with macros trying to redefine each other #45732
Comments
It used to always be possible to macros to "redefine" each other; macro invocations expended "before" the redefine would resolve to the old definition and macros invocation expanded "after" the redefine would resolve to the new definition. However, with macros 2.0 naming / RFC 1560, macro expansion no longer has an "order" -- we now resolve and expand all we can, update the module graph and make progress resolving To be able to make progress coherently resolving names in the fix point algorithm, we wanted to forbid one In the above example, if there is a single invocation of Note that with macros 2.0, it is an error even with just one #![feature(decl_macro)]
pub macro once($mac:ident) {
macro $mac() {}
// If we just put `macro once() {}` here like as in the original example, it wouldn't be usable outside the macro definition due to hygiene and wouldn't be an error.
}
once!(once); // error cc @nrc |
@jseyfried OK sounds like this is fully by design, thanks for the explanation! |
On IRC we were trying to make a macro that turns itself into a no-op after the first call. I think it's not actually possible, but I was confused by the compiler's behavior.
A macro that tries to redefine itself (or another already existing macro) is allowed to do so once, but fails with an error the second time.
The error points to the first invocation. However, there is no error if I remove the second invocation!
Also, why can't I do this? :) The error refers us to RFC 1560 which doesn't talk about macros.
cc @jseyfried
The text was updated successfully, but these errors were encountered: