In if, while, for and match heads, a { starts the body. A struct literal or an
else there would be ambiguous, so Auk asks for parentheses around it.
Wrong#
struct P { x: int }
fn origin(p: P): bool {
if p == P { x: 0 } { true } else { false }
}Fixed#
struct P { x: int }
fn origin(p: P): bool {
if p == (P { x: 0 }) { true } else { false }
}Common causes#
- Comparing with a struct literal in a condition.
while (x else 0) > 0written without the parentheses around theelse.- Binding the value to a
letfirst is often clearer.