This repository was archived by the owner on Oct 6, 2024. It is now read-only.
This repository was archived by the owner on Oct 6, 2024. It is now read-only.
Inconsistent expression precedence when using camel #94
Closed
Description
Hey! I have encountered an edge case with a surprising behavior. When using an expression in a macro along with camel and using a unary operator on the expression, the parentheses are eliminated resulting in a faulty short circuit.
Reproducible with:
paste = 1.0.12
rustc = 1.68.0
macro_rules! test {
($($name:ident $pred:expr),*) => {
paste::paste! {
$(
if !$pred {
let camel = [<$name:camel>]::new();
println!("{}", $pred);
}
)*
}
}
}
fn main() {
test!(String false || true);
}
Expanded to the following via cargo expand:
fn main() {
if !false || true {
let camel = String::new();
{
::std::io::_print(format_args!("{0}\n", false || true));
};
}
}
Whereas without using camel it expands to:
fn main() {
if !(false || true) {
{
::std::io::_print(format_args!("{0}\n", false || true));
};
}
}
Metadata
Metadata
Assignees
Labels
No labels