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.
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
Implement
trailing_semicolon = "Preserve"
#6149base: master
Are you sure you want to change the base?
Implement
trailing_semicolon = "Preserve"
#6149Changes from 3 commits
fc7f6e1
10e6db2
8f944d0
3126770
922e8ba
1973b90
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 cannot remember what the bug policy here is, but ideally we'd just remove this adjustment to
shape
since it's already accounted for informat_stmt
. That causes self-formatting test to fail because some expressions actually fit onto one line.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.
You can fix the
shape
adjustment if the fix is version gated toversion=Two
. You could updated the logic so that we only sub 1 whenversion=One
is set,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 fixed it in Version=Two, added a test for one&two, and fixed the cases that changed rustfmt's own formatting (since rustfmt apparently uses Two! 😆)
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.
responded to this in #6149 (comment)
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.
was this the cause of the double semicolon counting?
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.
See the comment below; I pointed out the reason for the the double semicolon counting in more detail.
I split these two branches because we need to preserve semicolons only if we have a
StmtKind::Semi
, and not if we have aStmtKind::Expr
.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.
Would you mind showing an example where things are wrapping early, maybe even adding a
version=One
test case if we go the route of fixing things forversion=Two
.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.
The return statement line is exactly 100 chars long. When formatting the expression, we first subtract one from the shape here:
rustfmt/src/stmt.rs
Lines 119 to 128 in 7289391
(See
let shape = shape.sub_width(suffix.len())?;
)And then once again here:
rustfmt/src/expr.rs
Lines 67 to 71 in 7289391
(in
format_expr
).In practice, for example, we need to format
return helloo...o(arg)
which is an expression that is 95 characters long (100 - 4 identation - 1 semicolon) but after subtracting from theshape
twice, we only have have a budget of 94 characters, even though the whole expression should fit in the line.I can add it as a
version=One
test.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.
For the record, i discovered this because it happens twice in practice in the rustfmt codebase, so the self-formatting test failed.
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.
Yeah, we use
version=Two
within rustfmt as a way to dogfood unstable formatting (at least that's my assumption)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.
Do we still need this function if we're version gating the fix and only applying the old behavior for
version=One
?