[rust-dev] Macros expanding to multiple statements

Ashish Myles marcianx at gmail.com
Sat Jan 11 18:40:26 PST 2014

Rust 0.9 indicates that support for expansion of macros into multiple
statements is now supported, and the following example from the test suite
works for me.

However, I receive an error for the following code


macro_rules! my_print(
    ($a:expr, $b:expr) => (
        println!("{:?}", a);
        println!("{:?}", b);

fn main() {
    let a = 1;
    let b = 2;
    my_print!(a, b);

(Note that the ^~~~~~~ below points at println.)

$ rustc macro_ignores_second_line.rs
macro_ignores_second_line.rs:6:9: 6:16 error: macro expansion ignores token
`println` and any following
macro_ignores_second_line.rs:6         println!("{:?}", b);
error: aborting due to previous error
task 'rustc' failed at 'explicit failure',
task '<main>' failed at 'explicit failure',

What's the right way to do this?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/rust-dev/attachments/20140111/6a355fbf/attachment.html>

More information about the Rust-dev mailing list