Skip to content

pretty-printer loses parens in "if (1 == fail) { }" #929

@jruderman

Description

@jruderman
fn f() { if (1 == fail) { } else { } }

and

fn f() { if 1 == (fail) { } else { } }

lose their parens, becoming something that fails to parse:

fn f() { if 1 == fail { } else { } }

This could be solved by parenthesizing the whole discriminant, parenthesizing just the "fail", or getting rid of the syntactic ambiguity. I see a way to do the first option, by making pprust::print_maybe_parens_discrim recurse right. I could write that patch, along with tests, if you think it's the right thing to do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-prettyArea: Pretty printing (including `-Z unpretty`)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions