aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-10 08:04:49 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-10 08:04:49 +0000
commita8a4f8012e525c816aedf5b0bc51e3ad4c13a0ab (patch)
treecd2cd9080114eee7c079b2120e27fb5655cdb947 /crates/ra_syntax/src/ast
parent8bcb84ea681f982946a24b5e000ddde58247adba (diff)
parentc098a3fda52ef0b02188abfa91adcd67e82c0c02 (diff)
Merge #773
773: Crash fixes r=matklad a=flodiebold This fixes a bunch of crashes found while running type inference on the whole rustc repo :sweat_smile: - avoid infinite recursion with ref bind patterns - avoid another infinite recursion - handle literal patterns, add a new LITERAL_PAT syntax node for this - fix an expect that's wrong on some invalid code Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/ast')
-rw-r--r--crates/ra_syntax/src/ast/generated.rs37
1 files changed, 36 insertions, 1 deletions
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index 60314d245..256277609 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -1821,6 +1821,38 @@ impl LiteralExpr {
1821 1821
1822impl LiteralExpr {} 1822impl LiteralExpr {}
1823 1823
1824// LiteralPat
1825#[derive(Debug, PartialEq, Eq, Hash)]
1826#[repr(transparent)]
1827pub struct LiteralPat {
1828 pub(crate) syntax: SyntaxNode,
1829}
1830unsafe impl TransparentNewType for LiteralPat {
1831 type Repr = rowan::SyntaxNode<RaTypes>;
1832}
1833
1834impl AstNode for LiteralPat {
1835 fn cast(syntax: &SyntaxNode) -> Option<&Self> {
1836 match syntax.kind() {
1837 LITERAL_PAT => Some(LiteralPat::from_repr(syntax.into_repr())),
1838 _ => None,
1839 }
1840 }
1841 fn syntax(&self) -> &SyntaxNode { &self.syntax }
1842}
1843
1844impl ToOwned for LiteralPat {
1845 type Owned = TreeArc<LiteralPat>;
1846 fn to_owned(&self) -> TreeArc<LiteralPat> { TreeArc::cast(self.syntax.to_owned()) }
1847}
1848
1849
1850impl LiteralPat {
1851 pub fn literal(&self) -> Option<&Literal> {
1852 super::child_opt(self)
1853 }
1854}
1855
1824// LoopExpr 1856// LoopExpr
1825#[derive(Debug, PartialEq, Eq, Hash)] 1857#[derive(Debug, PartialEq, Eq, Hash)]
1826#[repr(transparent)] 1858#[repr(transparent)]
@@ -2594,6 +2626,7 @@ pub enum PatKind<'a> {
2594 TuplePat(&'a TuplePat), 2626 TuplePat(&'a TuplePat),
2595 SlicePat(&'a SlicePat), 2627 SlicePat(&'a SlicePat),
2596 RangePat(&'a RangePat), 2628 RangePat(&'a RangePat),
2629 LiteralPat(&'a LiteralPat),
2597} 2630}
2598 2631
2599impl AstNode for Pat { 2632impl AstNode for Pat {
@@ -2607,7 +2640,8 @@ impl AstNode for Pat {
2607 | TUPLE_STRUCT_PAT 2640 | TUPLE_STRUCT_PAT
2608 | TUPLE_PAT 2641 | TUPLE_PAT
2609 | SLICE_PAT 2642 | SLICE_PAT
2610 | RANGE_PAT => Some(Pat::from_repr(syntax.into_repr())), 2643 | RANGE_PAT
2644 | LITERAL_PAT => Some(Pat::from_repr(syntax.into_repr())),
2611 _ => None, 2645 _ => None,
2612 } 2646 }
2613 } 2647 }
@@ -2631,6 +2665,7 @@ impl Pat {
2631 TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(&self.syntax).unwrap()), 2665 TUPLE_PAT => PatKind::TuplePat(TuplePat::cast(&self.syntax).unwrap()),
2632 SLICE_PAT => PatKind::SlicePat(SlicePat::cast(&self.syntax).unwrap()), 2666 SLICE_PAT => PatKind::SlicePat(SlicePat::cast(&self.syntax).unwrap()),
2633 RANGE_PAT => PatKind::RangePat(RangePat::cast(&self.syntax).unwrap()), 2667 RANGE_PAT => PatKind::RangePat(RangePat::cast(&self.syntax).unwrap()),
2668 LITERAL_PAT => PatKind::LiteralPat(LiteralPat::cast(&self.syntax).unwrap()),
2634 _ => unreachable!(), 2669 _ => unreachable!(),
2635 } 2670 }
2636 } 2671 }