Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting introduces syntax error in a rare edge case #52

Closed
Bubbler-4 opened this issue Jun 19, 2023 · 1 comment · Fixed by #53
Closed

Formatting introduces syntax error in a rare edge case #52

Bubbler-4 opened this issue Jun 19, 2023 · 1 comment · Fixed by #53

Comments

@Bubbler-4
Copy link

Small example:

fn main() {
    let v = vec![1, 2, 3];
    let a = v.into_iter().fold(0, |w, x|
        match x { _ => x } | w
    );
}

After one round-trip (syn::parse_file followed by prettyplease::unparse), the code becomes:

fn main() {
    let v = vec![1, 2, 3];
    let a = v
        .into_iter()
        .fold(
            0,
            |w, x| {
                match x {
                    _ => x,
                } | w
            },
        );
}

Note the extra {} around the body of the |w, x| closure. This change makes rustc complain:

error: expected one of `:`, `@`, or `|`, found `}`
  --> src/bin/temp.rs:11:13
   |
10 |                 } | w
   |                      - expected one of `:`, `@`, or `|`
11 |             },
   |             ^ unexpected token
   |
help: parentheses are required to parse this as an expression
   |
8  ~                 (match x {
9  |                     _ => x,
10 ~                 }) | w
   |

@dtolnay
Copy link
Owner

dtolnay commented Jun 19, 2023

Good catch. Fixed in prettyplease 0.2.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants