When creating an identifier in a declarative macro, it is mandatory to put additional brackets in the macro (double brackets). I was wondering why the compiler does not just (always) add the additional brackets.
Example 1: this code will not compile because only single brackets are used where double brackets are mandatory:
macro_rules! some_macro {
() => {
let mut x = 1;
x += 1;
x
};
}
fn main() {
let y = some_macro!();
}
Adding double brackets solves the compile error.
Example 2: this code will compile regardless of using single or double brackets:
macro_rules! some_macro {
() => {{
1
}};
}
fn main() {
let y = some_macro!();
}
Are there cases in which a macro with double brackets breaks single brackets macros? If not, why doesn't the compiler always adds double brackets?