rust-lang / rust-lang/rfcs

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

Open
#672 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

T-lang
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

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

For earlier discussion, see https://github.com/rust-lang/rust/issues/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 https://github.com/mozilla/rust/pull/11905 more natural.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the issue examples and the earlier discussion in #11928, then review the linked syntax-extension and RFC context. The work is done when the proposed macro non-terminal behavior is specified clearly enough to support the shown block examples and can proceed through the RFC process.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.