Description
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.