mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Parse let
expressions in order to support let
chains
We still need to reject freestanding `let` expressions: see https://github.com/rust-analyzer/rust-analyzer/issues/11320#issuecomment-1018212465.
This commit is contained in:
parent
d6ed146a1c
commit
de8633f15f
7 changed files with 99 additions and 67 deletions
|
@ -29,6 +29,15 @@ fn expr_no_struct(p: &mut Parser) {
|
|||
expr_bp(p, None, r, 1);
|
||||
}
|
||||
|
||||
/// Parses the expression in `let pattern = expression`.
|
||||
/// It needs to be parsed with lower precedence than `&&`, so that
|
||||
/// `if let true = true && false` is parsed as `if (let true = true) && (true)`
|
||||
/// and not `if let true = (true && true)`.
|
||||
fn expr_let(p: &mut Parser) {
|
||||
let r = Restrictions { forbid_structs: true, prefer_stmt: false };
|
||||
expr_bp(p, None, r, 5);
|
||||
}
|
||||
|
||||
pub(super) fn stmt(p: &mut Parser, semicolon: Semicolon) {
|
||||
if p.eat(T![;]) {
|
||||
return;
|
||||
|
@ -185,6 +194,7 @@ fn current_op(p: &Parser) -> (u8, SyntaxKind) {
|
|||
T![%] if p.at(T![%=]) => (1, T![%=]),
|
||||
T![%] => (11, T![%]),
|
||||
T![&] if p.at(T![&=]) => (1, T![&=]),
|
||||
// If you update this, remember to update `expr_let()` too.
|
||||
T![&] if p.at(T![&&]) => (4, T![&&]),
|
||||
T![&] => (8, T![&]),
|
||||
T![/] if p.at(T![/=]) => (1, T![/=]),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue