diff options
author | Aleksey Kladov <[email protected]> | 2018-08-13 15:42:43 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-13 15:42:43 +0100 |
commit | d1eceefeb8b683da3f64b89446f04f01803962e1 (patch) | |
tree | b5e80856cadc70dbc5f9a8e2cbe6cbf751e5f716 | |
parent | 5a56ac4b72e7f57fb20d49bcf531611f144cc0e0 (diff) |
dyn type
-rw-r--r-- | crates/libsyntax2/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/libsyntax2/src/grammar.ron | 2 | ||||
-rw-r--r-- | crates/libsyntax2/src/grammar/types.rs | 13 | ||||
-rw-r--r-- | crates/libsyntax2/src/syntax_kinds/generated.rs | 6 | ||||
-rw-r--r-- | crates/libsyntax2/tests/data/parser/err/0013_invalid_type.rs | 7 | ||||
-rw-r--r-- | crates/libsyntax2/tests/data/parser/err/0013_invalid_type.txt | 82 | ||||
-rw-r--r-- | crates/libsyntax2/tests/test/main.rs | 1 |
7 files changed, 111 insertions, 1 deletions
diff --git a/crates/libsyntax2/Cargo.toml b/crates/libsyntax2/Cargo.toml index 810952a0f..cfaa3bc9b 100644 --- a/crates/libsyntax2/Cargo.toml +++ b/crates/libsyntax2/Cargo.toml | |||
@@ -14,3 +14,4 @@ smol_str = { path = "../smol_str" } | |||
14 | 14 | ||
15 | [dev-dependencies] | 15 | [dev-dependencies] |
16 | assert_eq_text = { path = "../assert_eq_text" } | 16 | assert_eq_text = { path = "../assert_eq_text" } |
17 | walkdir = "2.2.0" | ||
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron index ee231931e..c07ed4203 100644 --- a/crates/libsyntax2/src/grammar.ron +++ b/crates/libsyntax2/src/grammar.ron | |||
@@ -55,6 +55,7 @@ Grammar( | |||
55 | "enum", | 55 | "enum", |
56 | "trait", | 56 | "trait", |
57 | "impl", | 57 | "impl", |
58 | "dyn", | ||
58 | "true", | 59 | "true", |
59 | "false", | 60 | "false", |
60 | "as", | 61 | "as", |
@@ -134,6 +135,7 @@ Grammar( | |||
134 | "FN_POINTER_TYPE", | 135 | "FN_POINTER_TYPE", |
135 | "FOR_TYPE", | 136 | "FOR_TYPE", |
136 | "IMPL_TRAIT_TYPE", | 137 | "IMPL_TRAIT_TYPE", |
138 | "DYN_TRAIT_TYPE", | ||
137 | 139 | ||
138 | "REF_PAT", | 140 | "REF_PAT", |
139 | "BIND_PAT", | 141 | "BIND_PAT", |
diff --git a/crates/libsyntax2/src/grammar/types.rs b/crates/libsyntax2/src/grammar/types.rs index 0d8c6bfba..5ba3fcca0 100644 --- a/crates/libsyntax2/src/grammar/types.rs +++ b/crates/libsyntax2/src/grammar/types.rs | |||
@@ -11,9 +11,10 @@ pub(super) fn type_(p: &mut Parser) { | |||
11 | FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), | 11 | FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), |
12 | FOR_KW => for_type(p), | 12 | FOR_KW => for_type(p), |
13 | IMPL_KW => impl_trait_type(p), | 13 | IMPL_KW => impl_trait_type(p), |
14 | DYN_KW => dyn_trait_type(p), | ||
14 | _ if paths::is_path_start(p) => path_type(p), | 15 | _ if paths::is_path_start(p) => path_type(p), |
15 | _ => { | 16 | _ => { |
16 | p.error("expected type"); | 17 | p.err_and_bump("expected type"); |
17 | } | 18 | } |
18 | } | 19 | } |
19 | } | 20 | } |
@@ -194,6 +195,16 @@ fn impl_trait_type(p: &mut Parser) { | |||
194 | m.complete(p, IMPL_TRAIT_TYPE); | 195 | m.complete(p, IMPL_TRAIT_TYPE); |
195 | } | 196 | } |
196 | 197 | ||
198 | // test dyn_trait_type | ||
199 | // type A = dyn Iterator<Item=Foo<'a>> + 'a; | ||
200 | fn dyn_trait_type(p: &mut Parser) { | ||
201 | assert!(p.at(DYN_KW)); | ||
202 | let m = p.start(); | ||
203 | p.bump(); | ||
204 | type_params::bounds_without_colon(p); | ||
205 | m.complete(p, DYN_TRAIT_TYPE); | ||
206 | } | ||
207 | |||
197 | // test path_type | 208 | // test path_type |
198 | // type A = Foo; | 209 | // type A = Foo; |
199 | // type B = ::Foo; | 210 | // type B = ::Foo; |
diff --git a/crates/libsyntax2/src/syntax_kinds/generated.rs b/crates/libsyntax2/src/syntax_kinds/generated.rs index c45a4800c..f5f8fe1ef 100644 --- a/crates/libsyntax2/src/syntax_kinds/generated.rs +++ b/crates/libsyntax2/src/syntax_kinds/generated.rs | |||
@@ -62,6 +62,7 @@ pub enum SyntaxKind { | |||
62 | ENUM_KW, | 62 | ENUM_KW, |
63 | TRAIT_KW, | 63 | TRAIT_KW, |
64 | IMPL_KW, | 64 | IMPL_KW, |
65 | DYN_KW, | ||
65 | TRUE_KW, | 66 | TRUE_KW, |
66 | FALSE_KW, | 67 | FALSE_KW, |
67 | AS_KW, | 68 | AS_KW, |
@@ -133,6 +134,7 @@ pub enum SyntaxKind { | |||
133 | FN_POINTER_TYPE, | 134 | FN_POINTER_TYPE, |
134 | FOR_TYPE, | 135 | FOR_TYPE, |
135 | IMPL_TRAIT_TYPE, | 136 | IMPL_TRAIT_TYPE, |
137 | DYN_TRAIT_TYPE, | ||
136 | REF_PAT, | 138 | REF_PAT, |
137 | BIND_PAT, | 139 | BIND_PAT, |
138 | PLACEHOLDER_PAT, | 140 | PLACEHOLDER_PAT, |
@@ -210,6 +212,7 @@ impl SyntaxKind { | |||
210 | | ENUM_KW | 212 | | ENUM_KW |
211 | | TRAIT_KW | 213 | | TRAIT_KW |
212 | | IMPL_KW | 214 | | IMPL_KW |
215 | | DYN_KW | ||
213 | | TRUE_KW | 216 | | TRUE_KW |
214 | | FALSE_KW | 217 | | FALSE_KW |
215 | | AS_KW | 218 | | AS_KW |
@@ -297,6 +300,7 @@ impl SyntaxKind { | |||
297 | ENUM_KW => &SyntaxInfo { name: "ENUM_KW" }, | 300 | ENUM_KW => &SyntaxInfo { name: "ENUM_KW" }, |
298 | TRAIT_KW => &SyntaxInfo { name: "TRAIT_KW" }, | 301 | TRAIT_KW => &SyntaxInfo { name: "TRAIT_KW" }, |
299 | IMPL_KW => &SyntaxInfo { name: "IMPL_KW" }, | 302 | IMPL_KW => &SyntaxInfo { name: "IMPL_KW" }, |
303 | DYN_KW => &SyntaxInfo { name: "DYN_KW" }, | ||
300 | TRUE_KW => &SyntaxInfo { name: "TRUE_KW" }, | 304 | TRUE_KW => &SyntaxInfo { name: "TRUE_KW" }, |
301 | FALSE_KW => &SyntaxInfo { name: "FALSE_KW" }, | 305 | FALSE_KW => &SyntaxInfo { name: "FALSE_KW" }, |
302 | AS_KW => &SyntaxInfo { name: "AS_KW" }, | 306 | AS_KW => &SyntaxInfo { name: "AS_KW" }, |
@@ -368,6 +372,7 @@ impl SyntaxKind { | |||
368 | FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" }, | 372 | FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" }, |
369 | FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" }, | 373 | FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" }, |
370 | IMPL_TRAIT_TYPE => &SyntaxInfo { name: "IMPL_TRAIT_TYPE" }, | 374 | IMPL_TRAIT_TYPE => &SyntaxInfo { name: "IMPL_TRAIT_TYPE" }, |
375 | DYN_TRAIT_TYPE => &SyntaxInfo { name: "DYN_TRAIT_TYPE" }, | ||
371 | REF_PAT => &SyntaxInfo { name: "REF_PAT" }, | 376 | REF_PAT => &SyntaxInfo { name: "REF_PAT" }, |
372 | BIND_PAT => &SyntaxInfo { name: "BIND_PAT" }, | 377 | BIND_PAT => &SyntaxInfo { name: "BIND_PAT" }, |
373 | PLACEHOLDER_PAT => &SyntaxInfo { name: "PLACEHOLDER_PAT" }, | 378 | PLACEHOLDER_PAT => &SyntaxInfo { name: "PLACEHOLDER_PAT" }, |
@@ -445,6 +450,7 @@ impl SyntaxKind { | |||
445 | "enum" => ENUM_KW, | 450 | "enum" => ENUM_KW, |
446 | "trait" => TRAIT_KW, | 451 | "trait" => TRAIT_KW, |
447 | "impl" => IMPL_KW, | 452 | "impl" => IMPL_KW, |
453 | "dyn" => DYN_KW, | ||
448 | "true" => TRUE_KW, | 454 | "true" => TRUE_KW, |
449 | "false" => FALSE_KW, | 455 | "false" => FALSE_KW, |
450 | "as" => AS_KW, | 456 | "as" => AS_KW, |
diff --git a/crates/libsyntax2/tests/data/parser/err/0013_invalid_type.rs b/crates/libsyntax2/tests/data/parser/err/0013_invalid_type.rs new file mode 100644 index 000000000..20dde3bc3 --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/err/0013_invalid_type.rs | |||
@@ -0,0 +1,7 @@ | |||
1 | pub struct Cache( | ||
2 | RefCell<HashMap< | ||
3 | TypeId, | ||
4 | Box<@ Any>, | ||
5 | >> | ||
6 | ); | ||
7 | |||
diff --git a/crates/libsyntax2/tests/data/parser/err/0013_invalid_type.txt b/crates/libsyntax2/tests/data/parser/err/0013_invalid_type.txt new file mode 100644 index 000000000..8b56f699f --- /dev/null +++ b/crates/libsyntax2/tests/data/parser/err/0013_invalid_type.txt | |||
@@ -0,0 +1,82 @@ | |||
1 | FILE@[0; 86) | ||
2 | STRUCT@[0; 84) | ||
3 | VISIBILITY@[0; 3) | ||
4 | PUB_KW@[0; 3) | ||
5 | WHITESPACE@[3; 4) | ||
6 | STRUCT_KW@[4; 10) | ||
7 | WHITESPACE@[10; 11) | ||
8 | NAME@[11; 16) | ||
9 | IDENT@[11; 16) "Cache" | ||
10 | L_PAREN@[16; 17) | ||
11 | WHITESPACE@[17; 22) | ||
12 | POS_FIELD@[22; 68) | ||
13 | PATH_TYPE@[22; 68) | ||
14 | PATH@[22; 68) | ||
15 | PATH_SEGMENT@[22; 68) | ||
16 | NAME_REF@[22; 29) | ||
17 | IDENT@[22; 29) "RefCell" | ||
18 | TYPE_ARG_LIST@[29; 68) | ||
19 | L_ANGLE@[29; 30) | ||
20 | TYPE_ARG@[30; 68) | ||
21 | PATH_TYPE@[30; 68) | ||
22 | PATH@[30; 68) | ||
23 | PATH_SEGMENT@[30; 68) | ||
24 | NAME_REF@[30; 37) | ||
25 | IDENT@[30; 37) "HashMap" | ||
26 | TYPE_ARG_LIST@[37; 68) | ||
27 | L_ANGLE@[37; 38) | ||
28 | WHITESPACE@[38; 47) | ||
29 | TYPE_ARG@[47; 53) | ||
30 | PATH_TYPE@[47; 53) | ||
31 | PATH@[47; 53) | ||
32 | PATH_SEGMENT@[47; 53) | ||
33 | NAME_REF@[47; 53) | ||
34 | IDENT@[47; 53) "TypeId" | ||
35 | COMMA@[53; 54) | ||
36 | WHITESPACE@[54; 63) | ||
37 | TYPE_ARG@[63; 68) | ||
38 | PATH_TYPE@[63; 68) | ||
39 | PATH@[63; 68) | ||
40 | PATH_SEGMENT@[63; 68) | ||
41 | NAME_REF@[63; 66) | ||
42 | IDENT@[63; 66) "Box" | ||
43 | TYPE_ARG_LIST@[66; 68) | ||
44 | L_ANGLE@[66; 67) | ||
45 | err: `expected type` | ||
46 | TYPE_ARG@[67; 68) | ||
47 | ERROR@[67; 68) | ||
48 | AT@[67; 68) | ||
49 | err: `expected COMMA` | ||
50 | err: `expected R_ANGLE` | ||
51 | err: `expected COMMA` | ||
52 | err: `expected R_ANGLE` | ||
53 | err: `expected COMMA` | ||
54 | err: `expected R_ANGLE` | ||
55 | err: `expected COMMA` | ||
56 | WHITESPACE@[68; 69) | ||
57 | POS_FIELD@[69; 72) | ||
58 | PATH_TYPE@[69; 72) | ||
59 | PATH@[69; 72) | ||
60 | PATH_SEGMENT@[69; 72) | ||
61 | NAME_REF@[69; 72) | ||
62 | IDENT@[69; 72) "Any" | ||
63 | err: `expected COMMA` | ||
64 | err: `expected type` | ||
65 | POS_FIELD@[72; 73) | ||
66 | ERROR@[72; 73) | ||
67 | R_ANGLE@[72; 73) | ||
68 | COMMA@[73; 74) | ||
69 | WHITESPACE@[74; 79) | ||
70 | err: `expected type` | ||
71 | POS_FIELD@[79; 80) | ||
72 | ERROR@[79; 80) | ||
73 | R_ANGLE@[79; 80) | ||
74 | err: `expected COMMA` | ||
75 | err: `expected type` | ||
76 | POS_FIELD@[80; 81) | ||
77 | ERROR@[80; 81) | ||
78 | R_ANGLE@[80; 81) | ||
79 | WHITESPACE@[81; 82) | ||
80 | R_PAREN@[82; 83) | ||
81 | SEMI@[83; 84) | ||
82 | WHITESPACE@[84; 86) | ||
diff --git a/crates/libsyntax2/tests/test/main.rs b/crates/libsyntax2/tests/test/main.rs index 64d080dfd..6b0a44d0c 100644 --- a/crates/libsyntax2/tests/test/main.rs +++ b/crates/libsyntax2/tests/test/main.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | extern crate libsyntax2; | 1 | extern crate libsyntax2; |
2 | #[macro_use] | 2 | #[macro_use] |
3 | extern crate assert_eq_text; | 3 | extern crate assert_eq_text; |
4 | extern crate walkdir; | ||
4 | 5 | ||
5 | use std::{ | 6 | use std::{ |
6 | fs, | 7 | fs, |