-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
keep the trailing semicolon on loops that break with a value #7072
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
Open
AsthaMishra
wants to merge
3
commits into
rust-lang:main
Choose a base branch
from
AsthaMishra:fix-issue-7061
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 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
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about loops deeply nested inside other loops loops?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes it works in nested loops as well |
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,73 @@ | ||
| unsafe fn foo() -> i32 { 42 } | ||
|
|
||
| fn main () { | ||
| 'label: loop { | ||
| break 'label unsafe { foo() } | ||
| }; | ||
| } | ||
|
|
||
| fn test_for_issue_5377() { | ||
| loop { | ||
| break false | ||
| }; | ||
| } | ||
|
|
||
| // A `loop` that cannot produce a value keeps the old behaviour | ||
| // redundant semicolon is removed. | ||
| fn no_value() { | ||
| loop { break }; | ||
| while false { }; | ||
| for _ in 0..0 { }; | ||
| } | ||
|
|
||
| //minimal loop that produces a value keeps the semicolon | ||
| fn minimal(){ | ||
| loop { break 5 }; | ||
| } | ||
|
|
||
| //nested loop tests | ||
| fn nested_inner_break() { | ||
| loop { | ||
| loop { break 5 }; | ||
| break | ||
| }; | ||
| } | ||
|
|
||
| fn nested_labeled_break() { | ||
| 'outer: loop { | ||
| loop { | ||
| break 'outer 5 | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| fn nested_deeply() { | ||
| 'outer: loop { | ||
| loop { | ||
| loop { | ||
| break 'outer unsafe { foo() } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| fn nested_deeply_four_layers() { | ||
| 'outer: loop { | ||
| loop { | ||
| loop { | ||
| loop { | ||
| break 'outer unsafe { foo() } | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
|
|
||
| fn break_inside_closure() { | ||
| loop { | ||
| let f = || loop { break 5 }; | ||
| let _ = f(); | ||
| break | ||
| }; | ||
| } |
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,82 @@ | ||
| unsafe fn foo() -> i32 { | ||
| 42 | ||
| } | ||
|
|
||
| fn main() { | ||
| 'label: loop { | ||
| break 'label unsafe { foo() }; | ||
| }; | ||
| } | ||
|
|
||
| fn test_for_issue_5377() { | ||
| loop { | ||
| break false; | ||
| }; | ||
| } | ||
|
|
||
| // A `loop` that cannot produce a value keeps the old behaviour | ||
| // redundant semicolon is removed. | ||
| fn no_value() { | ||
| loop { | ||
| break; | ||
| } | ||
| while false {} | ||
| for _ in 0..0 {} | ||
| } | ||
|
|
||
| //minimal loop that produces a value keeps the semicolon | ||
| fn minimal() { | ||
| loop { | ||
| break 5; | ||
| }; | ||
| } | ||
|
|
||
| //nested loop tests | ||
| fn nested_inner_break() { | ||
| loop { | ||
| loop { | ||
| break 5; | ||
| }; | ||
| break; | ||
| }; | ||
| } | ||
|
|
||
| fn nested_labeled_break() { | ||
| 'outer: loop { | ||
| loop { | ||
| break 'outer 5; | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| fn nested_deeply() { | ||
| 'outer: loop { | ||
| loop { | ||
| loop { | ||
| break 'outer unsafe { foo() }; | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| fn nested_deeply_four_layers() { | ||
| 'outer: loop { | ||
| loop { | ||
| loop { | ||
| loop { | ||
| break 'outer unsafe { foo() }; | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| fn break_inside_closure() { | ||
| loop { | ||
| let f = || loop { | ||
| break 5; | ||
| }; | ||
| let _ = f(); | ||
| break; | ||
| }; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
How does rustfmt know that
vdoesn't resolve to()? Does it make a difference?For example:
View changes since the review
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.
no rustfmt does not know what it will resolve to. No it does not make a difference as
;is kept either way, If loop breaks into a value and does not have semicolon then you get error - E0308 otherwise it is just redundant