-
Notifications
You must be signed in to change notification settings - Fork 926
Format derive attributes vertically #5578
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
Comments
Thanks for reaching out! To the best of my knowledge there isn't a configuration that allows what you're looking for. I think we only format derives vertically if the derive list exceeds the Lines 150 to 155 in ef91154
|
Cool! Thanks for the info. So derive attributes do not fall into the If I have a go at implementing this feature, then handling I just wonder whether there's a broader form that should be handled the same way? |
It would seem that derives are special cased. Likely because rustfmt provides the option to merge multiple derives into a single derive. For example this: #[derive(Debug)]
#[derive(Clone)]
struct s; could be formatted like: #[derive(Debug, Clone)]
struct s;
PRs are always welcome! Just a hunch, but you'll likely want to make changes to the lines of code I called out above where we determine what the tactic should be. It might be as simple as swapping let tactic = definitive_tactic(
&all_items,
ListTactic::HorizontalVertical,
Separator::Comma,
- argument_shape.width,
+ context.config.attr_fn_like_width()
); |
Just so you're aware those are handled here: Lines 296 to 313 in ef91154
However, derive formatting is handled in format_derive as mentioned above, and it's likely that we can't reuse this code path because of the additional merging we might do when rewriting derives. Hope all this info helps! |
Hi!
I'd like to format my
#[derive(..)]
attributes vertically - like this:I've tried the following in my
rustfmt.toml
, but this seemed to have no effect.Also adding a trailing comma to the list doesn't work.
rustfmt
just removes the comma and reformats the list horizontally.Any help appreciated!
The text was updated successfully, but these errors were encountered: