Skip to content

feat: parse super let #19653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/parser/src/grammar/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(super) fn stmt(p: &mut Parser<'_>, semicolon: Semicolon) {
// }
attributes::outer_attrs(p);

if p.at(T![let]) {
if p.at(T![let]) || (p.at(T![super]) && p.nth_at(1, T![let])) {
let_stmt(p, semicolon);
m.complete(p, LET_STMT);
return;
Expand Down Expand Up @@ -113,8 +113,9 @@ pub(super) fn stmt(p: &mut Parser<'_>, semicolon: Semicolon) {
}

// test let_stmt
// fn f() { let x: i32 = 92; }
// fn f() { let x: i32 = 92; super let y; super::foo; }
pub(super) fn let_stmt(p: &mut Parser<'_>, with_semi: Semicolon) {
p.eat(T![super]);
p.bump(T![let]);
patterns::pattern(p);
if p.at(T![:]) {
Expand Down
23 changes: 23 additions & 0 deletions crates/parser/test_data/parser/inline/ok/let_stmt.rast
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,28 @@ SOURCE_FILE
INT_NUMBER "92"
SEMICOLON ";"
WHITESPACE " "
LET_STMT
SUPER_KW "super"
WHITESPACE " "
LET_KW "let"
WHITESPACE " "
IDENT_PAT
NAME
IDENT "y"
SEMICOLON ";"
WHITESPACE " "
EXPR_STMT
PATH_EXPR
PATH
PATH
PATH_SEGMENT
NAME_REF
SUPER_KW "super"
COLON2 "::"
PATH_SEGMENT
NAME_REF
IDENT "foo"
SEMICOLON ";"
WHITESPACE " "
R_CURLY "}"
WHITESPACE "\n"
2 changes: 1 addition & 1 deletion crates/parser/test_data/parser/inline/ok/let_stmt.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fn f() { let x: i32 = 92; }
fn f() { let x: i32 = 92; super let y; super::foo; }
2 changes: 1 addition & 1 deletion crates/syntax/rust.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ Stmt =
| LetStmt

LetStmt =
Attr* 'let' Pat (':' Type)?
Attr* 'super'? 'let' Pat (':' Type)?
'=' initializer:Expr
LetElse?
';'
Expand Down
2 changes: 2 additions & 0 deletions crates/syntax/src/ast/generated/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,8 @@ impl LetStmt {
pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) }
#[inline]
pub fn let_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![let]) }
#[inline]
pub fn super_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![super]) }
}
pub struct Lifetime {
pub(crate) syntax: SyntaxNode,
Expand Down