rustfmt
rustfmt copied to clipboard
5796 derive attribute is not wrapped if it's exactly max length
https://github.com/rust-lang/rustfmt/issues/5796
This is not the prettiest solution but there is a assumption that once we enter write_list for list.rs we always subtract the separator from the width. This is causing the bug to occur here. As the line exceeds that max width by 1 and this subtraction makes the formatter think it is equal.
So the item_str we get back is actually greater than the width so I do a check for this and format it again but this time vertically.
I don't think this is pretty or a optimal fix (as we've to format twice) but I wanted to open a PR to generate a conversation about it. Maybe we can discuss a better solution to the problem now it has been identified a little more.
What I would really like to achive is getting definitive_tactic() to handle this correctly but that relys on the argument_shape which is correct.
https://github.com/rust-lang/rustfmt/blob/6356fca675bd756d71f5c123cd053d17b16c573e/src/attr.rs#L133-L138
So which ever way I look at this, I always come back to these lines of code which are ignoring that final ,.
https://github.com/rust-lang/rustfmt/blob/6356fca675bd756d71f5c123cd053d17b16c573e/src/lists.rs#L245-L247