Skip to content
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

filter empty statements when checking block emptiness #3878

Merged
merged 2 commits into from
Oct 26, 2019

Conversation

calebcartwright
Copy link
Member

Fixes #3868

@@ -2,33 +2,33 @@

fn main() {
loop {
();
();
let foo = ();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@calebcartwright Why do we need to update all the tests?

Copy link
Member Author

@calebcartwright calebcartwright Oct 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry i meant to leave a note on that. Apparently both ; and (); are parsed as empty tuple exprs in the block statements, so with the updated logic filtering out empty statements, these blocks were now being detected as empty.

    loop {
        ();
        ();
        }

would be flattened to

    loop {}

which was making these tests fail since they're trying to validate brace placement. the updates were just to convert to non-empty statements in those blocks to prevent the flattening.

Is this the correct behavior? Should we treat a block that only has a (); statement the same as one that only has a ; (both as empty blocks)?

If not I can do some minor refactoring to get the SnippetProvider available when checking the block statements, and in the event of the empty tuple grab the associated snippet and check for ; vs ();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your explanation!

Is this the correct behavior? Should we treat a block that only has a (); statement the same as one that only has a ; (both as empty blocks)?

Removing (); seems fine to me, though I am afraid that we may need to version-gate this as we didn't use to remove it. As we will be preparing for 2.0 release in the near future, I would like to merge this PR after we released 1.4.10 so that we don't need to add an extra version-gate which will be removed soon.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM!

@topecongiro topecongiro added this to the 2.0.0 milestone Oct 23, 2019
@topecongiro
Copy link
Contributor

@calebcartwright Sorry, would you mind resolving the conflict? I should have merged this before #3880.

@calebcartwright
Copy link
Member Author

@calebcartwright Sorry, would you mind resolving the conflict? I should have merged this before #3880.

Sure, will do!

@topecongiro topecongiro merged commit ed7c032 into rust-lang:master Oct 26, 2019
@topecongiro
Copy link
Contributor

Thank you for the update!

@calebcartwright calebcartwright deleted the block-empty-statements branch January 3, 2020 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Needs two passes to correctly format.
3 participants