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

Add a macro non-terminal for the interior of a block #672

Open
steveklabnik opened this issue Jan 21, 2015 · 0 comments
Open

Add a macro non-terminal for the interior of a block #672

steveklabnik opened this issue Jan 21, 2015 · 0 comments
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.

Comments

@steveklabnik
Copy link
Member

Issue by huonw
Thursday Jan 30, 2014 at 08:25 GMT

For earlier discussion, see rust-lang/rust#11928

This issue was labelled with: A-syntaxext, B-RFC in the Rust repository


e.g. (using the currently-invalid brace syntax from #11892)

macro_rules! spawn {
     ($b: block_internals) => {
        spawn(proc() { $b })
     }
}

spawn! {
     use foo::bar;
     fn baz() {}

     if x == 0 { bar() }
     let a = 1 + 2;
     foo();
     baz()
}

I don't believe this is currently possible to emulate. e.g. with $($s: stmt);* you have to write fn foo() {}; if x == 0 { bar() }; ... and without the ; you end up with foo() bar() being valid (and expr doesn't allow for statements like let and fn bar() {}). The best solution I've found is just writing ($e: expr) => { ... } but this requires double braces:

spawn! { foo() } // ok

spawn! { foo(); bar() } // not ok! :(

spawn! {{ foo(); bar() }} // ok :(

This would make sugary control-flow-y macros like spawn and scope/finally from rust-lang/rust#11905 more natural.

@petrochenkov petrochenkov added the T-lang Relevant to the language team, which will review and decide on the RFC. label Jan 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-lang Relevant to the language team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

2 participants