diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-03-17 10:16:34 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-03-17 10:16:34 +0000 |
commit | 3ec28dd9b80dd1699f1b05fa26ab5f0551b607b6 (patch) | |
tree | e8253f38bebf21dd050484d15859b0eb893e23e0 /crates | |
parent | 7d3f48cdaf20d718e711f999573adf3303e9396a (diff) | |
parent | a1d84f5fb033113a0a0b9a0b4d9951a6a0bf04b8 (diff) |
Merge #984
984: Allow attribute on struct literal field r=matklad a=pcpthm
Cherrypicked from #980
Co-authored-by: pcpthm <[email protected]>
Diffstat (limited to 'crates')
3 files changed, 54 insertions, 1 deletions
diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index 70c71a8e1..647fedfb5 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs | |||
@@ -453,8 +453,13 @@ pub(crate) fn named_field_list(p: &mut Parser) { | |||
453 | p.bump(); | 453 | p.bump(); |
454 | while !p.at(EOF) && !p.at(R_CURLY) { | 454 | while !p.at(EOF) && !p.at(R_CURLY) { |
455 | match p.current() { | 455 | match p.current() { |
456 | IDENT => { | 456 | // test struct_literal_field_with_attr |
457 | // fn main() { | ||
458 | // S { #[cfg(test)] field: 1 } | ||
459 | // } | ||
460 | IDENT | POUND => { | ||
457 | let m = p.start(); | 461 | let m = p.start(); |
462 | attributes::outer_attributes(p); | ||
458 | name_ref(p); | 463 | name_ref(p); |
459 | if p.eat(COLON) { | 464 | if p.eat(COLON) { |
460 | expr(p); | 465 | expr(p); |
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0125_struct_literal_field_with_attr.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0125_struct_literal_field_with_attr.rs new file mode 100644 index 000000000..a6c7760c7 --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0125_struct_literal_field_with_attr.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | fn main() { | ||
2 | S { #[cfg(test)] field: 1 } | ||
3 | } | ||
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0125_struct_literal_field_with_attr.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0125_struct_literal_field_with_attr.txt new file mode 100644 index 000000000..34c80500a --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/inline/ok/0125_struct_literal_field_with_attr.txt | |||
@@ -0,0 +1,45 @@ | |||
1 | SOURCE_FILE@[0; 46) | ||
2 | FN_DEF@[0; 45) | ||
3 | FN_KW@[0; 2) | ||
4 | WHITESPACE@[2; 3) | ||
5 | NAME@[3; 7) | ||
6 | IDENT@[3; 7) "main" | ||
7 | PARAM_LIST@[7; 9) | ||
8 | L_PAREN@[7; 8) | ||
9 | R_PAREN@[8; 9) | ||
10 | WHITESPACE@[9; 10) | ||
11 | BLOCK@[10; 45) | ||
12 | L_CURLY@[10; 11) | ||
13 | WHITESPACE@[11; 16) | ||
14 | STRUCT_LIT@[16; 43) | ||
15 | PATH@[16; 17) | ||
16 | PATH_SEGMENT@[16; 17) | ||
17 | NAME_REF@[16; 17) | ||
18 | IDENT@[16; 17) "S" | ||
19 | WHITESPACE@[17; 18) | ||
20 | NAMED_FIELD_LIST@[18; 43) | ||
21 | L_CURLY@[18; 19) | ||
22 | WHITESPACE@[19; 20) | ||
23 | NAMED_FIELD@[20; 41) | ||
24 | ATTR@[20; 32) | ||
25 | POUND@[20; 21) | ||
26 | TOKEN_TREE@[21; 32) | ||
27 | L_BRACK@[21; 22) | ||
28 | IDENT@[22; 25) "cfg" | ||
29 | TOKEN_TREE@[25; 31) | ||
30 | L_PAREN@[25; 26) | ||
31 | IDENT@[26; 30) "test" | ||
32 | R_PAREN@[30; 31) | ||
33 | R_BRACK@[31; 32) | ||
34 | WHITESPACE@[32; 33) | ||
35 | NAME_REF@[33; 38) | ||
36 | IDENT@[33; 38) "field" | ||
37 | COLON@[38; 39) | ||
38 | WHITESPACE@[39; 40) | ||
39 | LITERAL@[40; 41) | ||
40 | INT_NUMBER@[40; 41) "1" | ||
41 | WHITESPACE@[41; 42) | ||
42 | R_CURLY@[42; 43) | ||
43 | WHITESPACE@[43; 44) | ||
44 | R_CURLY@[44; 45) | ||
45 | WHITESPACE@[45; 46) | ||