rust-lang / rust-lang/rust-analyzer

Our parse tree differs wrt to block trailing expressions

Open
#16,363 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-parser C-bug
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

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.

https://github.com/rust-lang/rust-analyzer/issues/16289 might be related to this.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Rust examples and comparing rust-analyzer's parse trees and diagnostics with rustc's output. Investigate parsing of block trailing expressions and let-else statements; done means the assignment examples are represented as binary expression statements and the let-else example is rejected as rustc rejects it.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.