aboutsummaryrefslogtreecommitdiff
path: root/src/parser/grammar/types.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-02-11 09:51:09 +0000
committerAleksey Kladov <[email protected]>2018-02-11 09:51:09 +0000
commit8a3f17a4e263781deac5e503ad5116ec78004618 (patch)
tree0b489b1784c572011dd9e25d6d0ba53e8a50f148 /src/parser/grammar/types.rs
parent2fb33b2d0d14f09ee06a42bca252dccbf57185e1 (diff)
G: fn pointer type
Diffstat (limited to 'src/parser/grammar/types.rs')
-rw-r--r--src/parser/grammar/types.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/parser/grammar/types.rs b/src/parser/grammar/types.rs
index 37b74bfe7..ea4df8639 100644
--- a/src/parser/grammar/types.rs
+++ b/src/parser/grammar/types.rs
@@ -8,6 +8,7 @@ pub(super) fn type_(p: &mut Parser) {
8 L_BRACK => array_or_slice_type(p), 8 L_BRACK => array_or_slice_type(p),
9 AMPERSAND => reference_type(p), 9 AMPERSAND => reference_type(p),
10 UNDERSCORE => placeholder_type(p), 10 UNDERSCORE => placeholder_type(p),
11 FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p),
11 IDENT => path_type(p), 12 IDENT => path_type(p),
12 _ => { 13 _ => {
13 p.error("expected type"); 14 p.error("expected type");
@@ -140,6 +141,31 @@ fn placeholder_type(p: &mut Parser) {
140 m.complete(p, PLACEHOLDER_TYPE); 141 m.complete(p, PLACEHOLDER_TYPE);
141} 142}
142 143
144// test fn_pointer_type
145// type A = fn();
146// type B = unsafe fn();
147// type C = unsafe extern "C" fn();
148fn fn_pointer_type(p: &mut Parser) {
149 let m = p.start();
150 p.eat(UNSAFE_KW);
151 if p.at(EXTERN_KW) {
152 abi(p);
153 }
154 // test fn_pointer_type_missing_fn
155 // type F = unsafe ();
156 if !p.eat(FN_KW) {
157 m.abandon(p);
158 p.error("expected `fn`");
159 return;
160 }
161
162 fn_value_parameters(p);
163 // test fn_pointer_type_with_ret
164 // type F = fn() -> ();
165 fn_ret_type(p);
166 m.complete(p, FN_POINTER_TYPE);
167}
168
143fn path_type(p: &mut Parser) { 169fn path_type(p: &mut Parser) {
144 assert!(p.at(IDENT)); 170 assert!(p.at(IDENT));
145 let m = p.start(); 171 let m = p.start();