Skip to content

Redundant braces lead to compilation failure: expected expression, found as #59975

Closed
@RalfJung

Description

@RalfJung

The following program surprisingly does not compile:

fn main() {
    let x = &mut 2;
    let _val = {{x} as *mut i32};
}

The error is rather confusing, somehow it expects something to be ():

error: expected expression, found keyword `as`
 --> src/main.rs:3:21
  |
3 |     let _val = {{x} as *mut i32};
  |                     ^^ expected expression

error[E0308]: mismatched types
 --> src/main.rs:3:18
  |
1 | fn main() {
  |           - expected `()` because of default return type
2 |     let x = &mut 2;
3 |     let _val = {{x} as *mut i32};
  |                  ^ expected (), found mutable reference
  |
  = note: expected type `()`
             found type `&mut {integer}`

If I remove either of the pair of braces in the last line, it works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-grammarArea: The grammar of RustT-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