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

Parse bracketed box expressions #16863

Closed
wants to merge 1 commit into from
Closed

Conversation

ftxqxd
Copy link
Contributor

@ftxqxd ftxqxd commented Aug 30, 2014

This lets the parser parse expressions like box (1i + 2) as box() (1i + 2). Expressions are parsed greedily in if, while, and for expressions, so that if box(foo) {} {} is parsed as if (box(foo) {}) {}. This is the same behaviour as before this change.

Closes #15386.

This lets the parser parse expressions like `box (1i + 2)` as `box() (1i + 2)`.
Expressions are parsed greedily in `if`, `while`, and `for` expressions, so that
`if box(foo) {} {}` is parsed as `if (box(foo) {}) {}`. This is the same
behaviour as before this change.

Closes rust-lang#15386.
@lilyball
Copy link
Contributor

This seems like a bad idea. It's just going to be confusing. The rule implemented here is if box (expr) is followed by something that looks like it could be an expression, treat (expr) as a placement, otherwise treat it as the value to box. As you already stated, this means that if box (foo) { ... } considers the { ... } to be the expression to be boxed. Yes that's the current behavior, but the current behavior is unambiguous: any parenthesized expression after box is always placement.

At the very least, if box (foo) { ... } absolutely must be non-greedy and treat the { ... } as the block for the if expression. But more generally, I think it's confusing to change how we treat the (parenthesized) expression based on whether there's a subsequent expression.

@alexcrichton
Copy link
Member

Closing due to inactivity, I also think that changes to the grammar such as this may require an RFC to gain feedback and such.

@ftxqxd ftxqxd mentioned this pull request Oct 23, 2014
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 31, 2024
Bump dependencies and use in-tree `rustc_pattern_analysis`

One last `pattern_analysis` API change. I don't have any more planned! So we can now use the in-tree version when available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't create box of parenthesised expression (documentation, error reporting)
3 participants