aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-06-12 15:46:05 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-06-12 15:46:05 +0100
commitc452d2842c2ac7156178a05fe477e8832253a2c4 (patch)
tree3ac7ef81def034f7bdaffd8c9656d22e35c4300b
parent03645c55761f8c9345ee3837a6010e65e7a80179 (diff)
parent2ca9f718978b20e8cffb669dc61b63ad7d5e82cd (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]>
-rw-r--r--crates/ra_parser/src/grammar/items.rs16
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs4
-rw-r--r--crates/ra_syntax/src/grammar.ron1
-rw-r--r--crates/ra_syntax/tests/data/parser/err/0011_extern_struct.txt2
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.txt4
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0131_existential_type.rs1
-rw-r--r--crates/ra_syntax/tests/data/parser/inline/ok/0131_existential_type.txt31
7 files changed, 53 insertions, 6 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" },
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index 1c2714307..eab55058b 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -100,6 +100,7 @@ Grammar(
100 contextual_keywords: [ 100 contextual_keywords: [
101 "auto", 101 "auto",
102 "default", 102 "default",
103 "existential",
103 "union", 104 "union",
104 ], 105 ],
105 literals: [ 106 literals: [
diff --git a/crates/ra_syntax/tests/data/parser/err/0011_extern_struct.txt b/crates/ra_syntax/tests/data/parser/err/0011_extern_struct.txt
index 033dac2aa..381147dc0 100644
--- a/crates/ra_syntax/tests/data/parser/err/0011_extern_struct.txt
+++ b/crates/ra_syntax/tests/data/parser/err/0011_extern_struct.txt
@@ -10,4 +10,4 @@ SOURCE_FILE@[0; 19)
10 IDENT@[14; 17) "Foo" 10 IDENT@[14; 17) "Foo"
11 SEMI@[17; 18) ";" 11 SEMI@[17; 18) ";"
12 WHITESPACE@[18; 19) "\n" 12 WHITESPACE@[18; 19) "\n"
13error 6: expected fn, trait or impl 13error 6: expected existential, fn, trait or impl
diff --git a/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.txt b/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.txt
index 9eb4c9b36..b1ef210d3 100644
--- a/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.txt
+++ b/crates/ra_syntax/tests/data/parser/inline/err/0010_wrong_order_fns.txt
@@ -35,5 +35,5 @@ SOURCE_FILE@[0; 50)
35 L_CURLY@[47; 48) "{" 35 L_CURLY@[47; 48) "{"
36 R_CURLY@[48; 49) "}" 36 R_CURLY@[48; 49) "}"
37 WHITESPACE@[49; 50) "\n" 37 WHITESPACE@[49; 50) "\n"
38error 5: expected fn, trait or impl 38error 5: expected existential, fn, trait or impl
39error 31: expected fn, trait or impl 39error 31: expected existential, fn, trait or impl
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0131_existential_type.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0131_existential_type.rs
new file mode 100644
index 000000000..23baf7145
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0131_existential_type.rs
@@ -0,0 +1 @@
existential type Foo: Fn() -> usize;
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0131_existential_type.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0131_existential_type.txt
new file mode 100644
index 000000000..6bfac985a
--- /dev/null
+++ b/crates/ra_syntax/tests/data/parser/inline/ok/0131_existential_type.txt
@@ -0,0 +1,31 @@
1SOURCE_FILE@[0; 37)
2 TYPE_ALIAS_DEF@[0; 36)
3 EXISTENTIAL_KW@[0; 11) "existential"
4 WHITESPACE@[11; 12) " "
5 TYPE_KW@[12; 16) "type"
6 WHITESPACE@[16; 17) " "
7 NAME@[17; 20)
8 IDENT@[17; 20) "Foo"
9 COLON@[20; 21) ":"
10 WHITESPACE@[21; 22) " "
11 TYPE_BOUND_LIST@[22; 35)
12 TYPE_BOUND@[22; 35)
13 PATH_TYPE@[22; 35)
14 PATH@[22; 35)
15 PATH_SEGMENT@[22; 35)
16 NAME_REF@[22; 24)
17 IDENT@[22; 24) "Fn"
18 PARAM_LIST@[24; 26)
19 L_PAREN@[24; 25) "("
20 R_PAREN@[25; 26) ")"
21 WHITESPACE@[26; 27) " "
22 RET_TYPE@[27; 35)
23 THIN_ARROW@[27; 29) "->"
24 WHITESPACE@[29; 30) " "
25 PATH_TYPE@[30; 35)
26 PATH@[30; 35)
27 PATH_SEGMENT@[30; 35)
28 NAME_REF@[30; 35)
29 IDENT@[30; 35) "usize"
30 SEMI@[35; 36) ";"
31 WHITESPACE@[36; 37) "\n"