diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-10 08:04:49 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-10 08:04:49 +0000 |
commit | a8a4f8012e525c816aedf5b0bc51e3ad4c13a0ab (patch) | |
tree | cd2cd9080114eee7c079b2120e27fb5655cdb947 /crates/ra_syntax/src/grammar/patterns.rs | |
parent | 8bcb84ea681f982946a24b5e000ddde58247adba (diff) | |
parent | c098a3fda52ef0b02188abfa91adcd67e82c0c02 (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/grammar/patterns.rs')
-rw-r--r-- | crates/ra_syntax/src/grammar/patterns.rs | 41 |
1 files changed, 26 insertions, 15 deletions
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 | ||
63 | fn 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 | // } | ||
77 | fn 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 = (); |