Skip to content

Commit 6a6d0ff

Browse files
committed
parse turbofishes in patterns
1 parent 2eaf126 commit 6a6d0ff

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

grammar.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,7 @@ module.exports = grammar({
13411341
alias(choice(...primitiveTypes), $.identifier),
13421342
$.identifier,
13431343
$.scoped_identifier,
1344+
$.identifier_with_turbofish,
13441345
$.tuple_pattern,
13451346
$.tuple_struct_pattern,
13461347
$.struct_pattern,
@@ -1358,6 +1359,15 @@ module.exports = grammar({
13581359
'_',
13591360
),
13601361

1362+
identifier_with_turbofish: $ => seq(
1363+
choice(
1364+
$.identifier,
1365+
$.scoped_identifier,
1366+
),
1367+
'::',
1368+
field('type_arguments', $.type_arguments),
1369+
),
1370+
13611371
tuple_pattern: $ => seq(
13621372
'(',
13631373
sepBy(',', choice($._pattern, $.closure_expression)),

test/corpus/patterns.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,3 +520,30 @@ fn foo(x: i32) {
520520
(match_arm
521521
pattern: (match_pattern)
522522
value: (block))))))))
523+
524+
================================================================================
525+
Pattern with turbofish
526+
================================================================================
527+
528+
match y {
529+
None::<T> => 17,
530+
_ => 42,
531+
}
532+
533+
--------------------------------------------------------------------------------
534+
535+
(source_file
536+
(expression_statement
537+
(match_expression
538+
(identifier)
539+
(match_block
540+
(match_arm
541+
(match_pattern
542+
(identifier_with_turbofish
543+
(identifier)
544+
(type_arguments
545+
(type_identifier))))
546+
(integer_literal))
547+
(match_arm
548+
(match_pattern)
549+
(integer_literal))))))

0 commit comments

Comments
 (0)