diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-12 15:46:05 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-06-12 15:46:05 +0100 |
commit | c452d2842c2ac7156178a05fe477e8832253a2c4 (patch) | |
tree | 3ac7ef81def034f7bdaffd8c9656d22e35c4300b /crates/ra_parser/src | |
parent | 03645c55761f8c9345ee3837a6010e65e7a80179 (diff) | |
parent | 2ca9f718978b20e8cffb669dc61b63ad7d5e82cd (diff) |
Merge #1393
1393: fix: support existential type r=matklad a=csmoe
Closes https://github.com/rust-analyzer/rust-analyzer/issues/1387
r? @matklad
Co-authored-by: csmoe <[email protected]>
Diffstat (limited to 'crates/ra_parser/src')
-rw-r--r-- | crates/ra_parser/src/grammar/items.rs | 16 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs | 4 |
2 files changed, 17 insertions, 3 deletions
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 7718fbe6a..e85147e9e 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs | |||
@@ -107,6 +107,10 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul | |||
107 | p.bump_remap(T![default]); | 107 | p.bump_remap(T![default]); |
108 | has_mods = true; | 108 | has_mods = true; |
109 | } | 109 | } |
110 | if p.at(IDENT) && p.at_contextual_kw("existential") && p.nth(1) == T![type] { | ||
111 | p.bump_remap(T![existential]); | ||
112 | has_mods = true; | ||
113 | } | ||
110 | 114 | ||
111 | // items | 115 | // items |
112 | match p.current() { | 116 | match p.current() { |
@@ -165,12 +169,17 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul | |||
165 | traits::impl_block(p); | 169 | traits::impl_block(p); |
166 | m.complete(p, IMPL_BLOCK); | 170 | m.complete(p, IMPL_BLOCK); |
167 | } | 171 | } |
172 | // test existential_type | ||
173 | // existential type Foo: Fn() -> usize; | ||
174 | T![type] => { | ||
175 | type_def(p, m); | ||
176 | } | ||
168 | _ => { | 177 | _ => { |
169 | if !has_visibility && !has_mods { | 178 | if !has_visibility && !has_mods { |
170 | return Err(m); | 179 | return Err(m); |
171 | } else { | 180 | } else { |
172 | if has_mods { | 181 | if has_mods { |
173 | p.error("expected fn, trait or impl"); | 182 | p.error("expected existential, fn, trait or impl"); |
174 | } else { | 183 | } else { |
175 | p.error("expected an item"); | 184 | p.error("expected an item"); |
176 | } | 185 | } |
@@ -187,7 +196,9 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> { | |||
187 | // test extern_crate | 196 | // test extern_crate |
188 | // extern crate foo; | 197 | // extern crate foo; |
189 | T![extern] if la == T![crate] => extern_crate_item(p, m), | 198 | T![extern] if la == T![crate] => extern_crate_item(p, m), |
190 | T![type] => type_def(p, m), | 199 | T![type] => { |
200 | type_def(p, m); | ||
201 | } | ||
191 | T![mod] => mod_item(p, m), | 202 | T![mod] => mod_item(p, m), |
192 | T![struct] => { | 203 | T![struct] => { |
193 | // test struct_items | 204 | // test struct_items |
@@ -308,7 +319,6 @@ fn type_def(p: &mut Parser, m: Marker) { | |||
308 | // test type_item_where_clause | 319 | // test type_item_where_clause |
309 | // type Foo where Foo: Copy = (); | 320 | // type Foo where Foo: Copy = (); |
310 | type_params::opt_where_clause(p); | 321 | type_params::opt_where_clause(p); |
311 | |||
312 | if p.eat(T![=]) { | 322 | if p.eat(T![=]) { |
313 | types::type_(p); | 323 | types::type_(p); |
314 | } | 324 | } |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 2c021f3e9..036415eac 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs | |||
@@ -106,6 +106,7 @@ pub enum SyntaxKind { | |||
106 | TRY_KW, | 106 | TRY_KW, |
107 | AUTO_KW, | 107 | AUTO_KW, |
108 | DEFAULT_KW, | 108 | DEFAULT_KW, |
109 | EXISTENTIAL_KW, | ||
109 | UNION_KW, | 110 | UNION_KW, |
110 | INT_NUMBER, | 111 | INT_NUMBER, |
111 | FLOAT_NUMBER, | 112 | FLOAT_NUMBER, |
@@ -336,6 +337,7 @@ macro_rules! T { | |||
336 | (try) => { $crate::SyntaxKind::TRY_KW }; | 337 | (try) => { $crate::SyntaxKind::TRY_KW }; |
337 | (auto) => { $crate::SyntaxKind::AUTO_KW }; | 338 | (auto) => { $crate::SyntaxKind::AUTO_KW }; |
338 | (default) => { $crate::SyntaxKind::DEFAULT_KW }; | 339 | (default) => { $crate::SyntaxKind::DEFAULT_KW }; |
340 | (existential) => { $crate::SyntaxKind::EXISTENTIAL_KW }; | ||
339 | (union) => { $crate::SyntaxKind::UNION_KW }; | 341 | (union) => { $crate::SyntaxKind::UNION_KW }; |
340 | } | 342 | } |
341 | 343 | ||
@@ -394,6 +396,7 @@ impl SyntaxKind { | |||
394 | | TRY_KW | 396 | | TRY_KW |
395 | | AUTO_KW | 397 | | AUTO_KW |
396 | | DEFAULT_KW | 398 | | DEFAULT_KW |
399 | | EXISTENTIAL_KW | ||
397 | | UNION_KW | 400 | | UNION_KW |
398 | => true, | 401 | => true, |
399 | _ => false | 402 | _ => false |
@@ -566,6 +569,7 @@ impl SyntaxKind { | |||
566 | TRY_KW => &SyntaxInfo { name: "TRY_KW" }, | 569 | TRY_KW => &SyntaxInfo { name: "TRY_KW" }, |
567 | AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, | 570 | AUTO_KW => &SyntaxInfo { name: "AUTO_KW" }, |
568 | DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, | 571 | DEFAULT_KW => &SyntaxInfo { name: "DEFAULT_KW" }, |
572 | EXISTENTIAL_KW => &SyntaxInfo { name: "EXISTENTIAL_KW" }, | ||
569 | UNION_KW => &SyntaxInfo { name: "UNION_KW" }, | 573 | UNION_KW => &SyntaxInfo { name: "UNION_KW" }, |
570 | INT_NUMBER => &SyntaxInfo { name: "INT_NUMBER" }, | 574 | INT_NUMBER => &SyntaxInfo { name: "INT_NUMBER" }, |
571 | FLOAT_NUMBER => &SyntaxInfo { name: "FLOAT_NUMBER" }, | 575 | FLOAT_NUMBER => &SyntaxInfo { name: "FLOAT_NUMBER" }, |