From 1af8eb9c08f974a1b3beecfebadeb03144ef337d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 31 Jul 2018 22:41:29 +0300 Subject: impl trait type --- src/parser/grammar/type_params.rs | 5 +++++ src/parser/grammar/types.rs | 11 +++++++++++ 2 files changed, 16 insertions(+) (limited to 'src/parser/grammar') 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) { pub(super) fn bounds(p: &mut Parser) { assert!(p.at(COLON)); p.bump(); + bounds_without_colon(p); +} + +pub(super) fn bounds_without_colon(p: &mut Parser) { loop { let has_paren = p.eat(L_PAREN); p.eat(QUESTION); @@ -79,6 +83,7 @@ pub(super) fn bounds(p: &mut Parser) { } } + pub(super) fn where_clause(p: &mut Parser) { if p.at(WHERE_KW) { 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) { UNDERSCORE => placeholder_type(p), FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), FOR_KW => for_type(p), + IMPL_KW => impl_trait_type(p), _ if paths::is_path_start(p) => path_type(p), _ => { p.error("expected type"); @@ -183,6 +184,16 @@ fn for_type(p: &mut Parser) { m.complete(p, FOR_TYPE); } +// test impl_trait_type +// type A = impl Iterator> + 'a; +fn impl_trait_type(p: &mut Parser) { + assert!(p.at(IMPL_KW)); + let m = p.start(); + p.bump(); + type_params::bounds_without_colon(p); + m.complete(p, IMPL_TRAIT_TYPE); +} + // test path_type // type A = Foo; // type B = ::Foo; -- cgit v1.2.3