Why macro ignore double slash

run

macro_rules! demo {
    ($($tok:tt)*) => {
        stringify!($($tok)*)
    };
}

fn main() {
    println!("{}", demo!{ 
    hi
    // hello 
    });
}

i just notice this in python inline macro.so i am interested in why

1 Like

(FIFY)

The compiler discards the comments in the code before doing anything else. Technically, the lexer discards them before sending the tokens to the parser, so there's no chance of capturing comments, even in a macro.

It's not true of doc comments, though. Try "///" instead of "//" and you'll see (playground).

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.