Skip to content

Our parse tree differs wrt to block trailing expressions #16363

@Veykril

Description

@Veykril
Member

Some examples:

fn main() {
    S {..}  = ();
    || {  } = ();
    break {  } = ();
}

we get the following diagnostics in rustc

error[E0070]: invalid left-hand side of assignment
 --> src/main.rs:4:13
  |
4 |     || {  } = ();
  |        ---- ^
  |        |
  |        cannot assign to this expression

error[E0070]: invalid left-hand side of assignment
 --> src/main.rs:5:16
  |
5 |     break {  } = ();
  |           ---- ^
  |           |
  |           cannot assign to this expression

which clearly show that these are expression statements containing a binary expression each, yet in r-a the second one is considered a statement containing a closure expression and the third a statement containing a break expresson (with a nested binary expression inside each). This is very much wrong and most likely causes issue in other places as well.

Meanwhile in fn func() { let Some(_) = || {Some(1)} else { panic!("h") };} we should error with error: right curly brace }beforeelsein alet...else statement not allowed yet we accept this just fine.

#16289 might be related to this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserparser issuesC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Veykril

        Issue actions

          Our parse tree differs wrt to block trailing expressions · Issue #16363 · rust-lang/rust-analyzer