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

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

Closed
usagi opened this issue Mar 27, 2020 · 1 comment
Closed
Labels
bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce

Comments

@usagi
Copy link

usagi commented Mar 27, 2020

  • 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.

@topecongiro topecongiro added bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce labels Mar 31, 2020
@calebcartwright
Copy link
Member

Closed via #4201

bradleypmartin pushed a commit to bradleypmartin/rustfmt that referenced this issue May 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

No branches or pull requests

3 participants