Skip to content

Commit efe3263

Browse files
calixtemanmaxbrunsfeld
authored andcommitted
Function type can have a for-lifetime #51
Co-Authored-By: calixteman <[email protected]>
1 parent 6eb4797 commit efe3263

File tree

5 files changed

+70990
-69425
lines changed

5 files changed

+70990
-69425
lines changed

corpus/types.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ fn high_order3(value: i32, f: &FnOnce(i32) -> i32) -> i32 {
129129
f(value)
130130
}
131131

132+
type F = for<'a, 'b> fn(x: &'a A, y: &'a mut B<'i, 't>,) -> C;
133+
132134
---
133135

134136
(source_file
@@ -151,7 +153,13 @@ fn high_order3(value: i32, f: &FnOnce(i32) -> i32) -> i32 {
151153
(parameters
152154
(parameter (identifier) (primitive_type))
153155
(parameter (identifier) (reference_type (function_type (type_identifier) (parameters (primitive_type)) (primitive_type)))))
154-
(primitive_type) (block (call_expression (identifier) (arguments (identifier))))))
156+
(primitive_type) (block (call_expression (identifier) (arguments (identifier)))))
157+
(type_item
158+
(type_identifier)
159+
(function_type
160+
(for_lifetimes (lifetime (identifier)) (lifetime (identifier)))
161+
(parameters (parameter (identifier) (reference_type (lifetime (identifier)) (type_identifier))) (parameter (identifier) (reference_type (lifetime (identifier)) (mutable_specifier) (generic_type (type_identifier) (type_arguments (lifetime (identifier)) (lifetime (identifier)))))))
162+
(type_identifier))))
155163

156164
=================================
157165
Unsafe and extern function types

grammar.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ module.exports = grammar({
7575
[$.scoped_identifier, $.scoped_type_identifier],
7676
[$.parameters, $._pattern],
7777
[$.parameters, $.tuple_struct_pattern],
78+
[$.type_parameters, $.for_lifetimes],
7879
],
7980

8081
word: $ => $.identifier,
@@ -686,7 +687,16 @@ module.exports = grammar({
686687
']'
687688
),
688689

690+
for_lifetimes: $ => seq(
691+
'for',
692+
'<',
693+
sepBy1(',', $.lifetime,),
694+
optional(','),
695+
'>'
696+
),
697+
689698
function_type: $ => seq(
699+
optional($.for_lifetimes),
690700
optional($.function_modifiers),
691701
prec(PREC.call, seq(
692702
field('trait', choice(

src/grammar.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3809,9 +3809,75 @@
38093809
}
38103810
]
38113811
},
3812+
"for_lifetimes": {
3813+
"type": "SEQ",
3814+
"members": [
3815+
{
3816+
"type": "STRING",
3817+
"value": "for"
3818+
},
3819+
{
3820+
"type": "STRING",
3821+
"value": "<"
3822+
},
3823+
{
3824+
"type": "SEQ",
3825+
"members": [
3826+
{
3827+
"type": "SYMBOL",
3828+
"name": "lifetime"
3829+
},
3830+
{
3831+
"type": "REPEAT",
3832+
"content": {
3833+
"type": "SEQ",
3834+
"members": [
3835+
{
3836+
"type": "STRING",
3837+
"value": ","
3838+
},
3839+
{
3840+
"type": "SYMBOL",
3841+
"name": "lifetime"
3842+
}
3843+
]
3844+
}
3845+
}
3846+
]
3847+
},
3848+
{
3849+
"type": "CHOICE",
3850+
"members": [
3851+
{
3852+
"type": "STRING",
3853+
"value": ","
3854+
},
3855+
{
3856+
"type": "BLANK"
3857+
}
3858+
]
3859+
},
3860+
{
3861+
"type": "STRING",
3862+
"value": ">"
3863+
}
3864+
]
3865+
},
38123866
"function_type": {
38133867
"type": "SEQ",
38143868
"members": [
3869+
{
3870+
"type": "CHOICE",
3871+
"members": [
3872+
{
3873+
"type": "SYMBOL",
3874+
"name": "for_lifetimes"
3875+
},
3876+
{
3877+
"type": "BLANK"
3878+
}
3879+
]
3880+
},
38153881
{
38163882
"type": "CHOICE",
38173883
"members": [
@@ -8016,6 +8082,10 @@
80168082
[
80178083
"parameters",
80188084
"tuple_struct_pattern"
8085+
],
8086+
[
8087+
"type_parameters",
8088+
"for_lifetimes"
80198089
]
80208090
],
80218091
"externals": [

src/node-types.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,21 @@
15841584
]
15851585
}
15861586
},
1587+
{
1588+
"type": "for_lifetimes",
1589+
"named": true,
1590+
"fields": {},
1591+
"children": {
1592+
"multiple": true,
1593+
"required": true,
1594+
"types": [
1595+
{
1596+
"type": "lifetime",
1597+
"named": true
1598+
}
1599+
]
1600+
}
1601+
},
15871602
{
15881603
"type": "foreign_mod_item",
15891604
"named": true,
@@ -1824,9 +1839,13 @@
18241839
}
18251840
},
18261841
"children": {
1827-
"multiple": false,
1842+
"multiple": true,
18281843
"required": false,
18291844
"types": [
1845+
{
1846+
"type": "for_lifetimes",
1847+
"named": true
1848+
},
18301849
{
18311850
"type": "function_modifiers",
18321851
"named": true

0 commit comments

Comments
 (0)