diff options
author | Aleksey Kladov <[email protected]> | 2018-08-08 16:34:26 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-08 16:34:26 +0100 |
commit | 8f21afacfc981e93f2ad78cd340e9b6c0e821d92 (patch) | |
tree | de7edde0b99d913c9f6ec049f794e71a26f1cecc /src/grammar | |
parent | de7b1887ae46c78c3c0abf6d264b2649b1b5cf0b (diff) |
Optional patterns in fn types
Diffstat (limited to 'src/grammar')
-rw-r--r-- | src/grammar/params.rs | 32 | ||||
-rw-r--r-- | src/grammar/paths.rs | 2 | ||||
-rw-r--r-- | src/grammar/types.rs | 2 |
3 files changed, 25 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); |