-
Notifications
You must be signed in to change notification settings - Fork 963
Enforce that the last statement in a loop body has a semicolon #6711
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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. Can we add two more test cases:
In both case I wouldn't expect us to add a |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // rustfmt-edition: 2024 | ||
| // rustfmt-style_edition: 2027 | ||
|
|
||
| fn main() { | ||
| for x in [1] { | ||
| println!() | ||
| } | ||
|
|
||
| while false { | ||
| println!() | ||
| } | ||
|
|
||
| while let Some('x') = None { | ||
| println!() | ||
| } | ||
|
|
||
| loop { | ||
| println!() | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,7 +184,7 @@ macro_rules! binary { | |
| op, | ||
| rhs, | ||
| }, | ||
| } | ||
| }; | ||
|
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. Was this a necessary change? If not I'd prefer we revert it since we try not to change existing test cases. |
||
| } | ||
| }; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // rustfmt-edition: 2024 | ||
| // rustfmt-style_edition: 2027 | ||
|
|
||
| fn main() { | ||
| for x in [1] { | ||
| println!(); | ||
| } | ||
|
|
||
| while false { | ||
| println!(); | ||
| } | ||
|
|
||
| while let Some('x') = None { | ||
| println!(); | ||
| } | ||
|
|
||
| loop { | ||
| println!(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -216,7 +216,7 @@ macro_rules! binary { | |
| op, | ||
| rhs, | ||
| }, | ||
| } | ||
| }; | ||
|
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. Why did this change? |
||
| } | ||
| }; | ||
| } | ||
|
|
||
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.
What about macros that use curly braces?
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.
An alternative here might be to use
span_to_snippetand check if the returned string ends in}.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.
This appears to work with the current code as I'd want it to, but I couldn't tell you why...
Before
After
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.
Probably maybe that the block macro is a statement..?
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 changed it to this
And the tests still passed, so I think it's up to you to decide which is a more reasonable path.