Skip to content

Commit b3be181

Browse files
committed
feat: allow optional trait bounds in type arguments
1 parent d8a82d6 commit b3be181

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

grammar.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ module.exports = grammar({
729729
field('alias', $._type),
730730
),
731731

732-
lifetime: $ => seq('\'', $.identifier),
732+
lifetime: $ => prec(1, seq('\'', $.identifier)),
733733

734734
array_type: $ => seq(
735735
'[',
@@ -812,12 +812,15 @@ module.exports = grammar({
812812

813813
type_arguments: $ => seq(
814814
token(prec(1, '<')),
815-
sepBy1(',', choice(
816-
$._type,
817-
$.type_binding,
818-
$.lifetime,
819-
$._literal,
820-
$.block,
815+
sepBy1(',', seq(
816+
choice(
817+
$._type,
818+
$.type_binding,
819+
$.lifetime,
820+
$._literal,
821+
$.block,
822+
),
823+
optional($.trait_bounds),
821824
)),
822825
optional(','),
823826
'>',

test/corpus/declarations.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,6 +1667,30 @@ fn univariant(this: &impl ?Sized, that: &(impl LayoutCalculator + ?Sized)) {}
16671667
(type_identifier)))))))
16681668
(block)))
16691669

1670+
================================================================================
1671+
Trait bounds in type in trait
1672+
================================================================================
1673+
1674+
impl<T: AstDeref<Target: HasNodeId>> HasNodeId for T {}
1675+
1676+
--------------------------------------------------------------------------------
1677+
1678+
(source_file
1679+
(impl_item
1680+
(type_parameters
1681+
(constrained_type_parameter
1682+
(type_identifier)
1683+
(trait_bounds
1684+
(generic_type
1685+
(type_identifier)
1686+
(type_arguments
1687+
(type_identifier)
1688+
(trait_bounds
1689+
(type_identifier)))))))
1690+
(type_identifier)
1691+
(type_identifier)
1692+
(declaration_list)))
1693+
16701694
================================================================================
16711695
Macro invocations inside trait declarations
16721696
================================================================================

0 commit comments

Comments
 (0)