Open
Description
Let's consider the following code:
macro_rules! two_times {
($e:expr) => {
2 * $e
};
}
fn main() {
let a = two_times!(1 + 1);
assert_eq!(a, 4);
}
Let's break down its expansion according to the current Ferrocene specs:
$e
matches the expression1 + 1
(20.4.1.2:6),- When transcribing,
$e
is replaced with1 + 1
(20.4.2:3), - The final expansion is
2 * 1 + 1
.
Well, that's not what currently happens (playground link). rustc -Zunpretty=expanded
even adds parenthesis around the 1 + 1
.
My understanding as that expr
metavariables that match an arithmetic expression should have a higher precedence than the rest of the macro substitution. As far as I can tell, this is not mentioned in Ferrocene.
Side note: I don't have much experience in how Ferrocene specs are structured, so I may have used the wrong word/missed something important. Sorry for that.
Metadata
Metadata
Assignees
Labels
No labels