Skip to content

Commit fae6cdf

Browse files
committed
Allow generic_param_list for static items
1 parent 7b9e26e commit fae6cdf

File tree

2 files changed

+25
-41
lines changed

2 files changed

+25
-41
lines changed

src/tools/rust-analyzer/crates/parser/src/grammar/items/consts.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,25 @@ fn const_or_static(p: &mut Parser<'_>, m: Marker, is_const: bool) {
2525
}
2626

2727
// FIXME: Recover on statics with generic params/where clause.
28-
if is_const {
29-
// test generic_const
30-
// const C<i32>: u32 = 0;
31-
// impl Foo {
32-
// const C<'a>: &'a () = &();
33-
// }
34-
generic_params::opt_generic_param_list(p);
35-
} else if p.at(T![<]) {
28+
if !is_const && p.at(T![<]) {
29+
// test_err generic_static
30+
// static C<i32>: u32 = 0;
3631
p.error("`static` may not have generic parameters");
3732
}
38-
// test_err generic_static
39-
// static C<i32>: u32 = 0;
33+
// test generic_const
34+
// const C<i32>: u32 = 0;
35+
// impl Foo {
36+
// const C<'a>: &'a () = &();
37+
// }
38+
generic_params::opt_generic_param_list(p);
4039

4140
if p.at(T![:]) {
4241
types::ascription(p);
4342
} else if is_const {
4443
// test_err missing_const_type
4544
// const C = 0;
4645
p.error("missing type for `const`");
47-
} else if !p.at(T![<]) {
46+
} else {
4847
// test_err missing_static_type
4948
// static C = 0;
5049
p.error("missing type for `static`");

src/tools/rust-analyzer/crates/parser/test_data/parser/inline/err/generic_static.rast

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,24 @@ SOURCE_FILE
44
WHITESPACE " "
55
NAME
66
IDENT "C"
7-
ERROR
8-
L_ANGLE "<"
9-
ERROR
10-
PATH
11-
PATH_SEGMENT
12-
NAME_REF
7+
GENERIC_PARAM_LIST
8+
L_ANGLE "<"
9+
TYPE_PARAM
10+
NAME
1311
IDENT "i32"
14-
ERROR
15-
R_ANGLE ">"
16-
ERROR
12+
R_ANGLE ">"
1713
COLON ":"
18-
WHITESPACE " "
19-
ERROR
20-
PATH
21-
PATH_SEGMENT
22-
NAME_REF
23-
IDENT "u32"
24-
WHITESPACE " "
25-
ERROR
14+
WHITESPACE " "
15+
PATH_TYPE
16+
PATH
17+
PATH_SEGMENT
18+
NAME_REF
19+
IDENT "u32"
20+
WHITESPACE " "
2621
EQ "="
27-
WHITESPACE " "
28-
ERROR
29-
INT_NUMBER "0"
30-
ERROR
22+
WHITESPACE " "
23+
LITERAL
24+
INT_NUMBER "0"
3125
SEMICOLON ";"
3226
WHITESPACE "\n"
3327
error 8: `static` may not have generic parameters
34-
error 8: expected SEMICOLON
35-
error 8: expected an item
36-
error 12: expected an item
37-
error 12: expected an item
38-
error 13: expected an item
39-
error 18: expected an item
40-
error 19: expected an item
41-
error 21: expected an item
42-
error 22: expected an item

0 commit comments

Comments
 (0)