-
Notifications
You must be signed in to change notification settings - Fork 931
Control-flow comments formatting #4578
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
Closed
davidBar-On
wants to merge
5
commits into
rust-lang:rustfmt-2.0.0-rc.2
from
davidBar-On:issue-4549-controlflow-comments
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2cc1d82
Fix for issue #4549 - Cintrol-flow comments formatting
davidBar-On c0b320c
Handling comments with debug
davidBar-On eb02dc7
removing debug info
davidBar-On 943a097
remove change to toml done by mistake
davidBar-On 5d0f88c
Change unwrap() to ? in functions that return Option
davidBar-On 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 hidden or 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 hidden or 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,117 @@ | ||
// Issue #4549 | ||
|
||
// Different `if`/`else` expressions | ||
// NOTE: comments before and after the condition sign are currently not handled, | ||
// so the original code snippet is used. | ||
// Therefore, althorugh such cases are included in some of the tests, | ||
// such as `if x /*x*/ == /*y*/ y`, they are not really part of the tests purpose. | ||
fn main() { | ||
if /*w*/ x /*x*/ == /*y*/ y /*z*/ {} | ||
} | ||
|
||
fn main() { | ||
/*pre-if*/ if /*post-if*/ x == y /*pre-if-block*/ { x = y +7; } | ||
/*pre-elseif*/ else if /*post-elseif*/ z == u /*pre-elseif-block*/ { y = 5;} | ||
/*pre-else*/ else /*post-else*/ {z = x;} | ||
} | ||
|
||
fn main() { | ||
/*pre-if*/ if /*post-if*/ x /*x*/ == /*y*/ y /*pre-if-block*/ { x = y +7; } | ||
/*pre-elseif*/ else if /*post-elseif Longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggg*/ z == u /*pre-elseif-block*/ { y = 5; } | ||
/*pre-else*/ else /*post-else*/ { z = x; } | ||
} | ||
|
||
fn main() { | ||
/*pre-if*/ if // post-if - make sure that x and y states are the same | ||
x == y //pre-if-block - when they are same change y to next state | ||
{ x = y +7; } | ||
} | ||
|
||
fn main() { | ||
/*pre-if*/ if // post-if - make sure that x and y states are the sameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
x /*x*/ == /*y*/ y //pre-if-block - when they are same change y to next stateeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
{ x = y +7; } | ||
} | ||
|
||
fn main() { | ||
if 5 == 6 { x = y +7; } | ||
else if z == u { y = 5; } | ||
else { z = x; } | ||
} | ||
|
||
fn main() { | ||
if // if comment | ||
5 == 6 { x = y +7; } | ||
}fn main() { | ||
if | ||
// if comment | ||
5 == 6 { x = y +7; } | ||
} | ||
|
||
// Tests for `loop` | ||
fn main() { | ||
loop { x = y +7; }; | ||
|
||
/*pre-statement*/ loop /*pre-block*/ { x = y +7; }; | ||
|
||
/*pre-statement*/ loop /*pre-block Longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg*/ { y = 5; }; | ||
|
||
/*pre-statement*/ loop /*pre-block Longerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr*/ { y = 5; }; | ||
|
||
loop /*pre-block Longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg*/ {exppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp}; | ||
} | ||
|
||
// Tests for `while` | ||
// NOTE: same coments limitations as for `if`. | ||
fn main() { | ||
/*pre-statement*/ while /*post-cond*/ x /*x*/ == /*y*/ y /*pre-block*/ { x = y +7; }; | ||
|
||
/*pre-statement*/ while /*pre-cond Longgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg*/ z == u /*pre-block*/ { y = 5; }; | ||
|
||
/*pre-statement*/ while /*pre-cond Longerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr*/ z == u /*pre-block*/ { y = 5; }; | ||
|
||
/*pre-statement*/ while // pre-cond - make sure that x and y states are the sameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
x /*x*/ == /*y*/ y //pre-block - when they are same change y to next stateeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
{ x = y +7; } | ||
} | ||
|
||
// Tests for `if/while let` | ||
// NOTE: comments before an after the `pat` item that follows `let` (e.g. the `Some(x)` | ||
// in `let Some(x) =`) are currently not handledand, so original code is used. | ||
// E.g., in `while let /*C1*/ Some(x) /*C2*/ = /*C3*/ exp /*C4*/{}`, only the | ||
// `C3` and `C4` comments are handled, and therefore comments such as `C1` AND `C2` | ||
// are not included in the test. | ||
fn main() { | ||
/*pre-statement*/ while let Some(x) = /*pre-epr*/ exp /*pre-block*/ { y = x +7; }; | ||
|
||
/*pre-statement*/ while let Some(x) = /*pre-expr Longggggggggggggggggggggggggggggggggggggggggggggggggggg*/ exp /*pre-block*/ { y = x; }; | ||
|
||
/*pre-statement*/ while let Some(x) = /*pre-expr Longerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr*/ exp /*pre-block*/ { y = x; }; | ||
|
||
/*pre-statement*/ while let Some(x) = // pre-exprrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr | ||
exp //pre-blockkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk | ||
{ y = x +7; } | ||
} | ||
fn main() { | ||
/*pre-statement*/ if let Some(x) = /*pre-epr*/ exp /*pre-block*/ { y = x +7; }; | ||
|
||
/*pre-statement*/ if let Some(ref /*def*/ mut /*abc*/ state) = /*pre-epr*/ exp /*pre-block*/ { y = x +7; }; | ||
|
||
/*pre-statement*/ if let Some(ref /*def*/ mut /*abc*/ state) = /*pre-eprrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr*/ exp /*pre-blockkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk*/ { y = x +7; }; | ||
} | ||
|
||
// Tests for `for` | ||
// NOTE: comments `in` aare currently not handledand, so original code is used. | ||
// E.g., in `for x /*C1*/ in /*C2*/`, only the `C2` comment is handled, | ||
// and therefore comments such as `C1` are not included in the test. | ||
fn main() { | ||
/*pre-statement*/ for /*post-cond*/ x in /*post-in*/ exp /*pre-block*/ { y = x +7; }; | ||
|
||
/*pre-statement*/for /*pre-cond Longggggggggggggggggggggggggggggggggggggggggggggggggggg*/ x in exp /*pre-block*/ { y = x; }; | ||
|
||
/*pre-statement*/ for /*pre-cond Longerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr*/ x in exp /*pre-block*/ { y = x; }; | ||
|
||
/*pre-statement*/ for // pre-cond - make sure that x and y states are the sameeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
x in /*post-innnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn*/ exp //pre-block - when they are same change y to next stateeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee | ||
{ y = x +7; } | ||
} |
Oops, something went wrong.
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 seems like it could be extracted out into a separate PR, since it's largely just reusing a comparatively new helper and cleaning up some more complex code written before said helper.
If this can't be landed/merged independently, please let me know why, otherwise I'd ask that you pull this change out into a separate PR so that we can go ahead and push that through (understand that this PR may need/want that separate one to get merged first)
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.
Created PR #4626 with this change. This is the only change from this PR that does not depend on the other changes.