Skip to content

Commit ba821af

Browse files
bors[bot]matklad
andauthored
Merge #4815
4815: Correctly parse <_> paths in patterns r=matklad a=matklad closes #3659 bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents d4d384e + e8d5057 commit ba821af

File tree

5 files changed

+82
-41
lines changed

5 files changed

+82
-41
lines changed

crates/ra_parser/src/grammar/paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::*;
44

55
pub(super) const PATH_FIRST: TokenSet =
6-
token_set![IDENT, SELF_KW, SUPER_KW, CRATE_KW, COLON, L_ANGLE];
6+
token_set![IDENT, T![self], T![super], T![crate], T![:], T![<]];
77

88
pub(super) fn is_path_start(p: &Parser) -> bool {
99
is_use_path_start(p) || p.at(T![<])

crates/ra_parser/src/grammar/patterns.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::*;
44

55
pub(super) const PATTERN_FIRST: TokenSet = expressions::LITERAL_FIRST
66
.union(paths::PATH_FIRST)
7-
.union(token_set![BOX_KW, REF_KW, MUT_KW, L_PAREN, L_BRACK, AMP, UNDERSCORE, MINUS, DOT]);
7+
.union(token_set![T![box], T![ref], T![mut], T!['('], T!['['], T![&], T![_], T![-], T![.]]);
88

99
pub(crate) fn pattern(p: &mut Parser) {
1010
pattern_r(p, PAT_RECOVERY_SET);
@@ -88,7 +88,9 @@ fn atom_pat(p: &mut Parser, recovery_set: TokenSet) -> Option<CompletedMarker> {
8888
_ => bind_pat(p, true),
8989
},
9090

91-
_ if paths::is_use_path_start(p) => path_or_macro_pat(p),
91+
// test type_path_in_pattern
92+
// fn main() { let <_>::Foo = (); }
93+
_ if paths::is_path_start(p) => path_or_macro_pat(p),
9294
_ if is_literal_pat_start(p) => literal_pat(p),
9395

9496
T![.] if p.at(T![..]) => dot_dot_pat(p),
@@ -138,7 +140,7 @@ fn literal_pat(p: &mut Parser) -> CompletedMarker {
138140
// let Bar(..) = ();
139141
// }
140142
fn path_or_macro_pat(p: &mut Parser) -> CompletedMarker {
141-
assert!(paths::is_use_path_start(p));
143+
assert!(paths::is_path_start(p));
142144
let m = p.start();
143145
paths::expr_path(p);
144146
let kind = match p.current() {

crates/ra_syntax/test_data/parser/err/0024_many_type_parens.rast

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -180,44 +180,45 @@ [email protected]
180180
181181
182182
183-
184-
185-
186-
187-
188-
189-
190-
191-
192-
193-
194-
195-
183+
184+
185+
186+
187+
188+
189+
190+
191+
192+
193+
194+
195+
196+
196197
197198
198199
199200
200201
201-
202-
203-
204-
205-
206-
207-
208-
209-
210-
211-
212-
213-
214-
215-
216-
217-
218-
219-
220-
202+
203+
204+
205+
206+
207+
208+
209+
210+
211+
212+
213+
214+
215+
216+
217+
218+
219+
220+
221+
221222
222223
223224
@@ -302,13 +303,12 @@ error 146..146: expected expression
302303
error 147..147: expected SEMICOLON
303304
error 148..148: expected expression
304305
error 149..149: expected SEMICOLON
305-
error 154..154: expected pattern
306-
error 155..155: expected IN_KW
307-
error 155..155: expected expression
308-
error 157..157: expected a block
306+
error 155..155: expected type
307+
error 158..158: expected IN_KW
309308
error 165..165: expected expression
310309
error 168..168: expected expression
311310
error 179..179: expected expression
311+
error 180..180: expected a block
312312
error 180..180: expected COMMA
313313
error 180..180: expected expression
314314
error 180..180: expected R_PAREN
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() { let <_>::Foo = (); }

0 commit comments

Comments
 (0)