DanielKeep / tlborm

The Little Book of Rust Macros
880 stars 96 forks source link

Wrong output in 'Captures and Expansion Redux' chapter #42

Open padix-key opened 4 years ago

padix-key commented 4 years ago

The Captures and Expansion Redux chapter states that the following Rust code

macro_rules! capture_expr_then_stringify {
    ($e:expr) => {
        stringify!($e)
    };
}

fn main() {
    println!("{:?}", stringify!(dummy(2 * (1 + (3)))));
    println!("{:?}", capture_expr_then_stringify!(dummy(2 * (1 + (3)))));
}

produces the following output:

"dummy ( 2 * ( 1 + ( 3 ) ) )"
"dummy(2 * (1 + (3)))"

But executing the code on Rust Playground gives me:

"dummy (2 * (1 + (3)))"
"dummy(2 * (1 + (3)))"
bjorn3 commented 4 years ago

Rustc probably changed how it pretty prints since the code was written. Both results are fine, as they parse to the same expression.