-
Notifications
You must be signed in to change notification settings - Fork 898
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
Incorrect indentation on multi-line single generic bound #4689
Comments
Based on the guidelines in the description I tried the "naive" change of just deleting the 1st test error type: when the bound name is in the same line of the preceding code. E.g: rustfmt/tests/target/issue-3651.rs Lines 1 to 7 in 257311c
However, when fmt::Write bound is added, using current version of rusfmt (without the code change), indentation is changed to:
fn f() -> Box<
dyn FnMut() -> Thing<
WithType = LongItemName,
Error = LONGLONGLONGLONGLONGONGEvenLongerErrorNameLongerLonger,
> + fmt::Write,
> {
} With the rustfmt code change, both cases are indented the same. Should indentation be the same with or without adding the 2nd test error type: function in rustfmt/tests/target/issue-3508.rs Lines 1 to 7 in 257311c
With the rustfmt change, indentation is changed to: fn foo<F>(foo2: F)
where
F: Fn(
// this comment is deleted
)
{
} The same indentation is applied with current rustfmt (without the code change) when |
So there's two things to this, the existing behavior with extra indentation that's added when adding a second bound (however odd that may be in those snippets 😄) is a separate bug. However, that doesn't change the fact that the naive change is not viable, as that introduces a new bug. A different approach will be needed to address the bug with the trait bounds described in the issue description, though if the additional bug you've discovered can be addressed at the same time that'd be great too! |
I think this might the same issue, but happy to open a new issue if not - rustfmt removes all indentation from the mod inner {
fn foo() -> String
where { // running rustfmt removes all whitespace at the start of the line
String::new()
}
} |
@jyn514,
I checked and this issue is not fixed by the PR. I assume it is better to open a new issue then try to enhance the PR to also fix this problem. |
@jyn514, the issue is not resolved by this PR. I evaluated it to make sure it is not related and I have some observations. If you will open a new issues I will discuss there what I found. |
closing since #5390 was merged |
We have a bug in the generic bounds formatting code that does not properly account for the case where there's a single bound that itself has to be formatted across multiple lines.
Input
Output
Expected output
The same indentation as if there were 2+ bounds
Meta
The problematic code can be found here:
rustfmt/src/formatting/types.rs
Lines 1000 to 1007 in d84a32c
The issue is an incorrect assumption that if there's just one bound, or multiple bounds but which were able to be formatted on a single line without exceeding the max width limit, then we'll be formatting the bound(s) on a single line and there's no need to reformat the bounds with the proper indentation. However, as noted above this fails to catch the multi-lined single bound case so this check will need to be updated to also account for that case.
The text was updated successfully, but these errors were encountered: