Skip to content

Bug: trailing_comma + struct_field_align_threshold -> removing a struct's commas #4099

Closed
@usagi

Description

@usagi
  • rustfmt 1.4.12-nightly (9f53665f 2020-02-10)
  • rustc 1.44.0-nightly (f509b26a7 2020-03-18)

Minimal repro

  1. Prepare the nightly repos:
cargo new aaa
cd aaa
echo 'nightly' > rust-toolchain
  1. Prepare the .rustfmt.toml:
struct_field_align_threshold = 127
trailing_comma = "Never"
  1. Prepare the src/main.rs with a struct like it:
struct S {
  aaa: f32,

  bbb: f32,

  ccc: f32
}

fn main() {
  println!("Hello, world!");
}
  1. cargo fmt

The actual result of src/main.rs:

struct S {
    aaa: f32

    bbb: f32

    ccc: f32
}

fn main() {
    println!("Hello, world!");
}

Note: The commas are removed. Unfortunately, this result could not be compiled then I think it is high priority bug maybe.

The Expected result of src/main.rs:

struct S {
    aaa: f32,

    bbb: f32,

    ccc: f32
}

fn main() {
    println!("Hello, world!");
}

Note: I tried some different versions of the minimal repro code. So, I found two variations that could be format expectedly.

  1. The No empty lines pattern:
struct S {
  aaa: f32,
  bbb: f32,
  ccc: f32
}
  1. No White space characters pattern:
struct S {
aaa: f32,

bbb: f32,

ccc: f32
}

Note: These variant patterns be retained these commas cargo fmt once. However, once again cargo fmt, then these are removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPanic, non-idempotency, invalid code, etc.only-with-optionrequires a non-default option value to reproduce

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions