Skip to content

Failure to parse {2} + {2} #54482

Open
Open
@blaztinn

Description

@blaztinn

These examples should compile according to the rust reference:

fn compiles() -> i32 {
    ({2}) + ({2})
}

fn fails() -> i32 {
    {2} + {2}
}

fn compiles2() -> i32 {
    2 + {2}
}

fn fails2() -> i32 {
    {2} + 2
}

(Playground)

Errors:

   Compiling playground v0.0.1 (file:///playground)
error: expected expression, found `+`
 --> src/lib.rs:6:9
  |
6 |     {2} + {2}
  |         ^ expected expression

error: expected expression, found `+`
  --> src/lib.rs:14:9
   |
14 |     {2} + 2
   |         ^ expected expression

error: aborting due to 2 previous errors

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Rust reference snippet (thanks @Moongoodboy-K for the help here):

Expression : BlockExpression | OperatorExpression | ..
OperatorExpression : ArithmeticOrLogicalExpression | ..
ArithmeticOrLogicalExpression : Expression + Expression | ..
BlockExpression : { InnerAttribute* Statement* Expression? }

cc: @Moongoodboy-K

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-grammarArea: The grammar of RustA-parserArea: The lexing & parsing of Rust source code to an ASTC-discussionCategory: Discussion or questions that doesn't represent real issues.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions