-
Notifications
You must be signed in to change notification settings - Fork 909
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
Prevent trailing whitespace in where clause bound predicate #5019
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// rustfmt-trailing_comma: Always | ||
|
||
pub struct Matrix<T, const R: usize, const C: usize,> | ||
where | ||
[T; R * C]:, | ||
{ | ||
contents: [T; R * C], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// rustfmt-trailing_comma: Never | ||
|
||
pub struct Matrix<T, const R: usize, const C: usize> | ||
where | ||
[T; R * C]: | ||
{ | ||
contents: [T; R * C] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
impl ThisIsALongStructNameToPushTheWhereToWrapLolololol where | ||
[(); this_is_a_long_const_function_name()]: | ||
{ | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is on one of the hottest paths in the codebase, and while there wouldn't be any significant performance concerns with the proposed diff in this location, we should strive to avoid having to make fixes at this level due to the higher potential for unintended knock on effects.
Ideally, we'd be able to correct the issue upstream instead of having to try to retcon it here. Do you think that will be feasible in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could address it a little further upstream. Before I pitch some ideas I want to lay out my understanding of the code flow.
Code Flow
In this case when we call
rewrite
onast::WherePredicate
, we hit the first match arm ofast::WherePredicate::BoundPredicate
, which ultimately callsexpr::rewrite_assign_rhs
rustfmt/src/types.rs
Lines 412 to 433 in 599b2fd
As it's currently implemented,
expr::rewrite_assign_rhs
just callsexpr::rewrite_assign_rhs_with
, which is where thelhs
andrhs
get concatenated (linked below for reference).rustfmt/src/expr.rs
Lines 1918 to 1928 in 599b2fd
Ideas
expr::rewrite_assign_rhs_with
to only concatenate thelhs
andrhs
if therhs
isn't just whitespace.expr::choose_rhs
returning" "
when there is norhs
, but it does tackle the problem slightly further upstream.expr::rewrite_assign_potentially_empty_rhs
, (open to name suggestion) that will be called instead ofexpr::rewrite_assign_rhs
when rewritingast::WherePredicate::BoundPredicate
.rhs
. (I think I'm leaning towards this option)expr::choose_rhs
Definitely open to your thoughts and if you have other suggestions for where to make this fix!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the excellent, detailed write up. After reading and reflecting I think you were on the right path to begin with. I was originally thinking we'd check if the bounds where empty at the original callsite and skip trying to join a lhs with a non-existent rhs to begin with. However, doing that would likely start to bleed through the encapsulation of the
Rewrite
impl forGenericBounds
and/or require an upfront rewrite call of the bounds node to check for the empty string.As such I think I'm leaning pretty heavily towards num 3/your original proposal. Realize this goes slightly past the literal issue reports but could you also add some cases with the snippet from 5012 that are configured to do comma inserts too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
option 3 it is! I'll add those additional test cases and request a follow up review when they've been added!