Skip to content

Commit 92d9ee6

Browse files
committed
parse default const parameters
1 parent 2eaf126 commit 92d9ee6

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

grammar.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,19 @@ module.exports = grammar({
566566
field('name', $.identifier),
567567
':',
568568
field('type', $._type),
569+
optional(
570+
seq(
571+
'=',
572+
field('value',
573+
choice(
574+
$.block,
575+
$.identifier,
576+
$._literal,
577+
$.negative_literal,
578+
),
579+
),
580+
),
581+
),
569582
),
570583

571584
constrained_type_parameter: $ => seq(

test/corpus/declarations.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2413,3 +2413,29 @@ where
24132413
(type_arguments
24142414
(type_identifier))))))
24152415
(block)))
2416+
2417+
================================================================================
2418+
Const generics with default
2419+
================================================================================
2420+
2421+
pub struct Loaf<T: Sized, const N: usize = 1>([T; N]);
2422+
2423+
--------------------------------------------------------------------------------
2424+
2425+
(source_file
2426+
(struct_item
2427+
(visibility_modifier)
2428+
(type_identifier)
2429+
(type_parameters
2430+
(constrained_type_parameter
2431+
(type_identifier)
2432+
(trait_bounds
2433+
(type_identifier)))
2434+
(const_parameter
2435+
(identifier)
2436+
(primitive_type)
2437+
(integer_literal)))
2438+
(ordered_field_declaration_list
2439+
(array_type
2440+
(type_identifier)
2441+
(identifier)))))

0 commit comments

Comments
 (0)