5626: Minor r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-07-31 16:12:01 +00:00 committed by GitHub
commit 98975a772a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 79 deletions

View file

@ -241,7 +241,6 @@ fn get_tail_expr_from_block(expr: &Expr) -> Option<Vec<NodeType>> {
Expr::ArrayExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), Expr::ArrayExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::ParenExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), Expr::ParenExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::PathExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), Expr::PathExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::Label(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::RecordExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), Expr::RecordExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::IndexExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), Expr::IndexExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),
Expr::MethodCallExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]), Expr::MethodCallExpr(expr) => Some(vec![NodeType::Leaf(expr.syntax().clone())]),

View file

@ -569,9 +569,6 @@ impl ExprCollector<'_> {
} }
} }
} }
// FIXME implement HIR for these:
ast::Expr::Label(_e) => self.alloc_expr(Expr::Missing, syntax_ptr),
} }
} }

View file

@ -624,6 +624,19 @@ impl CastExpr {
pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) } pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ClosureExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for ClosureExpr {}
impl ClosureExpr {
pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
pub fn move_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![move]) }
pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ContinueExpr { pub struct ContinueExpr {
pub(crate) syntax: SyntaxNode, pub(crate) syntax: SyntaxNode,
} }
@ -690,28 +703,6 @@ impl IndexExpr {
pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) } pub fn r_brack_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![']']) }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Label {
pub(crate) syntax: SyntaxNode,
}
impl Label {
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
support::token(&self.syntax, T![lifetime])
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ClosureExpr {
pub(crate) syntax: SyntaxNode,
}
impl ast::AttrsOwner for ClosureExpr {}
impl ClosureExpr {
pub fn static_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![static]) }
pub fn async_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![async]) }
pub fn move_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![move]) }
pub fn param_list(&self) -> Option<ParamList> { support::child(&self.syntax) }
pub fn ret_type(&self) -> Option<RetType> { support::child(&self.syntax) }
pub fn body(&self) -> Option<Expr> { support::child(&self.syntax) }
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct LoopExpr { pub struct LoopExpr {
pub(crate) syntax: SyntaxNode, pub(crate) syntax: SyntaxNode,
} }
@ -835,6 +826,15 @@ impl WhileExpr {
pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) } pub fn condition(&self) -> Option<Condition> { support::child(&self.syntax) }
} }
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Label {
pub(crate) syntax: SyntaxNode,
}
impl Label {
pub fn lifetime_token(&self) -> Option<SyntaxToken> {
support::token(&self.syntax, T![lifetime])
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct RecordExprFieldList { pub struct RecordExprFieldList {
pub(crate) syntax: SyntaxNode, pub(crate) syntax: SyntaxNode,
} }
@ -1337,14 +1337,13 @@ pub enum Expr {
BreakExpr(BreakExpr), BreakExpr(BreakExpr),
CallExpr(CallExpr), CallExpr(CallExpr),
CastExpr(CastExpr), CastExpr(CastExpr),
ClosureExpr(ClosureExpr),
ContinueExpr(ContinueExpr), ContinueExpr(ContinueExpr),
EffectExpr(EffectExpr), EffectExpr(EffectExpr),
FieldExpr(FieldExpr), FieldExpr(FieldExpr),
ForExpr(ForExpr), ForExpr(ForExpr),
IfExpr(IfExpr), IfExpr(IfExpr),
IndexExpr(IndexExpr), IndexExpr(IndexExpr),
Label(Label),
ClosureExpr(ClosureExpr),
Literal(Literal), Literal(Literal),
LoopExpr(LoopExpr), LoopExpr(LoopExpr),
MacroCall(MacroCall), MacroCall(MacroCall),
@ -2017,6 +2016,17 @@ impl AstNode for CastExpr {
} }
fn syntax(&self) -> &SyntaxNode { &self.syntax } fn syntax(&self) -> &SyntaxNode { &self.syntax }
} }
impl AstNode for ClosureExpr {
fn can_cast(kind: SyntaxKind) -> bool { kind == CLOSURE_EXPR }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for ContinueExpr { impl AstNode for ContinueExpr {
fn can_cast(kind: SyntaxKind) -> bool { kind == CONTINUE_EXPR } fn can_cast(kind: SyntaxKind) -> bool { kind == CONTINUE_EXPR }
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
@ -2083,28 +2093,6 @@ impl AstNode for IndexExpr {
} }
fn syntax(&self) -> &SyntaxNode { &self.syntax } fn syntax(&self) -> &SyntaxNode { &self.syntax }
} }
impl AstNode for Label {
fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for ClosureExpr {
fn can_cast(kind: SyntaxKind) -> bool { kind == CLOSURE_EXPR }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for LoopExpr { impl AstNode for LoopExpr {
fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR } fn can_cast(kind: SyntaxKind) -> bool { kind == LOOP_EXPR }
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
@ -2248,6 +2236,17 @@ impl AstNode for WhileExpr {
} }
fn syntax(&self) -> &SyntaxNode { &self.syntax } fn syntax(&self) -> &SyntaxNode { &self.syntax }
} }
impl AstNode for Label {
fn can_cast(kind: SyntaxKind) -> bool { kind == LABEL }
fn cast(syntax: SyntaxNode) -> Option<Self> {
if Self::can_cast(syntax.kind()) {
Some(Self { syntax })
} else {
None
}
}
fn syntax(&self) -> &SyntaxNode { &self.syntax }
}
impl AstNode for RecordExprFieldList { impl AstNode for RecordExprFieldList {
fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD_LIST } fn can_cast(kind: SyntaxKind) -> bool { kind == RECORD_EXPR_FIELD_LIST }
fn cast(syntax: SyntaxNode) -> Option<Self> { fn cast(syntax: SyntaxNode) -> Option<Self> {
@ -3086,6 +3085,9 @@ impl From<CallExpr> for Expr {
impl From<CastExpr> for Expr { impl From<CastExpr> for Expr {
fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) } fn from(node: CastExpr) -> Expr { Expr::CastExpr(node) }
} }
impl From<ClosureExpr> for Expr {
fn from(node: ClosureExpr) -> Expr { Expr::ClosureExpr(node) }
}
impl From<ContinueExpr> for Expr { impl From<ContinueExpr> for Expr {
fn from(node: ContinueExpr) -> Expr { Expr::ContinueExpr(node) } fn from(node: ContinueExpr) -> Expr { Expr::ContinueExpr(node) }
} }
@ -3104,12 +3106,6 @@ impl From<IfExpr> for Expr {
impl From<IndexExpr> for Expr { impl From<IndexExpr> for Expr {
fn from(node: IndexExpr) -> Expr { Expr::IndexExpr(node) } fn from(node: IndexExpr) -> Expr { Expr::IndexExpr(node) }
} }
impl From<Label> for Expr {
fn from(node: Label) -> Expr { Expr::Label(node) }
}
impl From<ClosureExpr> for Expr {
fn from(node: ClosureExpr) -> Expr { Expr::ClosureExpr(node) }
}
impl From<Literal> for Expr { impl From<Literal> for Expr {
fn from(node: Literal) -> Expr { Expr::Literal(node) } fn from(node: Literal) -> Expr { Expr::Literal(node) }
} }
@ -3159,8 +3155,8 @@ impl AstNode for Expr {
fn can_cast(kind: SyntaxKind) -> bool { fn can_cast(kind: SyntaxKind) -> bool {
match kind { match kind {
ARRAY_EXPR | AWAIT_EXPR | BIN_EXPR | BLOCK_EXPR | BOX_EXPR | BREAK_EXPR | CALL_EXPR ARRAY_EXPR | AWAIT_EXPR | BIN_EXPR | BLOCK_EXPR | BOX_EXPR | BREAK_EXPR | CALL_EXPR
| CAST_EXPR | CONTINUE_EXPR | EFFECT_EXPR | FIELD_EXPR | FOR_EXPR | IF_EXPR | CAST_EXPR | CLOSURE_EXPR | CONTINUE_EXPR | EFFECT_EXPR | FIELD_EXPR | FOR_EXPR
| INDEX_EXPR | LABEL | CLOSURE_EXPR | LITERAL | LOOP_EXPR | MACRO_CALL | MATCH_EXPR | IF_EXPR | INDEX_EXPR | LITERAL | LOOP_EXPR | MACRO_CALL | MATCH_EXPR
| METHOD_CALL_EXPR | PAREN_EXPR | PATH_EXPR | PREFIX_EXPR | RANGE_EXPR | METHOD_CALL_EXPR | PAREN_EXPR | PATH_EXPR | PREFIX_EXPR | RANGE_EXPR
| RECORD_EXPR | REF_EXPR | RETURN_EXPR | TRY_EXPR | TUPLE_EXPR | WHILE_EXPR => true, | RECORD_EXPR | REF_EXPR | RETURN_EXPR | TRY_EXPR | TUPLE_EXPR | WHILE_EXPR => true,
_ => false, _ => false,
@ -3176,14 +3172,13 @@ impl AstNode for Expr {
BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }), BREAK_EXPR => Expr::BreakExpr(BreakExpr { syntax }),
CALL_EXPR => Expr::CallExpr(CallExpr { syntax }), CALL_EXPR => Expr::CallExpr(CallExpr { syntax }),
CAST_EXPR => Expr::CastExpr(CastExpr { syntax }), CAST_EXPR => Expr::CastExpr(CastExpr { syntax }),
CLOSURE_EXPR => Expr::ClosureExpr(ClosureExpr { syntax }),
CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }), CONTINUE_EXPR => Expr::ContinueExpr(ContinueExpr { syntax }),
EFFECT_EXPR => Expr::EffectExpr(EffectExpr { syntax }), EFFECT_EXPR => Expr::EffectExpr(EffectExpr { syntax }),
FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }), FIELD_EXPR => Expr::FieldExpr(FieldExpr { syntax }),
FOR_EXPR => Expr::ForExpr(ForExpr { syntax }), FOR_EXPR => Expr::ForExpr(ForExpr { syntax }),
IF_EXPR => Expr::IfExpr(IfExpr { syntax }), IF_EXPR => Expr::IfExpr(IfExpr { syntax }),
INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }), INDEX_EXPR => Expr::IndexExpr(IndexExpr { syntax }),
LABEL => Expr::Label(Label { syntax }),
CLOSURE_EXPR => Expr::ClosureExpr(ClosureExpr { syntax }),
LITERAL => Expr::Literal(Literal { syntax }), LITERAL => Expr::Literal(Literal { syntax }),
LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }), LOOP_EXPR => Expr::LoopExpr(LoopExpr { syntax }),
MACRO_CALL => Expr::MacroCall(MacroCall { syntax }), MACRO_CALL => Expr::MacroCall(MacroCall { syntax }),
@ -3213,14 +3208,13 @@ impl AstNode for Expr {
Expr::BreakExpr(it) => &it.syntax, Expr::BreakExpr(it) => &it.syntax,
Expr::CallExpr(it) => &it.syntax, Expr::CallExpr(it) => &it.syntax,
Expr::CastExpr(it) => &it.syntax, Expr::CastExpr(it) => &it.syntax,
Expr::ClosureExpr(it) => &it.syntax,
Expr::ContinueExpr(it) => &it.syntax, Expr::ContinueExpr(it) => &it.syntax,
Expr::EffectExpr(it) => &it.syntax, Expr::EffectExpr(it) => &it.syntax,
Expr::FieldExpr(it) => &it.syntax, Expr::FieldExpr(it) => &it.syntax,
Expr::ForExpr(it) => &it.syntax, Expr::ForExpr(it) => &it.syntax,
Expr::IfExpr(it) => &it.syntax, Expr::IfExpr(it) => &it.syntax,
Expr::IndexExpr(it) => &it.syntax, Expr::IndexExpr(it) => &it.syntax,
Expr::Label(it) => &it.syntax,
Expr::ClosureExpr(it) => &it.syntax,
Expr::Literal(it) => &it.syntax, Expr::Literal(it) => &it.syntax,
Expr::LoopExpr(it) => &it.syntax, Expr::LoopExpr(it) => &it.syntax,
Expr::MacroCall(it) => &it.syntax, Expr::MacroCall(it) => &it.syntax,
@ -3715,6 +3709,11 @@ impl std::fmt::Display for CastExpr {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
} }
impl std::fmt::Display for ClosureExpr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for ContinueExpr { impl std::fmt::Display for ContinueExpr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
@ -3745,16 +3744,6 @@ impl std::fmt::Display for IndexExpr {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
} }
impl std::fmt::Display for Label {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for ClosureExpr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for LoopExpr { impl std::fmt::Display for LoopExpr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
@ -3820,6 +3809,11 @@ impl std::fmt::Display for WhileExpr {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)
} }
} }
impl std::fmt::Display for Label {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f)
}
}
impl std::fmt::Display for RecordExprFieldList { impl std::fmt::Display for RecordExprFieldList {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.syntax(), f) std::fmt::Display::fmt(self.syntax(), f)

View file

@ -215,14 +215,13 @@ Expr =
| BreakExpr | BreakExpr
| CallExpr | CallExpr
| CastExpr | CastExpr
| ClosureExpr
| ContinueExpr | ContinueExpr
| EffectExpr | EffectExpr
| FieldExpr | FieldExpr
| ForExpr | ForExpr
| IfExpr | IfExpr
| IndexExpr | IndexExpr
| Label
| ClosureExpr
| Literal | Literal
| LoopExpr | LoopExpr
| MacroCall | MacroCall
@ -340,7 +339,7 @@ ForExpr =
WhileExpr = WhileExpr =
Attr* Label? 'while' Condition Attr* Label? 'while' Condition
loop_body:BlockExpr? loop_body:BlockExpr
Label = Label =
'lifetime' 'lifetime'