diff options
author | Aleksey Kladov <aleksey.kladov@gmail.com> | 2018-07-31 20:41:29 +0100 |
---|---|---|
committer | Aleksey Kladov <aleksey.kladov@gmail.com> | 2018-07-31 20:41:29 +0100 |
commit | 1af8eb9c08f974a1b3beecfebadeb03144ef337d (patch) | |
tree | cd7d3d253679af61bf43fdee6eb1ea85d2796575 | |
parent | 643d23503527d9fcee32dea4f974b7dd0ee26143 (diff) |
impl trait type
-rw-r--r-- | src/grammar.ron | 1 | ||||
-rw-r--r-- | src/parser/grammar/type_params.rs | 5 | ||||
-rw-r--r-- | src/parser/grammar/types.rs | 11 | ||||
-rw-r--r-- | src/syntax_kinds/generated.rs | 2 | ||||
-rw-r--r-- | tests/data/parser/inline/0063_impl_trait_type.rs | 1 | ||||
-rw-r--r-- | tests/data/parser/inline/0063_impl_trait_type.txt | 39 |
6 files changed, 59 insertions, 0 deletions
diff --git a/src/grammar.ron b/src/grammar.ron index aa01cb205..df7b4083b 100644 --- a/src/grammar.ron +++ b/src/grammar.ron | |||
@@ -118,6 +118,7 @@ Grammar( | |||
118 | "PLACEHOLDER_TYPE", | 118 | "PLACEHOLDER_TYPE", |
119 | "FN_POINTER_TYPE", | 119 | "FN_POINTER_TYPE", |
120 | "FOR_TYPE", | 120 | "FOR_TYPE", |
121 | "IMPL_TRAIT_TYPE", | ||
121 | 122 | ||
122 | "REF_PAT", | 123 | "REF_PAT", |
123 | "BIND_PAT", | 124 | "BIND_PAT", |
diff --git a/src/parser/grammar/type_params.rs b/src/parser/grammar/type_params.rs index ccb44c0df..2affd47cc 100644 --- a/src/parser/grammar/type_params.rs +++ b/src/parser/grammar/type_params.rs | |||
@@ -57,6 +57,10 @@ pub(super) fn list(p: &mut Parser) { | |||
57 | pub(super) fn bounds(p: &mut Parser) { | 57 | pub(super) fn bounds(p: &mut Parser) { |
58 | assert!(p.at(COLON)); | 58 | assert!(p.at(COLON)); |
59 | p.bump(); | 59 | p.bump(); |
60 | bounds_without_colon(p); | ||
61 | } | ||
62 | |||
63 | pub(super) fn bounds_without_colon(p: &mut Parser) { | ||
60 | loop { | 64 | loop { |
61 | let has_paren = p.eat(L_PAREN); | 65 | let has_paren = p.eat(L_PAREN); |
62 | p.eat(QUESTION); | 66 | p.eat(QUESTION); |
@@ -79,6 +83,7 @@ pub(super) fn bounds(p: &mut Parser) { | |||
79 | } | 83 | } |
80 | } | 84 | } |
81 | 85 | ||
86 | |||
82 | pub(super) fn where_clause(p: &mut Parser) { | 87 | pub(super) fn where_clause(p: &mut Parser) { |
83 | if p.at(WHERE_KW) { | 88 | if p.at(WHERE_KW) { |
84 | let m = p.start(); | 89 | let m = p.start(); |
diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs index 014086521..31871ceec 100644 --- a/src/parser/grammar/types.rs +++ b/src/parser/grammar/types.rs | |||
@@ -10,6 +10,7 @@ pub(super) fn type_(p: &mut Parser) { | |||
10 | UNDERSCORE => placeholder_type(p), | 10 | UNDERSCORE => placeholder_type(p), |
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 | _ if paths::is_path_start(p) => path_type(p), | 14 | _ if paths::is_path_start(p) => path_type(p), |
14 | _ => { | 15 | _ => { |
15 | p.error("expected type"); | 16 | p.error("expected type"); |
@@ -183,6 +184,16 @@ fn for_type(p: &mut Parser) { | |||
183 | m.complete(p, FOR_TYPE); | 184 | m.complete(p, FOR_TYPE); |
184 | } | 185 | } |
185 | 186 | ||
187 | // test impl_trait_type | ||
188 | // type A = impl Iterator<Item=Foo<'a>> + 'a; | ||
189 | fn impl_trait_type(p: &mut Parser) { | ||
190 | assert!(p.at(IMPL_KW)); | ||
191 | let m = p.start(); | ||
192 | p.bump(); | ||
193 | type_params::bounds_without_colon(p); | ||
194 | m.complete(p, IMPL_TRAIT_TYPE); | ||
195 | } | ||
196 | |||
186 | // test path_type | 197 | // test path_type |
187 | // type A = Foo; | 198 | // type A = Foo; |
188 | // type B = ::Foo; | 199 | // type B = ::Foo; |
diff --git a/src/syntax_kinds/generated.rs b/src/syntax_kinds/generated.rs index a37fdea0b..156d42db4 100644 --- a/src/syntax_kinds/generated.rs +++ b/src/syntax_kinds/generated.rs | |||
@@ -111,6 +111,7 @@ pub enum SyntaxKind { | |||
111 | PLACEHOLDER_TYPE, | 111 | PLACEHOLDER_TYPE, |
112 | FN_POINTER_TYPE, | 112 | FN_POINTER_TYPE, |
113 | FOR_TYPE, | 113 | FOR_TYPE, |
114 | IMPL_TRAIT_TYPE, | ||
114 | REF_PAT, | 115 | REF_PAT, |
115 | BIND_PAT, | 116 | BIND_PAT, |
116 | PLACEHOLDER_PAT, | 117 | PLACEHOLDER_PAT, |
@@ -271,6 +272,7 @@ impl SyntaxKind { | |||
271 | PLACEHOLDER_TYPE => &SyntaxInfo { name: "PLACEHOLDER_TYPE" }, | 272 | PLACEHOLDER_TYPE => &SyntaxInfo { name: "PLACEHOLDER_TYPE" }, |
272 | FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" }, | 273 | FN_POINTER_TYPE => &SyntaxInfo { name: "FN_POINTER_TYPE" }, |
273 | FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" }, | 274 | FOR_TYPE => &SyntaxInfo { name: "FOR_TYPE" }, |
275 | IMPL_TRAIT_TYPE => &SyntaxInfo { name: "IMPL_TRAIT_TYPE" }, | ||
274 | REF_PAT => &SyntaxInfo { name: "REF_PAT" }, | 276 | REF_PAT => &SyntaxInfo { name: "REF_PAT" }, |
275 | BIND_PAT => &SyntaxInfo { name: "BIND_PAT" }, | 277 | BIND_PAT => &SyntaxInfo { name: "BIND_PAT" }, |
276 | PLACEHOLDER_PAT => &SyntaxInfo { name: "PLACEHOLDER_PAT" }, | 278 | PLACEHOLDER_PAT => &SyntaxInfo { name: "PLACEHOLDER_PAT" }, |
diff --git a/tests/data/parser/inline/0063_impl_trait_type.rs b/tests/data/parser/inline/0063_impl_trait_type.rs new file mode 100644 index 000000000..54c5a7c46 --- /dev/null +++ b/tests/data/parser/inline/0063_impl_trait_type.rs | |||
@@ -0,0 +1 @@ | |||
type A = impl Iterator<Item=Foo<'a>> + 'a; | |||
diff --git a/tests/data/parser/inline/0063_impl_trait_type.txt b/tests/data/parser/inline/0063_impl_trait_type.txt new file mode 100644 index 000000000..1a7d8618f --- /dev/null +++ b/tests/data/parser/inline/0063_impl_trait_type.txt | |||
@@ -0,0 +1,39 @@ | |||
1 | FILE@[0; 43) | ||
2 | TYPE_ITEM@[0; 43) | ||
3 | TYPE_KW@[0; 4) | ||
4 | NAME@[4; 7) | ||
5 | WHITESPACE@[4; 5) | ||
6 | IDENT@[5; 6) "A" | ||
7 | WHITESPACE@[6; 7) | ||
8 | EQ@[7; 8) | ||
9 | IMPL_TRAIT_TYPE@[8; 41) | ||
10 | WHITESPACE@[8; 9) | ||
11 | IMPL_KW@[9; 13) | ||
12 | PATH@[13; 37) | ||
13 | PATH_SEGMENT@[13; 37) | ||
14 | NAME_REF@[13; 22) | ||
15 | WHITESPACE@[13; 14) | ||
16 | IDENT@[14; 22) "Iterator" | ||
17 | TYPE_ARG_LIST@[22; 37) | ||
18 | L_ANGLE@[22; 23) | ||
19 | ASSOC_TYPE_ARG@[23; 35) | ||
20 | NAME_REF@[23; 27) | ||
21 | IDENT@[23; 27) "Item" | ||
22 | EQ@[27; 28) | ||
23 | PATH_TYPE@[28; 35) | ||
24 | PATH@[28; 35) | ||
25 | PATH_SEGMENT@[28; 35) | ||
26 | NAME_REF@[28; 31) | ||
27 | IDENT@[28; 31) "Foo" | ||
28 | TYPE_ARG_LIST@[31; 35) | ||
29 | L_ANGLE@[31; 32) | ||
30 | LIFETIME_ARG@[32; 34) | ||
31 | LIFETIME@[32; 34) "'a" | ||
32 | R_ANGLE@[34; 35) | ||
33 | R_ANGLE@[35; 36) | ||
34 | WHITESPACE@[36; 37) | ||
35 | PLUS@[37; 38) | ||
36 | WHITESPACE@[38; 39) | ||
37 | LIFETIME@[39; 41) "'a" | ||
38 | SEMI@[41; 42) | ||
39 | WHITESPACE@[42; 43) | ||