diff options
author | Aleksey Kladov <[email protected]> | 2018-07-31 20:41:29 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-07-31 20:41:29 +0100 |
commit | 1af8eb9c08f974a1b3beecfebadeb03144ef337d (patch) | |
tree | cd7d3d253679af61bf43fdee6eb1ea85d2796575 /src/parser/grammar | |
parent | 643d23503527d9fcee32dea4f974b7dd0ee26143 (diff) |
impl trait type
Diffstat (limited to 'src/parser/grammar')
-rw-r--r-- | src/parser/grammar/type_params.rs | 5 | ||||
-rw-r--r-- | src/parser/grammar/types.rs | 11 |
2 files changed, 16 insertions, 0 deletions
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; |