diff options
-rw-r--r-- | src/grammar/params.rs | 32 | ||||
-rw-r--r-- | src/grammar/paths.rs | 2 | ||||
-rw-r--r-- | src/grammar/types.rs | 2 | ||||
-rw-r--r-- | tests/data/parser/inline/0096_value_parameters_no_patterns.rs | 1 | ||||
-rw-r--r-- | tests/data/parser/inline/0096_value_parameters_no_patterns.txt | 81 | ||||
-rw-r--r-- | tests/data/parser/inline/0097_param_list_opt_patterns.rs | 1 | ||||
-rw-r--r-- | tests/data/parser/inline/0097_param_list_opt_patterns.txt | 43 |
7 files changed, 151 insertions, 11 deletions
diff --git a/src/grammar/params.rs b/src/grammar/params.rs index c7f17168b..32e905cb2 100644 --- a/src/grammar/params.rs +++ b/src/grammar/params.rs | |||
@@ -33,12 +33,6 @@ impl Flavor { | |||
33 | _ => true, | 33 | _ => true, |
34 | } | 34 | } |
35 | } | 35 | } |
36 | fn pattern_required(self) -> bool { | ||
37 | match self { | ||
38 | Flavor::OptionalPattern => false, | ||
39 | _ => true, | ||
40 | } | ||
41 | } | ||
42 | } | 36 | } |
43 | 37 | ||
44 | fn list_(p: &mut Parser, flavor: Flavor) { | 38 | fn list_(p: &mut Parser, flavor: Flavor) { |
@@ -65,9 +59,29 @@ fn list_(p: &mut Parser, flavor: Flavor) { | |||
65 | 59 | ||
66 | fn value_parameter(p: &mut Parser, flavor: Flavor) { | 60 | fn value_parameter(p: &mut Parser, flavor: Flavor) { |
67 | let m = p.start(); | 61 | let m = p.start(); |
68 | patterns::pattern(p); | 62 | match flavor { |
69 | if p.at(COLON) || flavor.type_required() { | 63 | Flavor::OptionalType | Flavor::Normal => { |
70 | types::ascription(p) | 64 | patterns::pattern(p); |
65 | if p.at(COLON) || flavor.type_required() { | ||
66 | types::ascription(p) | ||
67 | } | ||
68 | }, | ||
69 | // test value_parameters_no_patterns | ||
70 | // type F = Box<Fn(a: i32, &b: &i32, &mut c: &i32, ())>; | ||
71 | Flavor::OptionalPattern => { | ||
72 | let la0 = p.current(); | ||
73 | let la1 = p.nth(1); | ||
74 | let la2 = p.nth(2); | ||
75 | let la3 = p.nth(3); | ||
76 | if la0 == IDENT && la1 == COLON | ||
77 | || la0 == AMP && la1 == IDENT && la2 == COLON | ||
78 | || la0 == AMP && la1 == MUT_KW && la2 == IDENT && la3 == COLON { | ||
79 | patterns::pattern(p); | ||
80 | types::ascription(p); | ||
81 | } else { | ||
82 | types::type_(p); | ||
83 | } | ||
84 | }, | ||
71 | } | 85 | } |
72 | m.complete(p, PARAM); | 86 | m.complete(p, PARAM); |
73 | } | 87 | } |
diff --git a/src/grammar/paths.rs b/src/grammar/paths.rs index 6d406645f..c277e2a6b 100644 --- a/src/grammar/paths.rs +++ b/src/grammar/paths.rs | |||
@@ -75,7 +75,7 @@ fn path_generic_args(p: &mut Parser, mode: Mode) { | |||
75 | // test path_fn_trait_args | 75 | // test path_fn_trait_args |
76 | // type F = Box<Fn(x: i32) -> ()>; | 76 | // type F = Box<Fn(x: i32) -> ()>; |
77 | if p.at(L_PAREN) { | 77 | if p.at(L_PAREN) { |
78 | params::param_list(p); | 78 | params::param_list_opt_patterns(p); |
79 | fn_ret_type(p); | 79 | fn_ret_type(p); |
80 | } else { | 80 | } else { |
81 | type_args::type_arg_list(p, false) | 81 | type_args::type_arg_list(p, false) |
diff --git a/src/grammar/types.rs b/src/grammar/types.rs index 03a087acd..c8ced3d28 100644 --- a/src/grammar/types.rs +++ b/src/grammar/types.rs | |||
@@ -166,7 +166,7 @@ fn fn_pointer_type(p: &mut Parser) { | |||
166 | return; | 166 | return; |
167 | } | 167 | } |
168 | 168 | ||
169 | params::param_list(p); | 169 | params::param_list_opt_patterns(p); |
170 | // test fn_pointer_type_with_ret | 170 | // test fn_pointer_type_with_ret |
171 | // type F = fn() -> (); | 171 | // type F = fn() -> (); |
172 | fn_ret_type(p); | 172 | fn_ret_type(p); |
diff --git a/tests/data/parser/inline/0096_value_parameters_no_patterns.rs b/tests/data/parser/inline/0096_value_parameters_no_patterns.rs new file mode 100644 index 000000000..d8c23c76a --- /dev/null +++ b/tests/data/parser/inline/0096_value_parameters_no_patterns.rs | |||
@@ -0,0 +1 @@ | |||
type F = Box<Fn(a: i32, &b: &i32, &mut c: &i32, ())>; | |||
diff --git a/tests/data/parser/inline/0096_value_parameters_no_patterns.txt b/tests/data/parser/inline/0096_value_parameters_no_patterns.txt new file mode 100644 index 000000000..c3f9bf685 --- /dev/null +++ b/tests/data/parser/inline/0096_value_parameters_no_patterns.txt | |||
@@ -0,0 +1,81 @@ | |||
1 | FILE@[0; 54) | ||
2 | TYPE_ITEM@[0; 53) | ||
3 | TYPE_KW@[0; 4) | ||
4 | WHITESPACE@[4; 5) | ||
5 | NAME@[5; 6) | ||
6 | IDENT@[5; 6) "F" | ||
7 | WHITESPACE@[6; 7) | ||
8 | EQ@[7; 8) | ||
9 | WHITESPACE@[8; 9) | ||
10 | PATH_TYPE@[9; 52) | ||
11 | PATH@[9; 52) | ||
12 | PATH_SEGMENT@[9; 52) | ||
13 | NAME_REF@[9; 12) | ||
14 | IDENT@[9; 12) "Box" | ||
15 | TYPE_ARG_LIST@[12; 52) | ||
16 | L_ANGLE@[12; 13) | ||
17 | TYPE_ARG@[13; 51) | ||
18 | PATH_TYPE@[13; 51) | ||
19 | PATH@[13; 51) | ||
20 | PATH_SEGMENT@[13; 51) | ||
21 | NAME_REF@[13; 15) | ||
22 | IDENT@[13; 15) "Fn" | ||
23 | PARAM_LIST@[15; 51) | ||
24 | L_PAREN@[15; 16) | ||
25 | PARAM@[16; 22) | ||
26 | BIND_PAT@[16; 17) | ||
27 | NAME@[16; 17) | ||
28 | IDENT@[16; 17) "a" | ||
29 | COLON@[17; 18) | ||
30 | WHITESPACE@[18; 19) | ||
31 | PATH_TYPE@[19; 22) | ||
32 | PATH@[19; 22) | ||
33 | PATH_SEGMENT@[19; 22) | ||
34 | NAME_REF@[19; 22) | ||
35 | IDENT@[19; 22) "i32" | ||
36 | COMMA@[22; 23) | ||
37 | WHITESPACE@[23; 24) | ||
38 | PARAM@[24; 32) | ||
39 | REF_PAT@[24; 26) | ||
40 | AMP@[24; 25) | ||
41 | BIND_PAT@[25; 26) | ||
42 | NAME@[25; 26) | ||
43 | IDENT@[25; 26) "b" | ||
44 | COLON@[26; 27) | ||
45 | WHITESPACE@[27; 28) | ||
46 | REFERENCE_TYPE@[28; 32) | ||
47 | AMP@[28; 29) | ||
48 | PATH_TYPE@[29; 32) | ||
49 | PATH@[29; 32) | ||
50 | PATH_SEGMENT@[29; 32) | ||
51 | NAME_REF@[29; 32) | ||
52 | IDENT@[29; 32) "i32" | ||
53 | COMMA@[32; 33) | ||
54 | WHITESPACE@[33; 34) | ||
55 | PARAM@[34; 46) | ||
56 | REF_PAT@[34; 40) | ||
57 | AMP@[34; 35) | ||
58 | MUT_KW@[35; 38) | ||
59 | WHITESPACE@[38; 39) | ||
60 | BIND_PAT@[39; 40) | ||
61 | NAME@[39; 40) | ||
62 | IDENT@[39; 40) "c" | ||
63 | COLON@[40; 41) | ||
64 | WHITESPACE@[41; 42) | ||
65 | REFERENCE_TYPE@[42; 46) | ||
66 | AMP@[42; 43) | ||
67 | PATH_TYPE@[43; 46) | ||
68 | PATH@[43; 46) | ||
69 | PATH_SEGMENT@[43; 46) | ||
70 | NAME_REF@[43; 46) | ||
71 | IDENT@[43; 46) "i32" | ||
72 | COMMA@[46; 47) | ||
73 | WHITESPACE@[47; 48) | ||
74 | PARAM@[48; 50) | ||
75 | TUPLE_TYPE@[48; 50) | ||
76 | L_PAREN@[48; 49) | ||
77 | R_PAREN@[49; 50) | ||
78 | R_PAREN@[50; 51) | ||
79 | R_ANGLE@[51; 52) | ||
80 | SEMI@[52; 53) | ||
81 | WHITESPACE@[53; 54) | ||
diff --git a/tests/data/parser/inline/0097_param_list_opt_patterns.rs b/tests/data/parser/inline/0097_param_list_opt_patterns.rs new file mode 100644 index 000000000..9b93442c0 --- /dev/null +++ b/tests/data/parser/inline/0097_param_list_opt_patterns.rs | |||
@@ -0,0 +1 @@ | |||
fn foo<F: FnMut(&mut Foo<'a>)>(){} | |||
diff --git a/tests/data/parser/inline/0097_param_list_opt_patterns.txt b/tests/data/parser/inline/0097_param_list_opt_patterns.txt new file mode 100644 index 000000000..f8a37aebb --- /dev/null +++ b/tests/data/parser/inline/0097_param_list_opt_patterns.txt | |||
@@ -0,0 +1,43 @@ | |||
1 | FILE@[0; 35) | ||
2 | FN_ITEM@[0; 34) | ||
3 | FN_KW@[0; 2) | ||
4 | WHITESPACE@[2; 3) | ||
5 | NAME@[3; 6) | ||
6 | IDENT@[3; 6) "foo" | ||
7 | TYPE_PARAM_LIST@[6; 30) | ||
8 | L_ANGLE@[6; 7) | ||
9 | TYPE_PARAM@[7; 29) | ||
10 | NAME@[7; 8) | ||
11 | IDENT@[7; 8) "F" | ||
12 | COLON@[8; 9) | ||
13 | WHITESPACE@[9; 10) | ||
14 | PATH@[10; 29) | ||
15 | PATH_SEGMENT@[10; 29) | ||
16 | NAME_REF@[10; 15) | ||
17 | IDENT@[10; 15) "FnMut" | ||
18 | PARAM_LIST@[15; 29) | ||
19 | L_PAREN@[15; 16) | ||
20 | PARAM@[16; 28) | ||
21 | REFERENCE_TYPE@[16; 28) | ||
22 | AMP@[16; 17) | ||
23 | MUT_KW@[17; 20) | ||
24 | WHITESPACE@[20; 21) | ||
25 | PATH_TYPE@[21; 28) | ||
26 | PATH@[21; 28) | ||
27 | PATH_SEGMENT@[21; 28) | ||
28 | NAME_REF@[21; 24) | ||
29 | IDENT@[21; 24) "Foo" | ||
30 | TYPE_ARG_LIST@[24; 28) | ||
31 | L_ANGLE@[24; 25) | ||
32 | LIFETIME_ARG@[25; 27) | ||
33 | LIFETIME@[25; 27) "'a" | ||
34 | R_ANGLE@[27; 28) | ||
35 | R_PAREN@[28; 29) | ||
36 | R_ANGLE@[29; 30) | ||
37 | PARAM_LIST@[30; 32) | ||
38 | L_PAREN@[30; 31) | ||
39 | R_PAREN@[31; 32) | ||
40 | BLOCK_EXPR@[32; 34) | ||
41 | L_CURLY@[32; 33) | ||
42 | R_CURLY@[33; 34) | ||
43 | WHITESPACE@[34; 35) | ||