From 58d14bcaf70662506e1a289494365d976b40fc4e Mon Sep 17 00:00:00 2001 From: Ville Penttinen Date: Sun, 17 Feb 2019 22:19:21 +0200 Subject: Enable parsing attributes for generic lifetimes and type parameters --- crates/ra_syntax/src/grammar/type_params.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'crates/ra_syntax/src/grammar') diff --git a/crates/ra_syntax/src/grammar/type_params.rs b/crates/ra_syntax/src/grammar/type_params.rs index 1ec813b3e..40f998682 100644 --- a/crates/ra_syntax/src/grammar/type_params.rs +++ b/crates/ra_syntax/src/grammar/type_params.rs @@ -13,10 +13,20 @@ fn type_param_list(p: &mut Parser) { p.bump(); while !p.at(EOF) && !p.at(R_ANGLE) { + let m = p.start(); + + // test generic_lifetime_type_attribute + // fn foo<#[derive(Lifetime)] 'a, #[derive(Type)] T>(_: &'a T) { + // } + attributes::outer_attributes(p); + match p.current() { - LIFETIME => lifetime_param(p), - IDENT => type_param(p), - _ => p.err_and_bump("expected type parameter"), + LIFETIME => lifetime_param(p, m), + IDENT => type_param(p, m), + _ => { + m.abandon(p); + p.err_and_bump("expected type parameter") + } } if !p.at(R_ANGLE) && !p.expect(COMMA) { break; @@ -26,9 +36,8 @@ fn type_param_list(p: &mut Parser) { m.complete(p, TYPE_PARAM_LIST); } -fn lifetime_param(p: &mut Parser) { +fn lifetime_param(p: &mut Parser, m: Marker) { assert!(p.at(LIFETIME)); - let m = p.start(); p.bump(); if p.at(COLON) { lifetime_bounds(p); @@ -36,9 +45,8 @@ fn lifetime_param(p: &mut Parser) { m.complete(p, LIFETIME_PARAM); } -fn type_param(p: &mut Parser) { +fn type_param(p: &mut Parser, m: Marker) { assert!(p.at(IDENT)); - let m = p.start(); name(p); if p.at(COLON) { bounds(p); -- cgit v1.2.3