Skip to content

cannot define a capturing macro in an expr passed to println! #31946

Closed
@durka

Description

@durka

This code

macro_rules! passthru {
    ($($t:tt)*) => { format_args!("{}", $($t)*) }
}

fn main() {
    passthru!({
        macro_rules! foo {
            ($name:expr) => { concat!("hello ", $name) }
        }
        foo!("rust")
    });
}

fails with a nonsense "unknown macro variable name". It works if the macro has no captures or if it's defined outside. And you can normally define a macro in an expression.

Somehow related to the format_args! expansion, but it doesn't occur without the intermediate passthru! macro (which represents println!, print!, or format!). And I can't see the expansion because it doesn't get that far.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions