From ce1b34fd59a6145a4bb5682d672c846e101725d4 Mon Sep 17 00:00:00 2001 From: Michael Chesser Date: Tue, 7 Jan 2020 09:29:03 +1030 Subject: Improve const generics parsing - Handle const generics type args - Fix issue with const generic as first parameter in trait impl --- crates/ra_parser/src/grammar/items/traits.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'crates/ra_parser/src/grammar/items') diff --git a/crates/ra_parser/src/grammar/items/traits.rs b/crates/ra_parser/src/grammar/items/traits.rs index 2c560e824..964fd3041 100644 --- a/crates/ra_parser/src/grammar/items/traits.rs +++ b/crates/ra_parser/src/grammar/items/traits.rs @@ -100,6 +100,8 @@ pub(crate) fn impl_item_list(p: &mut Parser) { m.complete(p, ITEM_LIST); } +// test impl_type_params +// impl Bar {} fn choose_type_params_over_qpath(p: &Parser) -> bool { // There's an ambiguity between generic parameters and qualified paths in impls. // If we see `<` it may start both, so we have to inspect some following tokens. @@ -107,6 +109,7 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool { // but not qualified paths (with one exception): // `<` `>` - empty generic parameters // `<` `#` - generic parameters with attributes + // `<` `const` - const generic parameters // `<` (LIFETIME|IDENT) `>` - single generic parameter // `<` (LIFETIME|IDENT) `,` - first generic parameter in a list // `<` (LIFETIME|IDENT) `:` - generic parameter with bounds @@ -119,7 +122,7 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool { if !p.at(T![<]) { return false; } - if p.nth(1) == T![#] || p.nth(1) == T![>] { + if p.nth(1) == T![#] || p.nth(1) == T![>] || p.nth(1) == CONST_KW { return true; } (p.nth(1) == LIFETIME || p.nth(1) == IDENT) -- cgit v1.2.3