diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-01-06 23:43:24 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-01-06 23:43:24 +0000 |
commit | 7b9df1062d65e6977f16d6595ffb5912769011a3 (patch) | |
tree | 8a9535261dac04f171caa68d4b908cdde0b4a34c /crates/ra_parser/src/grammar/items | |
parent | c92a090f49cad2fa540562536f07fcb619f16680 (diff) | |
parent | ce1b34fd59a6145a4bb5682d672c846e101725d4 (diff) |
Merge #2724
2724: Improve const generic parsing r=matklad a=mchesser
Add support for generic arguments in:
`impl` type parameters:
```rust
impl<const N: u32> Bar<N> {}
```
type args:
```rust
type A = B<1, { 2 }>;
test::<10>();
```
Co-authored-by: Michael Chesser <[email protected]>
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) |