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 producing statements are evaluated out-of-order #154

Open
udoprog opened this issue Oct 12, 2020 · 0 comments
Open

Macros producing statements are evaluated out-of-order #154

udoprog opened this issue Oct 12, 2020 · 0 comments
Labels
bug Something isn't working

Comments

@udoprog
Copy link
Collaborator

udoprog commented Oct 12, 2020

Macros in statement positions might produce expressions or statements. This causes issues if the macro produces an item, because items need to be indexed before macros using them in case they use the item produced.

As an example, println! can use a constant value as the first argument, but this would currently cause issues:

pub fn main() {
    println!(FORMAT, "World");
    declare_format!(); // produces: `const FORMAT = "Hello {}";
}

This could be solved in following ways:

  • Identify with metadata that a macro needs to use constant evaluation, in which case it is not permitted to expand to an item.
  • Not allowing constant evaluation in macros, which would be a shame.
  • Live with the fact that combining const values and macros have an inherent evaluation order.

Related: #153

@udoprog udoprog added the bug Something isn't working label Oct 12, 2020
@udoprog udoprog changed the title Macros producing statements aren't evaluated in order Macros producing statements are evaluated out-of-order Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant