reference icon indicating copy to clipboard operation
reference copied to clipboard

No-brace restrictions should mention that they are recursive.

Open ehuss opened this issue 6 years ago • 0 comments

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 https://github.com/rust-lang/rust/pull/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 https://github.com/rust-lang/rust/pull/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 https://github.com/rust-lang/rust/pull/88690): {"abc"}.len(); works but {1}-1 does not.

ehuss avatar Apr 21 '19 17:04 ehuss