Skip to content

Allow expressions to be followed by blocks in macro arguments #30679

@LFalch

Description

@LFalch

Rust macros try to be hygienic, soTo make sure you don't break Rust's syntax, it restricts what you can write after an expression, which means you can't do something like this:

macro_rules! do_if_true{
    ($e:expr $b:block) => {
        if $e $b
        else {
            println!("got false");
        }
    };
}

Since a block always has curly braces, I would expect an expression could be followed by a block but instead, you get this error:

error: `$e:expr` is followed by `$b:block`, which is not allowed for `expr` fragments

I tested this on both stable (rustc 1.5.0 (3d7cd77 2015-12-04)) and nightly (rustc 1.7.0-nightly (2b8e96d 2015-12-21)), but got the same result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions