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

Empty lines in where-clause #5655

Closed
stanislav-tkach opened this issue Jan 9, 2023 · 2 comments · Fixed by #5867
Closed

Empty lines in where-clause #5655

stanislav-tkach opened this issue Jan 9, 2023 · 2 comments · Fixed by #5867
Assignees
Labels
feature-request good first issue Issues up for grabs, also good candidates for new rustfmt contributors p-low

Comments

@stanislav-tkach
Copy link
Contributor

stanislav-tkach commented Jan 9, 2023

I would expect the empty line between the T: std::fmt::Debug and T: std::fmt::Display lines to be removed by rustfmt, but it isn't:

fn foo<T>(_: T)
where
    T: std::fmt::Debug,

    T: std::fmt::Display,
{
}

At least not by the rustfmt 1.5.1-stable (69f9c33d 2022-12-12) version.

I'm sorry if it is a duplicate, but I haven't been able to find any related issues.

@ytmimi
Copy link
Contributor

ytmimi commented Jan 10, 2023

Thanks for reaching out! hmm odd behavior, but confirming I can reproduce this!

The style guide section on where clauses doesn't mention anything about preserving newlines, so this might just be rustfmt wanting to leave the bounds as the developer wrote them.

I did some digging and it turns out that the newlines are kept because we set preserve_newline(true) when building the ListFormatting in rewrite_bounds_on_where_clause:

rustfmt/src/items.rs

Lines 2886 to 2889 in ee2bed9

let fmt = ListFormatting::new(shape, context.config)
.tactic(shape_tactic)
.trailing_separator(comma_tactic)
.preserve_newline(true);

We can't change the current default behavior because that would be a breaking formatting change, but we could introduce a new, nightly, configuration option to allow you to configure whether or not to preserve newlines between where clause bounds.

@ytmimi ytmimi added good first issue Issues up for grabs, also good candidates for new rustfmt contributors p-low feature-request labels Jan 10, 2023
@naosense
Copy link

looks simple, I'll take it

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request good first issue Issues up for grabs, also good candidates for new rustfmt contributors p-low
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants