aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_hir/src/expr.rs1
-rw-r--r--crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_3.snap13
-rw-r--r--crates/ra_hir/src/ty/tests.rs15
-rw-r--r--crates/ra_syntax/src/ast/generated.rs37
-rw-r--r--crates/ra_syntax/src/grammar.ron3
-rw-r--r--crates/ra_syntax/src/grammar/patterns.rs41
-rw-r--r--crates/ra_syntax/src/syntax_kinds/generated.rs2
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0055_literal_pattern.txt22
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0058_range_pat.txt30
-rw-r--r--crates/ra_syntax/tests/data/parser/ok/0035_weird_exprs.txt10
10 files changed, 133 insertions, 41 deletions
diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs
index 4e61d87ff..bf423d3d8 100644
--- a/crates/ra_hir/src/expr.rs
+++ b/crates/ra_hir/src/expr.rs
@@ -850,6 +850,7 @@ impl ExprCollector {
850 } 850 }
851 851
852 // TODO: implement 852 // TODO: implement
853 ast::PatKind::LiteralPat(_) => Pat::Missing,
853 ast::PatKind::SlicePat(_) | ast::PatKind::RangePat(_) => Pat::Missing, 854 ast::PatKind::SlicePat(_) | ast::PatKind::RangePat(_) => Pat::Missing,
854 }; 855 };
855 let syntax_ptr = SyntaxNodePtr::new(pat.syntax()); 856 let syntax_ptr = SyntaxNodePtr::new(pat.syntax());
diff --git a/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_3.snap b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_3.snap
new file mode 100644
index 000000000..d15b77e17
--- /dev/null
+++ b/crates/ra_hir/src/ty/snapshots/tests__infer_std_crash_3.snap
@@ -0,0 +1,13 @@
1---
2created: "2019-02-09T18:02:37.377591660Z"
3creator: [email protected]
4source: crates/ra_hir/src/ty/tests.rs
5expression: "&result"
6---
7[18; 102) '{ ... } }': ()
8[24; 100) 'match ... }': ()
9[42; 88) 'SizeSk...tail }': [unknown]
10[76; 80) 'true': [unknown]
11[82; 86) 'tail': [unknown]
12[92; 94) '{}': ()
13
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index 3139eba0b..e0b5a6471 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -663,6 +663,21 @@ fn test_line_buffer() {
663 ); 663 );
664} 664}
665 665
666#[test]
667fn infer_std_crash_3() {
668 // taken from rustc
669 check_inference(
670 "infer_std_crash_3",
671 r#"
672pub fn compute() {
673 match _ {
674 SizeSkeleton::Pointer { non_zero: true, tail } => {}
675 }
676}
677"#,
678 );
679}
680
666fn infer(content: &str) -> String { 681fn infer(content: &str) -> String {
667 let (db, _, file_id) = MockDatabase::with_single_file(content); 682 let (db, _, file_id) = MockDatabase::with_single_file(content);
668 let source_file = db.parse(file_id); 683 let source_file = db.parse(file_id);
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 }
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index 046db5885..d428bc595 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -161,6 +161,7 @@ Grammar(
161 "TUPLE_PAT", 161 "TUPLE_PAT",
162 "SLICE_PAT", 162 "SLICE_PAT",
163 "RANGE_PAT", 163 "RANGE_PAT",
164 "LITERAL_PAT",
164 165
165 // atoms 166 // atoms
166 "TUPLE_EXPR", 167 "TUPLE_EXPR",
@@ -524,6 +525,7 @@ Grammar(
524 "TuplePat": ( collections: [["args", "Pat"]] ), 525 "TuplePat": ( collections: [["args", "Pat"]] ),
525 "SlicePat": (), 526 "SlicePat": (),
526 "RangePat": (), 527 "RangePat": (),
528 "LiteralPat": (options: ["Literal"]),
527 529
528 "Pat": ( 530 "Pat": (
529 enum: [ 531 enum: [
@@ -536,6 +538,7 @@ Grammar(
536 "TuplePat", 538 "TuplePat",
537 "SlicePat", 539 "SlicePat",
538 "RangePat", 540 "RangePat",
541 "LiteralPat",
539 ], 542 ],
540 ), 543 ),
541 544
diff --git a/crates/ra_syntax/src/grammar/patterns.rs b/crates/ra_syntax/src/grammar/patterns.rs
index f3f400ae0..9d7da639d 100644
--- a/crates/ra_syntax/src/grammar/patterns.rs
+++ b/crates/ra_syntax/src/grammar/patterns.rs
@@ -43,21 +43,8 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
43 return Some(path_pat(p)); 43 return Some(path_pat(p));
44 } 44 }
45 45
46 // test literal_pattern 46 if is_literal_pat_start(p) {
47 // fn main() { 47 return Some(literal_pat(p));
48 // match () {
49 // -1 => (),
50 // 92 => (),
51 // 'c' => (),
52 // "hello" => (),
53 // }
54 // }
55 if p.at(MINUS) && (p.nth(1) == INT_NUMBER || p.nth(1) == FLOAT_NUMBER) {
56 p.bump();
57 }
58
59 if let Some(m) = expressions::literal(p) {
60 return Some(m);
61 } 48 }
62 49
63 let m = match la0 { 50 let m = match la0 {
@@ -73,6 +60,30 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
73 Some(m) 60 Some(m)
74} 61}
75 62
63fn is_literal_pat_start(p: &mut Parser) -> bool {
64 p.at(MINUS) && (p.nth(1) == INT_NUMBER || p.nth(1) == FLOAT_NUMBER)
65 || p.at_ts(expressions::LITERAL_FIRST)
66}
67
68// test literal_pattern
69// fn main() {
70// match () {
71// -1 => (),
72// 92 => (),
73// 'c' => (),
74// "hello" => (),
75// }
76// }
77fn literal_pat(p: &mut Parser) -> CompletedMarker {
78 assert!(is_literal_pat_start(p));
79 let m = p.start();
80 if p.at(MINUS) {
81 p.bump();
82 }
83 expressions::literal(p);
84 m.complete(p, LITERAL_PAT)
85}
86
76// test path_part 87// test path_part
77// fn foo() { 88// fn foo() {
78// let foo::Bar = (); 89// let foo::Bar = ();
diff --git a/crates/ra_syntax/src/syntax_kinds/generated.rs b/crates/ra_syntax/src/syntax_kinds/generated.rs
index fea513458..266b95bbb 100644
--- a/crates/ra_syntax/src/syntax_kinds/generated.rs
+++ b/crates/ra_syntax/src/syntax_kinds/generated.rs
@@ -157,6 +157,7 @@ pub enum SyntaxKind {
157 TUPLE_PAT, 157 TUPLE_PAT,
158 SLICE_PAT, 158 SLICE_PAT,
159 RANGE_PAT, 159 RANGE_PAT,
160 LITERAL_PAT,
160 TUPLE_EXPR, 161 TUPLE_EXPR,
161 ARRAY_EXPR, 162 ARRAY_EXPR,
162 PAREN_EXPR, 163 PAREN_EXPR,
@@ -493,6 +494,7 @@ impl SyntaxKind {
493 TUPLE_PAT => &SyntaxInfo { name: "TUPLE_PAT" }, 494 TUPLE_PAT => &SyntaxInfo { name: "TUPLE_PAT" },
494 SLICE_PAT => &SyntaxInfo { name: "SLICE_PAT" }, 495 SLICE_PAT => &SyntaxInfo { name: "SLICE_PAT" },
495 RANGE_PAT => &SyntaxInfo { name: "RANGE_PAT" }, 496 RANGE_PAT => &SyntaxInfo { name: "RANGE_PAT" },
497 LITERAL_PAT => &SyntaxInfo { name: "LITERAL_PAT" },
496 TUPLE_EXPR => &SyntaxInfo { name: "TUPLE_EXPR" }, 498 TUPLE_EXPR => &SyntaxInfo { name: "TUPLE_EXPR" },
497 ARRAY_EXPR => &SyntaxInfo { name: "ARRAY_EXPR" }, 499 ARRAY_EXPR => &SyntaxInfo { name: "ARRAY_EXPR" },
498 PAREN_EXPR => &SyntaxInfo { name: "PAREN_EXPR" }, 500 PAREN_EXPR => &SyntaxInfo { name: "PAREN_EXPR" },
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0055_literal_pattern.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0055_literal_pattern.txt
index 71d62eaba..51c5ab7f2 100644
--- a/crates/ra_syntax/tests/data/parser/inline/ok/0055_literal_pattern.txt
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0055_literal_pattern.txt
@@ -22,9 +22,10 @@ SOURCE_FILE@[0; 113)
22 L_CURLY@[25; 26) 22 L_CURLY@[25; 26)
23 WHITESPACE@[26; 35) 23 WHITESPACE@[26; 35)
24 MATCH_ARM@[35; 43) 24 MATCH_ARM@[35; 43)
25 MINUS@[35; 36) 25 LITERAL_PAT@[35; 37)
26 LITERAL@[36; 37) 26 MINUS@[35; 36)
27 INT_NUMBER@[36; 37) "1" 27 LITERAL@[36; 37)
28 INT_NUMBER@[36; 37) "1"
28 WHITESPACE@[37; 38) 29 WHITESPACE@[37; 38)
29 FAT_ARROW@[38; 40) 30 FAT_ARROW@[38; 40)
30 WHITESPACE@[40; 41) 31 WHITESPACE@[40; 41)
@@ -34,8 +35,9 @@ SOURCE_FILE@[0; 113)
34 COMMA@[43; 44) 35 COMMA@[43; 44)
35 WHITESPACE@[44; 53) 36 WHITESPACE@[44; 53)
36 MATCH_ARM@[53; 61) 37 MATCH_ARM@[53; 61)
37 LITERAL@[53; 55) 38 LITERAL_PAT@[53; 55)
38 INT_NUMBER@[53; 55) "92" 39 LITERAL@[53; 55)
40 INT_NUMBER@[53; 55) "92"
39 WHITESPACE@[55; 56) 41 WHITESPACE@[55; 56)
40 FAT_ARROW@[56; 58) 42 FAT_ARROW@[56; 58)
41 WHITESPACE@[58; 59) 43 WHITESPACE@[58; 59)
@@ -45,8 +47,9 @@ SOURCE_FILE@[0; 113)
45 COMMA@[61; 62) 47 COMMA@[61; 62)
46 WHITESPACE@[62; 71) 48 WHITESPACE@[62; 71)
47 MATCH_ARM@[71; 80) 49 MATCH_ARM@[71; 80)
48 LITERAL@[71; 74) 50 LITERAL_PAT@[71; 74)
49 CHAR@[71; 74) 51 LITERAL@[71; 74)
52 CHAR@[71; 74)
50 WHITESPACE@[74; 75) 53 WHITESPACE@[74; 75)
51 FAT_ARROW@[75; 77) 54 FAT_ARROW@[75; 77)
52 WHITESPACE@[77; 78) 55 WHITESPACE@[77; 78)
@@ -56,8 +59,9 @@ SOURCE_FILE@[0; 113)
56 COMMA@[80; 81) 59 COMMA@[80; 81)
57 WHITESPACE@[81; 90) 60 WHITESPACE@[81; 90)
58 MATCH_ARM@[90; 103) 61 MATCH_ARM@[90; 103)
59 LITERAL@[90; 97) 62 LITERAL_PAT@[90; 97)
60 STRING@[90; 97) 63 LITERAL@[90; 97)
64 STRING@[90; 97)
61 WHITESPACE@[97; 98) 65 WHITESPACE@[97; 98)
62 FAT_ARROW@[98; 100) 66 FAT_ARROW@[98; 100)
63 WHITESPACE@[100; 101) 67 WHITESPACE@[100; 101)
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0058_range_pat.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0058_range_pat.txt
index d47f38903..de54c49e6 100644
--- a/crates/ra_syntax/tests/data/parser/inline/ok/0058_range_pat.txt
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0058_range_pat.txt
@@ -22,13 +22,15 @@ SOURCE_FILE@[0; 112)
22 WHITESPACE@[26; 35) 22 WHITESPACE@[26; 35)
23 MATCH_ARM@[35; 50) 23 MATCH_ARM@[35; 50)
24 RANGE_PAT@[35; 44) 24 RANGE_PAT@[35; 44)
25 LITERAL@[35; 36) 25 LITERAL_PAT@[35; 36)
26 INT_NUMBER@[35; 36) "0" 26 LITERAL@[35; 36)
27 INT_NUMBER@[35; 36) "0"
27 WHITESPACE@[36; 37) 28 WHITESPACE@[36; 37)
28 DOTDOTDOT@[37; 40) 29 DOTDOTDOT@[37; 40)
29 WHITESPACE@[40; 41) 30 WHITESPACE@[40; 41)
30 LITERAL@[41; 44) 31 LITERAL_PAT@[41; 44)
31 INT_NUMBER@[41; 44) "100" 32 LITERAL@[41; 44)
33 INT_NUMBER@[41; 44) "100"
32 WHITESPACE@[44; 45) 34 WHITESPACE@[44; 45)
33 FAT_ARROW@[45; 47) 35 FAT_ARROW@[45; 47)
34 WHITESPACE@[47; 48) 36 WHITESPACE@[47; 48)
@@ -39,13 +41,15 @@ SOURCE_FILE@[0; 112)
39 WHITESPACE@[51; 60) 41 WHITESPACE@[51; 60)
40 MATCH_ARM@[60; 77) 42 MATCH_ARM@[60; 77)
41 RANGE_PAT@[60; 71) 43 RANGE_PAT@[60; 71)
42 LITERAL@[60; 63) 44 LITERAL_PAT@[60; 63)
43 INT_NUMBER@[60; 63) "101" 45 LITERAL@[60; 63)
46 INT_NUMBER@[60; 63) "101"
44 WHITESPACE@[63; 64) 47 WHITESPACE@[63; 64)
45 DOTDOTEQ@[64; 67) 48 DOTDOTEQ@[64; 67)
46 WHITESPACE@[67; 68) 49 WHITESPACE@[67; 68)
47 LITERAL@[68; 71) 50 LITERAL_PAT@[68; 71)
48 INT_NUMBER@[68; 71) "200" 51 LITERAL@[68; 71)
52 INT_NUMBER@[68; 71) "200"
49 WHITESPACE@[71; 72) 53 WHITESPACE@[71; 72)
50 FAT_ARROW@[72; 74) 54 FAT_ARROW@[72; 74)
51 WHITESPACE@[74; 75) 55 WHITESPACE@[74; 75)
@@ -56,13 +60,15 @@ SOURCE_FILE@[0; 112)
56 WHITESPACE@[78; 87) 60 WHITESPACE@[78; 87)
57 MATCH_ARM@[87; 102) 61 MATCH_ARM@[87; 102)
58 RANGE_PAT@[87; 97) 62 RANGE_PAT@[87; 97)
59 LITERAL@[87; 90) 63 LITERAL_PAT@[87; 90)
60 INT_NUMBER@[87; 90) "200" 64 LITERAL@[87; 90)
65 INT_NUMBER@[87; 90) "200"
61 WHITESPACE@[90; 91) 66 WHITESPACE@[90; 91)
62 DOTDOT@[91; 93) 67 DOTDOT@[91; 93)
63 WHITESPACE@[93; 94) 68 WHITESPACE@[93; 94)
64 LITERAL@[94; 97) 69 LITERAL_PAT@[94; 97)
65 INT_NUMBER@[94; 97) "301" 70 LITERAL@[94; 97)
71 INT_NUMBER@[94; 97) "301"
66 FAT_ARROW@[97; 99) 72 FAT_ARROW@[97; 99)
67 WHITESPACE@[99; 100) 73 WHITESPACE@[99; 100)
68 TUPLE_EXPR@[100; 102) 74 TUPLE_EXPR@[100; 102)
diff --git a/crates/ra_syntax/tests/data/parser/ok/0035_weird_exprs.txt b/crates/ra_syntax/tests/data/parser/ok/0035_weird_exprs.txt
index 20932a837..f3987c3b7 100644
--- a/crates/ra_syntax/tests/data/parser/ok/0035_weird_exprs.txt
+++ b/crates/ra_syntax/tests/data/parser/ok/0035_weird_exprs.txt
@@ -456,8 +456,9 @@ SOURCE_FILE@[0; 3813)
456 L_CURLY@[930; 931) 456 L_CURLY@[930; 931)
457 WHITESPACE@[931; 952) 457 WHITESPACE@[931; 952)
458 MATCH_ARM@[952; 1147) 458 MATCH_ARM@[952; 1147)
459 LITERAL@[952; 953) 459 LITERAL_PAT@[952; 953)
460 INT_NUMBER@[952; 953) "1" 460 LITERAL@[952; 953)
461 INT_NUMBER@[952; 953) "1"
461 WHITESPACE@[953; 954) 462 WHITESPACE@[953; 954)
462 FAT_ARROW@[954; 956) 463 FAT_ARROW@[954; 956)
463 WHITESPACE@[956; 957) 464 WHITESPACE@[956; 957)
@@ -1080,8 +1081,9 @@ SOURCE_FILE@[0; 3813)
1080 L_CURLY@[1853; 1854) 1081 L_CURLY@[1853; 1854)
1081 WHITESPACE@[1854; 1855) 1082 WHITESPACE@[1854; 1855)
1082 MATCH_ARM@[1855; 1863) 1083 MATCH_ARM@[1855; 1863)
1083 LITERAL@[1855; 1856) 1084 LITERAL_PAT@[1855; 1856)
1084 INT_NUMBER@[1855; 1856) "1" 1085 LITERAL@[1855; 1856)
1086 INT_NUMBER@[1855; 1856) "1"
1085 WHITESPACE@[1856; 1857) 1087 WHITESPACE@[1856; 1857)
1086 FAT_ARROW@[1857; 1859) 1088 FAT_ARROW@[1857; 1859)
1087 WHITESPACE@[1859; 1860) 1089 WHITESPACE@[1859; 1860)