diff options
author | DJMcNab <[email protected]> | 2019-01-28 20:03:56 +0000 |
---|---|---|
committer | DJMcNab <[email protected]> | 2019-01-28 20:03:56 +0000 |
commit | 00e6b5d26c82d5faff066c24418a0eb5741efcd1 (patch) | |
tree | 82ad741bab4f820850ba6f13e2b760cc840f43fb /crates/ra_syntax/tests/data | |
parent | 137b1ccb715fe795cdf6c528bef6f8df3387f158 (diff) |
Parse and validate attributes in blocks
Diffstat (limited to 'crates/ra_syntax/tests/data')
4 files changed, 316 insertions, 0 deletions
diff --git a/crates/ra_syntax/tests/data/parser/err/0031_block_inner_attrs.rs b/crates/ra_syntax/tests/data/parser/err/0031_block_inner_attrs.rs new file mode 100644 index 000000000..6a04f2d0a --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/err/0031_block_inner_attrs.rs | |||
@@ -0,0 +1,15 @@ | |||
1 | fn block() { | ||
2 | let inner = { | ||
3 | #![doc("Inner attributes not allowed here")] | ||
4 | //! Nor are ModuleDoc comments | ||
5 | }; | ||
6 | if true { | ||
7 | #![doc("Nor here")] | ||
8 | #![doc("We error on each attr")] | ||
9 | //! Nor are ModuleDoc comments | ||
10 | } | ||
11 | while true { | ||
12 | #![doc("Nor here")] | ||
13 | //! Nor are ModuleDoc comments | ||
14 | } | ||
15 | } | ||
diff --git a/crates/ra_syntax/tests/data/parser/err/0031_block_inner_attrs.txt b/crates/ra_syntax/tests/data/parser/err/0031_block_inner_attrs.txt new file mode 100644 index 000000000..086aa79ac --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/err/0031_block_inner_attrs.txt | |||
@@ -0,0 +1,114 @@ | |||
1 | SOURCE_FILE@[0; 350) | ||
2 | FN_DEF@[0; 349) | ||
3 | FN_KW@[0; 2) | ||
4 | WHITESPACE@[2; 3) | ||
5 | NAME@[3; 8) | ||
6 | IDENT@[3; 8) "block" | ||
7 | PARAM_LIST@[8; 10) | ||
8 | L_PAREN@[8; 9) | ||
9 | R_PAREN@[9; 10) | ||
10 | WHITESPACE@[10; 11) | ||
11 | BLOCK@[11; 349) | ||
12 | L_CURLY@[11; 12) | ||
13 | WHITESPACE@[12; 17) | ||
14 | LET_STMT@[17; 129) | ||
15 | LET_KW@[17; 20) | ||
16 | WHITESPACE@[20; 21) | ||
17 | BIND_PAT@[21; 26) | ||
18 | NAME@[21; 26) | ||
19 | IDENT@[21; 26) "inner" | ||
20 | WHITESPACE@[26; 27) | ||
21 | EQ@[27; 28) | ||
22 | WHITESPACE@[28; 29) | ||
23 | BLOCK_EXPR@[29; 128) | ||
24 | BLOCK@[29; 128) | ||
25 | L_CURLY@[29; 30) | ||
26 | WHITESPACE@[30; 39) | ||
27 | err: `A block in this position cannot accept inner attributes` | ||
28 | ATTR@[39; 83) | ||
29 | POUND@[39; 40) | ||
30 | EXCL@[40; 41) | ||
31 | TOKEN_TREE@[41; 83) | ||
32 | L_BRACK@[41; 42) | ||
33 | IDENT@[42; 45) "doc" | ||
34 | TOKEN_TREE@[45; 82) | ||
35 | L_PAREN@[45; 46) | ||
36 | STRING@[46; 81) | ||
37 | R_PAREN@[81; 82) | ||
38 | R_BRACK@[82; 83) | ||
39 | WHITESPACE@[83; 92) | ||
40 | COMMENT@[92; 122) | ||
41 | WHITESPACE@[122; 127) | ||
42 | R_CURLY@[127; 128) | ||
43 | SEMI@[128; 129) | ||
44 | WHITESPACE@[129; 134) | ||
45 | EXPR_STMT@[134; 257) | ||
46 | IF_EXPR@[134; 257) | ||
47 | IF_KW@[134; 136) | ||
48 | WHITESPACE@[136; 137) | ||
49 | CONDITION@[137; 141) | ||
50 | LITERAL@[137; 141) | ||
51 | TRUE_KW@[137; 141) | ||
52 | WHITESPACE@[141; 142) | ||
53 | BLOCK@[142; 257) | ||
54 | L_CURLY@[142; 143) | ||
55 | WHITESPACE@[143; 152) | ||
56 | err: `A block in this position cannot accept inner attributes` | ||
57 | ATTR@[152; 171) | ||
58 | POUND@[152; 153) | ||
59 | EXCL@[153; 154) | ||
60 | TOKEN_TREE@[154; 171) | ||
61 | L_BRACK@[154; 155) | ||
62 | IDENT@[155; 158) "doc" | ||
63 | TOKEN_TREE@[158; 170) | ||
64 | L_PAREN@[158; 159) | ||
65 | STRING@[159; 169) | ||
66 | R_PAREN@[169; 170) | ||
67 | R_BRACK@[170; 171) | ||
68 | WHITESPACE@[171; 180) | ||
69 | err: `A block in this position cannot accept inner attributes` | ||
70 | ATTR@[180; 212) | ||
71 | POUND@[180; 181) | ||
72 | EXCL@[181; 182) | ||
73 | TOKEN_TREE@[182; 212) | ||
74 | L_BRACK@[182; 183) | ||
75 | IDENT@[183; 186) "doc" | ||
76 | TOKEN_TREE@[186; 211) | ||
77 | L_PAREN@[186; 187) | ||
78 | STRING@[187; 210) | ||
79 | R_PAREN@[210; 211) | ||
80 | R_BRACK@[211; 212) | ||
81 | WHITESPACE@[212; 221) | ||
82 | COMMENT@[221; 251) | ||
83 | WHITESPACE@[251; 256) | ||
84 | R_CURLY@[256; 257) | ||
85 | WHITESPACE@[257; 262) | ||
86 | WHILE_EXPR@[262; 347) | ||
87 | WHILE_KW@[262; 267) | ||
88 | WHITESPACE@[267; 268) | ||
89 | CONDITION@[268; 272) | ||
90 | LITERAL@[268; 272) | ||
91 | TRUE_KW@[268; 272) | ||
92 | WHITESPACE@[272; 273) | ||
93 | BLOCK@[273; 347) | ||
94 | L_CURLY@[273; 274) | ||
95 | WHITESPACE@[274; 283) | ||
96 | err: `A block in this position cannot accept inner attributes` | ||
97 | ATTR@[283; 302) | ||
98 | POUND@[283; 284) | ||
99 | EXCL@[284; 285) | ||
100 | TOKEN_TREE@[285; 302) | ||
101 | L_BRACK@[285; 286) | ||
102 | IDENT@[286; 289) "doc" | ||
103 | TOKEN_TREE@[289; 301) | ||
104 | L_PAREN@[289; 290) | ||
105 | STRING@[290; 300) | ||
106 | R_PAREN@[300; 301) | ||
107 | R_BRACK@[301; 302) | ||
108 | WHITESPACE@[302; 311) | ||
109 | COMMENT@[311; 341) | ||
110 | WHITESPACE@[341; 346) | ||
111 | R_CURLY@[346; 347) | ||
112 | WHITESPACE@[347; 348) | ||
113 | R_CURLY@[348; 349) | ||
114 | WHITESPACE@[349; 350) | ||
diff --git a/crates/ra_syntax/tests/data/parser/ok/0045_block_inner_attrs.rs b/crates/ra_syntax/tests/data/parser/ok/0045_block_inner_attrs.rs new file mode 100644 index 000000000..88df8138e --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/ok/0045_block_inner_attrs.rs | |||
@@ -0,0 +1,20 @@ | |||
1 | fn block() { | ||
2 | #![doc("Inner attributes allowed here")] | ||
3 | //! As are ModuleDoc style comments | ||
4 | { | ||
5 | #![doc("Inner attributes are allowed in blocks used as statements")] | ||
6 | #![doc("Being validated is not affected by duplcates")] | ||
7 | //! As are ModuleDoc style comments | ||
8 | }; | ||
9 | { | ||
10 | #![doc("Inner attributes are allowed in blocks when they are the last statement of another block")] | ||
11 | //! As are ModuleDoc style comments | ||
12 | } | ||
13 | } | ||
14 | |||
15 | // https://github.com/rust-analyzer/rust-analyzer/issues/689 | ||
16 | impl Whatever { | ||
17 | fn salsa_event(&self, event_fn: impl Fn() -> Event<Self>) { | ||
18 | #![allow(unused_variables)] // this is `inner_attr` of the block | ||
19 | } | ||
20 | } | ||
diff --git a/crates/ra_syntax/tests/data/parser/ok/0045_block_inner_attrs.txt b/crates/ra_syntax/tests/data/parser/ok/0045_block_inner_attrs.txt new file mode 100644 index 000000000..a1ba645ef --- /dev/null +++ b/crates/ra_syntax/tests/data/parser/ok/0045_block_inner_attrs.txt | |||
@@ -0,0 +1,167 @@ | |||
1 | SOURCE_FILE@[0; 686) | ||
2 | FN_DEF@[0; 461) | ||
3 | FN_KW@[0; 2) | ||
4 | WHITESPACE@[2; 3) | ||
5 | NAME@[3; 8) | ||
6 | IDENT@[3; 8) "block" | ||
7 | PARAM_LIST@[8; 10) | ||
8 | L_PAREN@[8; 9) | ||
9 | R_PAREN@[9; 10) | ||
10 | WHITESPACE@[10; 11) | ||
11 | BLOCK@[11; 461) | ||
12 | L_CURLY@[11; 12) | ||
13 | WHITESPACE@[12; 17) | ||
14 | ATTR@[17; 57) | ||
15 | POUND@[17; 18) | ||
16 | EXCL@[18; 19) | ||
17 | TOKEN_TREE@[19; 57) | ||
18 | L_BRACK@[19; 20) | ||
19 | IDENT@[20; 23) "doc" | ||
20 | TOKEN_TREE@[23; 56) | ||
21 | L_PAREN@[23; 24) | ||
22 | STRING@[24; 55) | ||
23 | R_PAREN@[55; 56) | ||
24 | R_BRACK@[56; 57) | ||
25 | WHITESPACE@[57; 62) | ||
26 | COMMENT@[62; 97) | ||
27 | WHITESPACE@[97; 102) | ||
28 | EXPR_STMT@[102; 295) | ||
29 | BLOCK_EXPR@[102; 294) | ||
30 | BLOCK@[102; 294) | ||
31 | L_CURLY@[102; 103) | ||
32 | WHITESPACE@[103; 112) | ||
33 | ATTR@[112; 180) | ||
34 | POUND@[112; 113) | ||
35 | EXCL@[113; 114) | ||
36 | TOKEN_TREE@[114; 180) | ||
37 | L_BRACK@[114; 115) | ||
38 | IDENT@[115; 118) "doc" | ||
39 | TOKEN_TREE@[118; 179) | ||
40 | L_PAREN@[118; 119) | ||
41 | STRING@[119; 178) | ||
42 | R_PAREN@[178; 179) | ||
43 | R_BRACK@[179; 180) | ||
44 | WHITESPACE@[180; 189) | ||
45 | ATTR@[189; 244) | ||
46 | POUND@[189; 190) | ||
47 | EXCL@[190; 191) | ||
48 | TOKEN_TREE@[191; 244) | ||
49 | L_BRACK@[191; 192) | ||
50 | IDENT@[192; 195) "doc" | ||
51 | TOKEN_TREE@[195; 243) | ||
52 | L_PAREN@[195; 196) | ||
53 | STRING@[196; 242) | ||
54 | R_PAREN@[242; 243) | ||
55 | R_BRACK@[243; 244) | ||
56 | WHITESPACE@[244; 253) | ||
57 | COMMENT@[253; 288) | ||
58 | WHITESPACE@[288; 293) | ||
59 | R_CURLY@[293; 294) | ||
60 | SEMI@[294; 295) | ||
61 | WHITESPACE@[295; 300) | ||
62 | BLOCK_EXPR@[300; 459) | ||
63 | BLOCK@[300; 459) | ||
64 | L_CURLY@[300; 301) | ||
65 | WHITESPACE@[301; 310) | ||
66 | ATTR@[310; 409) | ||
67 | POUND@[310; 311) | ||
68 | EXCL@[311; 312) | ||
69 | TOKEN_TREE@[312; 409) | ||
70 | L_BRACK@[312; 313) | ||
71 | IDENT@[313; 316) "doc" | ||
72 | TOKEN_TREE@[316; 408) | ||
73 | L_PAREN@[316; 317) | ||
74 | STRING@[317; 407) | ||
75 | R_PAREN@[407; 408) | ||
76 | R_BRACK@[408; 409) | ||
77 | WHITESPACE@[409; 418) | ||
78 | COMMENT@[418; 453) | ||
79 | WHITESPACE@[453; 458) | ||
80 | R_CURLY@[458; 459) | ||
81 | WHITESPACE@[459; 460) | ||
82 | R_CURLY@[460; 461) | ||
83 | WHITESPACE@[461; 463) | ||
84 | COMMENT@[463; 523) | ||
85 | WHITESPACE@[523; 524) | ||
86 | IMPL_BLOCK@[524; 685) | ||
87 | IMPL_KW@[524; 528) | ||
88 | WHITESPACE@[528; 529) | ||
89 | PATH_TYPE@[529; 537) | ||
90 | PATH@[529; 537) | ||
91 | PATH_SEGMENT@[529; 537) | ||
92 | NAME_REF@[529; 537) | ||
93 | IDENT@[529; 537) "Whatever" | ||
94 | WHITESPACE@[537; 538) | ||
95 | ITEM_LIST@[538; 685) | ||
96 | L_CURLY@[538; 539) | ||
97 | WHITESPACE@[539; 544) | ||
98 | FN_DEF@[544; 683) | ||
99 | FN_KW@[544; 546) | ||
100 | WHITESPACE@[546; 547) | ||
101 | NAME@[547; 558) | ||
102 | IDENT@[547; 558) "salsa_event" | ||
103 | PARAM_LIST@[558; 601) | ||
104 | L_PAREN@[558; 559) | ||
105 | SELF_PARAM@[559; 564) | ||
106 | AMP@[559; 560) | ||
107 | SELF_KW@[560; 564) | ||
108 | COMMA@[564; 565) | ||
109 | WHITESPACE@[565; 566) | ||
110 | PARAM@[566; 600) | ||
111 | BIND_PAT@[566; 574) | ||
112 | NAME@[566; 574) | ||
113 | IDENT@[566; 574) "event_fn" | ||
114 | COLON@[574; 575) | ||
115 | WHITESPACE@[575; 576) | ||
116 | IMPL_TRAIT_TYPE@[576; 600) | ||
117 | IMPL_KW@[576; 580) | ||
118 | WHITESPACE@[580; 581) | ||
119 | PATH_TYPE@[581; 600) | ||
120 | PATH@[581; 600) | ||
121 | PATH_SEGMENT@[581; 600) | ||
122 | NAME_REF@[581; 583) | ||
123 | IDENT@[581; 583) "Fn" | ||
124 | PARAM_LIST@[583; 585) | ||
125 | L_PAREN@[583; 584) | ||
126 | R_PAREN@[584; 585) | ||
127 | WHITESPACE@[585; 586) | ||
128 | RET_TYPE@[586; 600) | ||
129 | THIN_ARROW@[586; 588) | ||
130 | WHITESPACE@[588; 589) | ||
131 | PATH_TYPE@[589; 600) | ||
132 | PATH@[589; 600) | ||
133 | PATH_SEGMENT@[589; 600) | ||
134 | NAME_REF@[589; 594) | ||
135 | IDENT@[589; 594) "Event" | ||
136 | TYPE_ARG_LIST@[594; 600) | ||
137 | L_ANGLE@[594; 595) | ||
138 | TYPE_ARG@[595; 599) | ||
139 | PATH_TYPE@[595; 599) | ||
140 | PATH@[595; 599) | ||
141 | PATH_SEGMENT@[595; 599) | ||
142 | NAME_REF@[595; 599) | ||
143 | IDENT@[595; 599) "Self" | ||
144 | R_ANGLE@[599; 600) | ||
145 | R_PAREN@[600; 601) | ||
146 | WHITESPACE@[601; 602) | ||
147 | BLOCK@[602; 683) | ||
148 | L_CURLY@[602; 603) | ||
149 | WHITESPACE@[603; 612) | ||
150 | ATTR@[612; 639) | ||
151 | POUND@[612; 613) | ||
152 | EXCL@[613; 614) | ||
153 | TOKEN_TREE@[614; 639) | ||
154 | L_BRACK@[614; 615) | ||
155 | IDENT@[615; 620) "allow" | ||
156 | TOKEN_TREE@[620; 638) | ||
157 | L_PAREN@[620; 621) | ||
158 | IDENT@[621; 637) "unused_variables" | ||
159 | R_PAREN@[637; 638) | ||
160 | R_BRACK@[638; 639) | ||
161 | WHITESPACE@[639; 640) | ||
162 | COMMENT@[640; 677) | ||
163 | WHITESPACE@[677; 682) | ||
164 | R_CURLY@[682; 683) | ||
165 | WHITESPACE@[683; 684) | ||
166 | R_CURLY@[684; 685) | ||
167 | WHITESPACE@[685; 686) | ||