Skip to content
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

Fix brace_style="PreferSameLine" with trailing_comma="Vertical" results #5556

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

hirasawayuki
Copy link

@hirasawayuki hirasawayuki commented Oct 2, 2022

Fixes #2321

  • Fixed trailing comma did not disappear when configured brace_style="PreferSameLine" and trailing_comma="Vertical".
  • Fixed test case.

Example

When brace_style="PreferSameLine" and trailing_comma="Vertical" configured, the results would be as in the following example:

before

fn lorem<S, T>(lorem: S, ipsum: T)
where
    S: Add + Sub,
    T: Mul + Div, { // ← trailing comma is not removed from the bound
    // body
}

after

fn lorem<S, T>(lorem: S, ipsum: T)
where
    S: Add + Sub,
    T: Mul + Div {
    // body
}

@hirasawayuki hirasawayuki changed the title Fix PreferSameLine brace_style with trailing_comma Vertical results Fix brace_style="PreferSameLine" with trailing_comma="Vertical" results Oct 2, 2022
@ytmimi
Copy link
Contributor

ytmimi commented Oct 4, 2022

Thanks for your first contribution to rustfmt 🎉

I try and get around to reviewing this in the coming days!

@ytmimi ytmimi self-assigned this Oct 4, 2022
T: UUUUUUUUUUU, {
T: UUUUUUUUUUU {
Copy link
Contributor

@ytmimi ytmimi Oct 10, 2022

Choose a reason for hiding this comment

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

Typically changing existing tests is not something we want to do and is usually a sign that the change needs to be version gated to prevent breaking formatting changes. However brace_style is an unstable option so the version gate might not be necessary in this case

Copy link
Author

Choose a reason for hiding this comment

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

I'll do it if I have to! 👍

Comment on lines 4 to 9
fn lorem<S, T,>(lorem: S, ipsum: T,)
where
S: Add + Sub,
T: Mul + Div, {
// body
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also include a where clause with with a single bound. I like that you've included tests with trailing_comma: Always and trailing_comma: Vertical. Could you also expand the tests to include the other combinations of brace_style

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the review. I added test case for brace_style AlwaysNextLine and SameLineWhere pattern.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for including those additional test cases! I'll have some time later this week to give this a more thorough review 😁

Comment on lines +6 to +7
S: Add + Sub,
T: Mul + Div {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at this output, I'd actually expect there to be a trailing comma after T: Mul + Div, since the where clause bounds were formatted vertically.

Comment on lines +5 to +8
where
S: Add + Sub,
T: Mul + Div,
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I don't understand the brace_style config fully, but with an option like SameLineWhere I'd expect this to format with the opening brace on the same line as the last where clause bound. Do you think the current behavior is correct?

Comment on lines +4 to +10
fn lorem<S, T,>(lorem: S, ipsum: T,)
where
S: Add + Sub,
T: Mul + Div,
{
// body
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Where clauses can appear in other contexts besides function definitions. Can we also add some examples with enum / struct definitions, and impl blocks to highlight how brace_style interacts with trailing_comma for those other language constructs?

Also including some tests with a single where clause bound (e.g. just S: Add + Sub) would also be helpful to highlight the difference between how a list of bounds VS a single bound is formatted.

@gentoid
Copy link
Contributor

gentoid commented Aug 26, 2023

It looks like there's no activity last months. Is it ok, if I pick up the baton?

@ytmimi
Copy link
Contributor

ytmimi commented Aug 26, 2023

@gentoid thanks for asking to get involved! You're more than welcome to open up a PR that builds off of this one, but I want to be mindful or your time and say that this is a fairly low priority issue and is unlikely to be reviewed any time soon.

@gentoid
Copy link
Contributor

gentoid commented Aug 26, 2023

Ok, great.

is unlikely to be reviewed any time soon.

That's fine.

Thanks!

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

Successfully merging this pull request may close these issues.

PreferSameLine brace_style with trailing_comma Vertical produces weird results
3 participants