Skip to content

Search for struct body span after any generic arguments #5274

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

Merged
merged 1 commit into from
Mar 21, 2022

Conversation

ytmimi
Copy link
Contributor

@ytmimi ytmimi commented Mar 20, 2022

Fixes #5273

Previously, rustfmt searched for the start of a struct body after the opening {. In most cases this works just fine, but const values can also be defined inside { }, which lead to issues when rewriting the struct body (as highlighted by the linked issue).

Now, rustfmt will search for the { after the generic argument list to guarantee that the { it finds is the start of the struct body.

Fixes 5273

Previously, rustfmt searched for the start of a struct body after the
opening `{`. In most cases this works just fine, but const values can
also be defined between `{ }`, which lead to issues when rewriting the
struct body.

Now, rustfmt will search for the `{` after the generic argument list to
guarantee that the `{` it finds is the start of the struct body.
Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@calebcartwright calebcartwright merged commit e41329c into rust-lang:master Mar 21, 2022
@calebcartwright
Copy link
Member

@ytmimi re: dialog #4220, I'd think ideally we'd do what you have here but use the span of the where clause instead as opposed to doing a full span search (where clause should be available as a field on the generics iirc)

@ytmimi
Copy link
Contributor Author

ytmimi commented Apr 2, 2022

Yup the where clause is is available on the Generics. I'm surprised that the span on the struct doesn't encompass the where clause as well.

1 similar comment
@ytmimi
Copy link
Contributor Author

ytmimi commented Apr 2, 2022

Yup the where clause is is available on the Generics. I'm surprised that the span on the struct doesn't encompass the where clause as well.

@calebcartwright
Copy link
Member

I'm surprised that the span on the struct doesn't encompass the where clause as well.

I know it seems odd at first blush for the span of the containing node to not extend to the end of the span of one its child nodes, but remember with certain item definitions there can be an awful lot of non-generics content between the end of the generics and the start of the where clause, which is why the spans are structured they way that they are

@ytmimi ytmimi deleted the issue_5273 branch August 7, 2022 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Const expressions break formatting
2 participants