mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-20 19:52:48 +00:00
add await expr to ast
This commit is contained in:
parent
2830d1376b
commit
5ac9f5cdc7
@ -220,6 +220,9 @@ pub enum Expr {
|
||||
expr: ExprId,
|
||||
name: Name,
|
||||
},
|
||||
Await {
|
||||
expr: ExprId,
|
||||
},
|
||||
Try {
|
||||
expr: ExprId,
|
||||
},
|
||||
@ -359,6 +362,7 @@ impl Expr {
|
||||
f(*rhs);
|
||||
}
|
||||
Expr::Field { expr, .. }
|
||||
| Expr::Await { expr }
|
||||
| Expr::Try { expr }
|
||||
| Expr::Cast { expr, .. }
|
||||
| Expr::Ref { expr, .. }
|
||||
@ -729,6 +733,10 @@ where
|
||||
};
|
||||
self.alloc_expr(Expr::Field { expr, name }, syntax_ptr)
|
||||
}
|
||||
ast::ExprKind::AwaitExpr(e) => {
|
||||
let expr = self.collect_expr_opt(e.expr());
|
||||
self.alloc_expr(Expr::Await { expr }, syntax_ptr)
|
||||
}
|
||||
ast::ExprKind::TryExpr(e) => {
|
||||
let expr = self.collect_expr_opt(e.expr());
|
||||
self.alloc_expr(Expr::Try { expr }, syntax_ptr)
|
||||
|
@ -1114,6 +1114,9 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
||||
.unwrap_or(Ty::Unknown);
|
||||
self.insert_type_vars(ty)
|
||||
}
|
||||
Expr::Await { .. } => {
|
||||
Ty::Unknown
|
||||
}
|
||||
Expr::Try { expr } => {
|
||||
let inner_ty = self.infer_expr(*expr, &Expectation::none());
|
||||
let ty = match self.resolve_ops_try_ok() {
|
||||
|
@ -175,6 +175,32 @@ impl Attr {
|
||||
}
|
||||
}
|
||||
|
||||
// AwaitExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct AwaitExpr {
|
||||
pub(crate) syntax: SyntaxNode,
|
||||
}
|
||||
|
||||
impl AstNode for AwaitExpr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
AWAIT_EXPR => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
if Self::can_cast(syntax.kind()) { Some(AwaitExpr { syntax }) } else { None }
|
||||
}
|
||||
fn syntax(&self) -> &SyntaxNode { &self.syntax }
|
||||
}
|
||||
|
||||
|
||||
impl AwaitExpr {
|
||||
pub fn expr(&self) -> Option<Expr> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
||||
// BinExpr
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct BinExpr {
|
||||
@ -566,7 +592,7 @@ pub struct Expr {
|
||||
impl AstNode for Expr {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
| TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR | FIELD_EXPR | TRY_EXPR | TRY_BLOCK_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => true,
|
||||
| TUPLE_EXPR | ARRAY_EXPR | PAREN_EXPR | PATH_EXPR | LAMBDA_EXPR | IF_EXPR | LOOP_EXPR | FOR_EXPR | WHILE_EXPR | CONTINUE_EXPR | BREAK_EXPR | LABEL | BLOCK_EXPR | RETURN_EXPR | MATCH_EXPR | STRUCT_LIT | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR | FIELD_EXPR | AWAIT_EXPR | TRY_EXPR | TRY_BLOCK_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR | BIN_EXPR | LITERAL | MACRO_CALL => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -599,6 +625,7 @@ pub enum ExprKind {
|
||||
IndexExpr(IndexExpr),
|
||||
MethodCallExpr(MethodCallExpr),
|
||||
FieldExpr(FieldExpr),
|
||||
AwaitExpr(AwaitExpr),
|
||||
TryExpr(TryExpr),
|
||||
TryBlockExpr(TryBlockExpr),
|
||||
CastExpr(CastExpr),
|
||||
@ -669,6 +696,9 @@ impl From<MethodCallExpr> for Expr {
|
||||
impl From<FieldExpr> for Expr {
|
||||
fn from(n: FieldExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
}
|
||||
impl From<AwaitExpr> for Expr {
|
||||
fn from(n: AwaitExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
}
|
||||
impl From<TryExpr> for Expr {
|
||||
fn from(n: TryExpr) -> Expr { Expr { syntax: n.syntax } }
|
||||
}
|
||||
@ -719,6 +749,7 @@ impl Expr {
|
||||
INDEX_EXPR => ExprKind::IndexExpr(IndexExpr::cast(self.syntax.clone()).unwrap()),
|
||||
METHOD_CALL_EXPR => ExprKind::MethodCallExpr(MethodCallExpr::cast(self.syntax.clone()).unwrap()),
|
||||
FIELD_EXPR => ExprKind::FieldExpr(FieldExpr::cast(self.syntax.clone()).unwrap()),
|
||||
AWAIT_EXPR => ExprKind::AwaitExpr(AwaitExpr::cast(self.syntax.clone()).unwrap()),
|
||||
TRY_EXPR => ExprKind::TryExpr(TryExpr::cast(self.syntax.clone()).unwrap()),
|
||||
TRY_BLOCK_EXPR => ExprKind::TryBlockExpr(TryBlockExpr::cast(self.syntax.clone()).unwrap()),
|
||||
CAST_EXPR => ExprKind::CastExpr(CastExpr::cast(self.syntax.clone()).unwrap()),
|
||||
|
@ -477,6 +477,7 @@ Grammar(
|
||||
),
|
||||
"IndexExpr": (),
|
||||
"FieldExpr": (options: ["Expr", "NameRef"]),
|
||||
"AwaitExpr": (options: ["Expr"]),
|
||||
"TryExpr": (options: ["Expr"]),
|
||||
"CastExpr": (options: ["Expr", "TypeRef"]),
|
||||
"RefExpr": (options: ["Expr"]),
|
||||
@ -508,6 +509,7 @@ Grammar(
|
||||
"IndexExpr",
|
||||
"MethodCallExpr",
|
||||
"FieldExpr",
|
||||
"AwaitExpr",
|
||||
"TryExpr",
|
||||
"TryBlockExpr",
|
||||
"CastExpr",
|
||||
|
Loading…
Reference in New Issue
Block a user