aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_syntax/src/grammar/attributes.rs10
-rw-r--r--crates/ra_syntax/src/grammar/expressions/atom.rs7
-rw-r--r--crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt90
3 files changed, 60 insertions, 47 deletions
diff --git a/crates/ra_syntax/src/grammar/attributes.rs b/crates/ra_syntax/src/grammar/attributes.rs
index 2624d2e16..cd30e8a45 100644
--- a/crates/ra_syntax/src/grammar/attributes.rs
+++ b/crates/ra_syntax/src/grammar/attributes.rs
@@ -1,15 +1,5 @@
1use super::*; 1use super::*;
2 2
3/// Parses both inner & outer attributes.
4///
5/// Allowing to run validation for reporting errors
6/// regarding attributes
7pub(super) fn all_attributes(p: &mut Parser) {
8 while p.at(POUND) {
9 attribute(p, p.nth(1) == EXCL)
10 }
11}
12
13pub(super) fn inner_attributes(p: &mut Parser) { 3pub(super) fn inner_attributes(p: &mut Parser) {
14 while p.current() == POUND && p.nth(1) == EXCL { 4 while p.current() == POUND && p.nth(1) == EXCL {
15 attribute(p, true) 5 attribute(p, true)
diff --git a/crates/ra_syntax/src/grammar/expressions/atom.rs b/crates/ra_syntax/src/grammar/expressions/atom.rs
index 67cd7e6b0..e74305b6a 100644
--- a/crates/ra_syntax/src/grammar/expressions/atom.rs
+++ b/crates/ra_syntax/src/grammar/expressions/atom.rs
@@ -331,11 +331,6 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
331 continue; 331 continue;
332 } 332 }
333 333
334 // This may result in invalid attributes
335 // if there are inner attributes mixed in together
336 // with the outer attributes, but we allow parsing
337 // those so we can run validation and report better errors
338
339 // test match_arms_outer_attributes 334 // test match_arms_outer_attributes
340 // fn foo() { 335 // fn foo() {
341 // match () { 336 // match () {
@@ -349,7 +344,7 @@ pub(crate) fn match_arm_list(p: &mut Parser) {
349 // _ => (), 344 // _ => (),
350 // } 345 // }
351 // } 346 // }
352 attributes::all_attributes(p); 347 attributes::outer_attributes(p);
353 348
354 // test match_arms_commas 349 // test match_arms_commas
355 // fn foo() { 350 // fn foo() {
diff --git a/crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt b/crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt
index b3ff36364..b7543abc9 100644
--- a/crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt
+++ b/crates/ra_syntax/tests/data/parser/err/0032_match_arms_inner_attrs.txt
@@ -33,18 +33,29 @@ SOURCE_FILE@[0; 293)
33 R_PAREN@[40; 41) 33 R_PAREN@[40; 41)
34 COMMA@[41; 42) 34 COMMA@[41; 42)
35 WHITESPACE@[42; 51) 35 WHITESPACE@[42; 51)
36 err: `Inner attributes are only allowed directly after the opening brace of the match expression` 36 ATTR@[51; 52)
37 ATTR@[51; 78)
38 POUND@[51; 52) 37 POUND@[51; 52)
39 EXCL@[52; 53) 38 err: `expected `[``
40 TOKEN_TREE@[53; 78) 39 err: `expected pattern`
40 MATCH_ARM@[52; 78)
41 ERROR@[52; 53)
42 EXCL@[52; 53)
43 err: `expected FAT_ARROW`
44 ARRAY_EXPR@[53; 78)
41 L_BRACK@[53; 54) 45 L_BRACK@[53; 54)
42 IDENT@[54; 57) "doc" 46 CALL_EXPR@[54; 77)
43 TOKEN_TREE@[57; 77) 47 PATH_EXPR@[54; 57)
44 L_PAREN@[57; 58) 48 PATH@[54; 57)
45 STRING@[58; 76) 49 PATH_SEGMENT@[54; 57)
46 R_PAREN@[76; 77) 50 NAME_REF@[54; 57)
51 IDENT@[54; 57) "doc"
52 ARG_LIST@[57; 77)
53 L_PAREN@[57; 58)
54 LITERAL@[58; 76)
55 STRING@[58; 76)
56 R_PAREN@[76; 77)
47 R_BRACK@[77; 78) 57 R_BRACK@[77; 78)
58 err: `expected COMMA`
48 WHITESPACE@[78; 87) 59 WHITESPACE@[78; 87)
49 MATCH_ARM@[87; 94) 60 MATCH_ARM@[87; 94)
50 PLACEHOLDER_PAT@[87; 88) 61 PLACEHOLDER_PAT@[87; 88)
@@ -92,23 +103,29 @@ SOURCE_FILE@[0; 293)
92 R_PAREN@[149; 150) 103 R_PAREN@[149; 150)
93 COMMA@[150; 151) 104 COMMA@[150; 151)
94 WHITESPACE@[151; 160) 105 WHITESPACE@[151; 160)
95 err: `Inner attributes are only allowed directly after the opening brace of the match expression` 106 ATTR@[160; 161)
96 ATTR@[160; 179)
97 POUND@[160; 161) 107 POUND@[160; 161)
98 EXCL@[161; 162) 108 err: `expected `[``
99 TOKEN_TREE@[162; 179) 109 err: `expected pattern`
110 MATCH_ARM@[161; 179)
111 ERROR@[161; 162)
112 EXCL@[161; 162)
113 err: `expected FAT_ARROW`
114 ARRAY_EXPR@[162; 179)
100 L_BRACK@[162; 163) 115 L_BRACK@[162; 163)
101 IDENT@[163; 166) "doc" 116 CALL_EXPR@[163; 178)
102 TOKEN_TREE@[166; 178) 117 PATH_EXPR@[163; 166)
103 L_PAREN@[166; 167) 118 PATH@[163; 166)
104 STRING@[167; 177) 119 PATH_SEGMENT@[163; 166)
105 R_PAREN@[177; 178) 120 NAME_REF@[163; 166)
121 IDENT@[163; 166) "doc"
122 ARG_LIST@[166; 178)
123 L_PAREN@[166; 167)
124 LITERAL@[167; 177)
125 STRING@[167; 177)
126 R_PAREN@[177; 178)
106 R_BRACK@[178; 179) 127 R_BRACK@[178; 179)
107 WHITESPACE@[179; 184) 128 WHITESPACE@[179; 184)
108 err: `expected pattern`
109 err: `expected FAT_ARROW`
110 err: `expected expression`
111 MATCH_ARM@[184; 184)
112 R_CURLY@[184; 185) 129 R_CURLY@[184; 185)
113 WHITESPACE@[185; 191) 130 WHITESPACE@[185; 191)
114 MATCH_EXPR@[191; 290) 131 MATCH_EXPR@[191; 290)
@@ -132,18 +149,29 @@ SOURCE_FILE@[0; 293)
132 R_PAREN@[220; 221) 149 R_PAREN@[220; 221)
133 R_BRACK@[221; 222) 150 R_BRACK@[221; 222)
134 WHITESPACE@[222; 231) 151 WHITESPACE@[222; 231)
135 err: `Inner attributes are only allowed directly after the opening brace of the match expression` 152 ATTR@[231; 232)
136 ATTR@[231; 250)
137 POUND@[231; 232) 153 POUND@[231; 232)
138 EXCL@[232; 233) 154 err: `expected `[``
139 TOKEN_TREE@[233; 250) 155 err: `expected pattern`
156 MATCH_ARM@[232; 250)
157 ERROR@[232; 233)
158 EXCL@[232; 233)
159 err: `expected FAT_ARROW`
160 ARRAY_EXPR@[233; 250)
140 L_BRACK@[233; 234) 161 L_BRACK@[233; 234)
141 IDENT@[234; 237) "doc" 162 CALL_EXPR@[234; 249)
142 TOKEN_TREE@[237; 249) 163 PATH_EXPR@[234; 237)
143 L_PAREN@[237; 238) 164 PATH@[234; 237)
144 STRING@[238; 248) 165 PATH_SEGMENT@[234; 237)
145 R_PAREN@[248; 249) 166 NAME_REF@[234; 237)
167 IDENT@[234; 237) "doc"
168 ARG_LIST@[237; 249)
169 L_PAREN@[237; 238)
170 LITERAL@[238; 248)
171 STRING@[238; 248)
172 R_PAREN@[248; 249)
146 R_BRACK@[249; 250) 173 R_BRACK@[249; 250)
174 err: `expected COMMA`
147 WHITESPACE@[250; 259) 175 WHITESPACE@[250; 259)
148 MATCH_ARM@[259; 266) 176 MATCH_ARM@[259; 266)
149 PLACEHOLDER_PAT@[259; 260) 177 PLACEHOLDER_PAT@[259; 260)