rustfmt icon indicating copy to clipboard operation
rustfmt copied to clipboard

[unstable option] enum_discrim_align_threshold

Open scampi opened this issue 6 years ago • 4 comments
trafficstars

Tracking issue for unstable option: enum_discrim_align_threshold

scampi avatar Feb 13 '19 22:02 scampi

I was looking at the vertical alignment options of rustfmt. I was suprised by this.

20:

enum Foo {
    A   = 0,
    Bb  = 1,
    RandomLongVariantGoesHere = 10,
    Ccc = 2,
}

enum Bar {
    VeryLongVariantNameHereA = 0,
    VeryLongVariantNameHereBb = 1,
    VeryLongVariantNameHereCcc = 2,
}

I would expect this:

enum Foo {
    A   = 0,
    Bb  = 1,
    RandomLongVariantGoesHere = 10,
    Ccc = 2,
}

enum Bar {
    VeryLongVariantNameHereA   = 0,
    VeryLongVariantNameHereBb  = 1,
    VeryLongVariantNameHereCcc = 2,
}

I think it would make more sense if the threshold would refer to the maximum number of spaces to insert to make things align. The length of the actual text doesn't seem to be very relevant here. It's just when one starts to align very long items with very short items it looks a bit weird to people, but personally I still prefer it most of the times. Another reason to limit vertical alignment might be the resulting total line length, as aligning wrapped lines doesn't make much sense.

I suppose the same issue might exist on other vertical alignment options like struct_field_align_threshold.

Maybe this could fall into a more general category of "align assignment operator"? Or maybe even a vertical_align_max_spaces which could apply to all vertical alignment?

najamelan avatar Mar 04 '20 12:03 najamelan

I agree with the above, and would be happy to look into making a PR if it's something that's wanted.

Leorii avatar Sep 17 '20 00:09 Leorii

Any blocking issues on stabilizing this feature? We've been using it for years, pretty happy with it, and its currently the last remaining reason we still have nightly installed.

jmrgibson avatar Aug 23 '22 00:08 jmrgibson

Any blocking issues on stabilizing this feature? We've been using it for years, pretty happy with it, and its currently the last remaining reason we still have nightly installed.

See #5365 and #5367 for general information on stabilization. I don't know the answers/details of those items for this specific option, but it's the material that would need to be attested to in order for this option to be judged as ready

calebcartwright avatar Aug 23 '22 01:08 calebcartwright