diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-26 21:41:27 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-26 21:41:27 +0000 |
commit | e40d8d40321b191ee82b8b07910f8a0898c8914c (patch) | |
tree | 7adcdf5fd1a09bdb18776e210a4686342979cbe6 /crates/ra_syntax/src/ast | |
parent | 99b032b0f6b3f718ee9500655f1149dc33eac610 (diff) | |
parent | 619af1e22cb71b981fde4cedbf6ebce9b3488028 (diff) |
Merge #683
683: fix AST for if expressions r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 3ace6533c..4f8723ae7 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -660,6 +660,50 @@ impl ToOwned for DynTraitType { | |||
660 | 660 | ||
661 | impl DynTraitType {} | 661 | impl DynTraitType {} |
662 | 662 | ||
663 | // ElseBranch | ||
664 | #[derive(Debug, PartialEq, Eq, Hash)] | ||
665 | #[repr(transparent)] | ||
666 | pub struct ElseBranch { | ||
667 | pub(crate) syntax: SyntaxNode, | ||
668 | } | ||
669 | unsafe impl TransparentNewType for ElseBranch { | ||
670 | type Repr = rowan::SyntaxNode<RaTypes>; | ||
671 | } | ||
672 | |||
673 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
674 | pub enum ElseBranchKind<'a> { | ||
675 | Block(&'a Block), | ||
676 | IfExpr(&'a IfExpr), | ||
677 | } | ||
678 | |||
679 | impl AstNode for ElseBranch { | ||
680 | fn cast(syntax: &SyntaxNode) -> Option<&Self> { | ||
681 | match syntax.kind() { | ||
682 | | BLOCK | ||
683 | | IF_EXPR => Some(ElseBranch::from_repr(syntax.into_repr())), | ||
684 | _ => None, | ||
685 | } | ||
686 | } | ||
687 | fn syntax(&self) -> &SyntaxNode { &self.syntax } | ||
688 | } | ||
689 | |||
690 | impl ToOwned for ElseBranch { | ||
691 | type Owned = TreeArc<ElseBranch>; | ||
692 | fn to_owned(&self) -> TreeArc<ElseBranch> { TreeArc::cast(self.syntax.to_owned()) } | ||
693 | } | ||
694 | |||
695 | impl ElseBranch { | ||
696 | pub fn kind(&self) -> ElseBranchKind { | ||
697 | match self.syntax.kind() { | ||
698 | BLOCK => ElseBranchKind::Block(Block::cast(&self.syntax).unwrap()), | ||
699 | IF_EXPR => ElseBranchKind::IfExpr(IfExpr::cast(&self.syntax).unwrap()), | ||
700 | _ => unreachable!(), | ||
701 | } | ||
702 | } | ||
703 | } | ||
704 | |||
705 | impl ElseBranch {} | ||
706 | |||
663 | // EnumDef | 707 | // EnumDef |
664 | #[derive(Debug, PartialEq, Eq, Hash)] | 708 | #[derive(Debug, PartialEq, Eq, Hash)] |
665 | #[repr(transparent)] | 709 | #[repr(transparent)] |