Wrapping expr in curly braces changes the operator precedence · Issue #28777 · rust-lang/rust (original) (raw)
This program prints different values depending upon whether the v1
or v2
initializer is surrounded by curly braces:
fn main() { let v1 = { 1 + {2} * {3} }; // 9, indicating a parse of (1 + 2) * 3 let v2 = 1 + {2} * {3} ; // 7, indicating a parse of 1 + (2 * 3) println!("{}", v1); println!("{}", v2); }
I think it should print 7
for both lines. parser-lalr -v
accepts this program and consistently parses 1 + (2 * 3) for both lines.
| | | | | | | (ExprBlock
| | | | | | | | (ExprBinary
| | | | | | | | | BiAdd
| | | | | | | | | (ExprLit
| | | | | | | | | | (LitInteger
| | | | | | | | | | | 1
| | | | | | | | | | )
| | | | | | | | | )
| | | | | | | | | (ExprBinary
| | | | | | | | | | BiMul
| | | | | | | | | | (ExprBlock
| | | | | | | | | | | (ExprLit
| | | | | | | | | | | | (LitInteger
| | | | | | | | | | | | | 2
| | | | | | | | | | | | )
| | | | | | | | | | | )
| | | | | | | | | | )
| | | | | | | | | | (ExprBlock
| | | | | | | | | | | (ExprLit
| | | | | | | | | | | | (LitInteger
| | | | | | | | | | | | | 3
| | | | | | | | | | | | )
| | | | | | | | | | | )
| | | | | | | | | | )
| | | | | | | | | )
| | | | | | | | )
| | | | | | | )