diff options
author | Michael Chesser <[email protected]> | 2020-01-06 22:59:03 +0000 |
---|---|---|
committer | Michael Chesser <[email protected]> | 2020-01-06 22:59:03 +0000 |
commit | ce1b34fd59a6145a4bb5682d672c846e101725d4 (patch) | |
tree | 8a9535261dac04f171caa68d4b908cdde0b4a34c /crates/ra_parser/src/grammar/items | |
parent | c92a090f49cad2fa540562536f07fcb619f16680 (diff) |
Improve const generics parsing
- Handle const generics type args
- Fix issue with const generic as first parameter in trait impl
Diffstat (limited to 'crates/ra_parser/src/grammar/items')
-rw-r--r-- | crates/ra_parser/src/grammar/items/traits.rs | 5 |
1 files changed, 4 insertions, 1 deletions
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) { | |||
100 | m.complete(p, ITEM_LIST); | 100 | m.complete(p, ITEM_LIST); |
101 | } | 101 | } |
102 | 102 | ||
103 | // test impl_type_params | ||
104 | // impl<const N: u32> Bar<N> {} | ||
103 | fn choose_type_params_over_qpath(p: &Parser) -> bool { | 105 | fn choose_type_params_over_qpath(p: &Parser) -> bool { |
104 | // There's an ambiguity between generic parameters and qualified paths in impls. | 106 | // There's an ambiguity between generic parameters and qualified paths in impls. |
105 | // If we see `<` it may start both, so we have to inspect some following tokens. | 107 | // 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 { | |||
107 | // but not qualified paths (with one exception): | 109 | // but not qualified paths (with one exception): |
108 | // `<` `>` - empty generic parameters | 110 | // `<` `>` - empty generic parameters |
109 | // `<` `#` - generic parameters with attributes | 111 | // `<` `#` - generic parameters with attributes |
112 | // `<` `const` - const generic parameters | ||
110 | // `<` (LIFETIME|IDENT) `>` - single generic parameter | 113 | // `<` (LIFETIME|IDENT) `>` - single generic parameter |
111 | // `<` (LIFETIME|IDENT) `,` - first generic parameter in a list | 114 | // `<` (LIFETIME|IDENT) `,` - first generic parameter in a list |
112 | // `<` (LIFETIME|IDENT) `:` - generic parameter with bounds | 115 | // `<` (LIFETIME|IDENT) `:` - generic parameter with bounds |
@@ -119,7 +122,7 @@ fn choose_type_params_over_qpath(p: &Parser) -> bool { | |||
119 | if !p.at(T![<]) { | 122 | if !p.at(T![<]) { |
120 | return false; | 123 | return false; |
121 | } | 124 | } |
122 | if p.nth(1) == T![#] || p.nth(1) == T![>] { | 125 | if p.nth(1) == T![#] || p.nth(1) == T![>] || p.nth(1) == CONST_KW { |
123 | return true; | 126 | return true; |
124 | } | 127 | } |
125 | (p.nth(1) == LIFETIME || p.nth(1) == IDENT) | 128 | (p.nth(1) == LIFETIME || p.nth(1) == IDENT) |