Skip to content

Split impl<...> X for Y<...> at 'for' #1037

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

Closed
nagisa opened this issue Jun 5, 2016 · 4 comments
Closed

Split impl<...> X for Y<...> at 'for' #1037

nagisa opened this issue Jun 5, 2016 · 4 comments

Comments

@nagisa
Copy link
Member

nagisa commented Jun 5, 2016

screenshot from 2016-06-05 18-52-08

@nrc nrc changed the title Nasty reformatting of impl<...> X for Y<...> Split impl<...> X for Y<...> at 'for' Jun 5, 2016
@fabric-and-ink
Copy link
Contributor

I will take a look at this.

@fabric-and-ink
Copy link
Contributor

fabric-and-ink commented Aug 7, 2016

@nrc can you maybe give me a hint, how to do this? My idea is simply to check if type + trait fits on one line. If not, break befose the for, indent and append the type rewrite. How do I check this condition in a nice way? Reformat the whole line (without the where-clause) with a big max_width and then check the length?

@nrc
Copy link
Member

nrc commented Aug 7, 2016

I would examine self_ty.rewrite, which is the concrete type of the impl declaration. If it contains a newline, then I would try reformatting it on a newline (this only requires changing the indent and budget supplied to the function). You could then compare the two versions, but I think that actually you could always put a newline before for in this case and use the second reformatting.

I think checking for a newline in the reformatted type is all you need to do - you will never affect the earlier part of the impl, and that is the only place that a linebreak can happen. You could also try this if the result of reformatting was None - in that case we couldn't fit the text into the budget, but if you give more space (by inserting the newline before for, then there might be enough space.

You should just check that when you do split, where clauses are still handled properly.

Also, you'll need to delay actually appending for until you have the final string for the type.

Ping me on irc if you want more info.

@fabric-and-ink
Copy link
Contributor

fabric-and-ink commented Aug 9, 2016

Thanks @nrc!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants