Skip to content

RustFmt does not take into account edition from Cargo.toml #368

@jonhoo

Description

@jonhoo

Steps to reproduce:

$ cargo new --bin edition-fmt
$ cd edition-fmt
$ grep edition Cargo.toml
edition = "2018"
$ echo 'fn main() { async { 1; }; }' > src/main.rs

Expected vs. actual behavior:

Expected:

Open src/main.rs in editor and run :RustFmt. The file should now look like this:

fn main() {
    async {
        1;
    };
}

Actual:

Open src/main.rs in editor and run :RustFmt. You get the error:

error: expected identifier, found `1`

This is because rustfmt is run, which defaults to the 2015 edition (where async isn't supported). The rustfmt command does not take into account edition from Cargo.toml. It is possible to work around this by doing:

$ echo 'edition = "2018"' > rustfmt.toml

But remembering to do this in all projects is a bit of a pain, and is not very discoverable. I believe the reason why rustfmt is used over cargo fmt is to support formatting only certain paths, and to support formatting even when operating on Rust files not in a cargo project, but the cost here seems too high. Is there some way we can get both that functionality and have sensible support for edition as specified in Cargo.toml?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions