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

No-brace restrictions should mention that they are recursive. #569

Open
ehuss opened this issue Apr 21, 2019 · 0 comments
Open

No-brace restrictions should mention that they are recursive. #569

ehuss opened this issue Apr 21, 2019 · 0 comments
Labels
A-grammar Area: Syntax and parsing

Comments

@ehuss
Copy link
Contributor

ehuss commented Apr 21, 2019

There are various places in the grammar that restrict expressions with various types of braces. These restrictions also apply recursively into the expressions. This should be captured somehow. Examples:

if-expr.md mentions that the expression cannot be a struct expression:

if S{} {/*...*/}  // This is syntactically invalid.

However this applies recursively:

if x == S{} {/*...*/}  // This is a conditional expression with a struct inside it, also invalid.

Another example is that a final expression in Statements must be an ExpressionWithoutBlock. However, ExpressionWithoutBlock does not capture that the block restriction also applies recursively. For example {{1}+{1}} does not parse.

I don't know the exact rules here, presumably anything with brackets as the last expression? Or parsing a block ends an expression? This needs to be spelled out explicitly, and somehow captured in the grammar.

See rust-lang/rust#59981.

Also, if, if-let, and match should explain why struct expressions aren't allowed, and it should indicate that parentheses can be used as a work-around.

NOTE: This applies to all the places where structs aren't allowed, like loop expressions.

See also rust-lang/rust#59981 for some example tests that illustrate similar issues.

Also, it's not just tail expressions. Method call expressions also can't be structs, as in if S{}.foo() {}.

Another example: match () { () => 1 } + 2 the match requires parentheses.
Another example: {{1}==0} doesn't work, but {1=={0}} does.

Another example (see rust-lang/rust#88690): {"abc"}.len(); works but {1}-1 does not.

@ehuss ehuss added the A-grammar Area: Syntax and parsing label Apr 21, 2019
@ehuss ehuss changed the title Struct restrictions should mention that they are recursive. No-brace restrictions should mention that they are recursive. May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: Syntax and parsing
Projects
None yet
Development

No branches or pull requests

1 participant