rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

Vector declarations with trailing commas don't get formatted

Open slyrz opened this issue 10 years ago • 3 comments

I noticed some odd behaviour with rustfmt (0.5.0). It leaves vector declarations with trailing commas untouched. The following code

fn main() {
  let arr_x = [ 1,  2,  3 ];
  let arr_y = [ 1,  2,  3, ];
  let vec_x = vec![ 1,  2,  3 ];
  let vec_y = vec![ 1,  2,  3, ];
}

becomes

fn main() {
    let arr_x = [1, 2, 3];
    let arr_y = [1, 2, 3];
    let vec_x = vec![1, 2, 3];
    let vec_y = vec![ 1,  2,  3, ];
}

Is this a bug or a feature?

slyrz avatar Jun 04 '16 09:06 slyrz

It's kind of a bug - we only reformat macro uses if they look like function calls, and a trailing comma breaks that, I guess.

nrc avatar Jun 04 '16 09:06 nrc

This was considered. There's no way to guarantee that the trailing comma is not significant.

marcusklaas avatar Jun 04 '16 19:06 marcusklaas

Closed by #1219.

topecongiro avatar May 25 '17 14:05 topecongiro