Skip to content

Rustfmt changes meaning of closure, also not idempotent #4050

Open
@dtolnay

Description

@dtolnay

Input program, which compiles:
https://play.rust-lang.org/?edition=2018&gist=046bcee6f5a6524efd1cf0d71b383fef

fn main() {
    || {
        println!();
        || 0
    }().to_string();
}

As of rustfmt 2.0.0-rc.1-nightly (b9138e0 2020-02-10), rustfmt incorrectly changes this to the following which does not compile:

fn main() {
    || {
        {
            println!();
            || 0
        }()
        .to_string()
    };
}

It is also not idempotent, since running rustfmt again changes it to:

fn main() {
    || {
        {
            println!();
            || 0
        }
        ().to_string()
    };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    a-closuresbugPanic, non-idempotency, invalid code, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions