diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-22 07:56:33 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-22 07:56:33 +0000 |
commit | d33493d779ba573403804b8d78e9b72fcf98f894 (patch) | |
tree | f6fe331d8fac08c821d0820e4c15410e1c9de66a /crates/ra_parser/src | |
parent | 000710bd089959796947b507d05a6426b7733b47 (diff) | |
parent | b04d4a88d1ba7f04445e807b6a816930b1e9bbf2 (diff) |
Merge #2641
2641: Parse const generics r=matklad a=roblabla
Adds very primitive support for parsing const generics (`const IDENT: TY`) so that rust-analyzer stops complaining about the syntax being invalid.
Fixes #1574
Fixes #2281
Co-authored-by: roblabla <[email protected]>
Diffstat (limited to 'crates/ra_parser/src')
-rw-r--r-- | crates/ra_parser/src/grammar/type_params.rs | 11 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/crates/ra_parser/src/grammar/type_params.rs b/crates/ra_parser/src/grammar/type_params.rs index 34406b5bd..50e4900c3 100644 --- a/crates/ra_parser/src/grammar/type_params.rs +++ b/crates/ra_parser/src/grammar/type_params.rs | |||
@@ -25,6 +25,7 @@ fn type_param_list(p: &mut Parser) { | |||
25 | match p.current() { | 25 | match p.current() { |
26 | LIFETIME => lifetime_param(p, m), | 26 | LIFETIME => lifetime_param(p, m), |
27 | IDENT => type_param(p, m), | 27 | IDENT => type_param(p, m), |
28 | CONST_KW => type_const_param(p, m), | ||
28 | _ => { | 29 | _ => { |
29 | m.abandon(p); | 30 | m.abandon(p); |
30 | p.err_and_bump("expected type parameter") | 31 | p.err_and_bump("expected type parameter") |
@@ -62,6 +63,16 @@ fn type_param(p: &mut Parser, m: Marker) { | |||
62 | m.complete(p, TYPE_PARAM); | 63 | m.complete(p, TYPE_PARAM); |
63 | } | 64 | } |
64 | 65 | ||
66 | // test const_param | ||
67 | // struct S<const N: u32>; | ||
68 | fn type_const_param(p: &mut Parser, m: Marker) { | ||
69 | assert!(p.at(CONST_KW)); | ||
70 | p.bump(T![const]); | ||
71 | name(p); | ||
72 | types::ascription(p); | ||
73 | m.complete(p, CONST_PARAM); | ||
74 | } | ||
75 | |||
65 | // test type_param_bounds | 76 | // test type_param_bounds |
66 | // struct S<T: 'a + ?Sized + (Copy)>; | 77 | // struct S<T: 'a + ?Sized + (Copy)>; |
67 | pub(super) fn bounds(p: &mut Parser) { | 78 | pub(super) fn bounds(p: &mut Parser) { |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index afe4ce51a..af2945f57 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs | |||
@@ -229,6 +229,7 @@ pub enum SyntaxKind { | |||
229 | TYPE_PARAM_LIST, | 229 | TYPE_PARAM_LIST, |
230 | LIFETIME_PARAM, | 230 | LIFETIME_PARAM, |
231 | TYPE_PARAM, | 231 | TYPE_PARAM, |
232 | CONST_PARAM, | ||
232 | TYPE_ARG_LIST, | 233 | TYPE_ARG_LIST, |
233 | LIFETIME_ARG, | 234 | LIFETIME_ARG, |
234 | TYPE_ARG, | 235 | TYPE_ARG, |