rust-lang / rust-lang/rust-analyzer
Our parse tree differs wrt to block trailing expressions
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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