From e44a6bcc8208f9d906febf9278120b75a6af67f9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 4 Sep 2018 12:25:23 +0300 Subject: for types in bounds --- crates/libsyntax2/src/grammar/type_params.rs | 18 +++++++++--------- crates/libsyntax2/src/grammar/types.rs | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 12 deletions(-) (limited to 'crates/libsyntax2/src') diff --git a/crates/libsyntax2/src/grammar/type_params.rs b/crates/libsyntax2/src/grammar/type_params.rs index 3fb4bd356..79bc95ce4 100644 --- a/crates/libsyntax2/src/grammar/type_params.rs +++ b/crates/libsyntax2/src/grammar/type_params.rs @@ -70,15 +70,15 @@ pub(super) fn bounds_without_colon(p: &mut Parser) { loop { let has_paren = p.eat(L_PAREN); p.eat(QUESTION); - if p.at(FOR_KW) { - //TODO - } - if p.at(LIFETIME) { - p.bump(); - } else if paths::is_path_start(p) { - paths::type_path(p); - } else { - break; + match p.current() { + LIFETIME => p.bump(), + FOR_KW => { + types::for_type(p) + } + _ if paths::is_path_start(p) => { + types::path_type(p) + } + _ => break, } if has_paren { p.expect(R_PAREN); diff --git a/crates/libsyntax2/src/grammar/types.rs b/crates/libsyntax2/src/grammar/types.rs index a52355b50..27e5b086e 100644 --- a/crates/libsyntax2/src/grammar/types.rs +++ b/crates/libsyntax2/src/grammar/types.rs @@ -191,12 +191,17 @@ fn fn_pointer_type(p: &mut Parser) { // test for_type // type A = for<'a> fn() -> (); -fn for_type(p: &mut Parser) { +pub(super) fn for_type(p: &mut Parser) { assert!(p.at(FOR_KW)); let m = p.start(); p.bump(); type_params::opt_type_param_list(p); - type_(p); + match p.current() { + FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), + _ if paths::is_path_start(p) => path_type_(p, false), + _ => p.error("expected a path"), + + } m.complete(p, FOR_TYPE); } @@ -226,12 +231,16 @@ fn dyn_trait_type(p: &mut Parser) { // type C = self::Foo; // type D = super::Foo; pub(super) fn path_type(p: &mut Parser) { + path_type_(p, true) +} + +pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) { assert!(paths::is_path_start(p) || p.at(L_ANGLE)); let m = p.start(); paths::type_path(p); // test path_type_with_bounds // fn foo() -> Box {} - if p.eat(PLUS) { + if allow_bounds && p.eat(PLUS) { type_params::bounds_without_colon(p); } m.complete(p, PATH_TYPE); -- cgit v1.2.3