aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar/types.rs
diff options
context:
space:
mode:
authorSergey Parilin <[email protected]>2019-05-15 13:35:47 +0100
committerSergey Parilin <[email protected]>2019-05-15 13:35:47 +0100
commit993abedd77cf23ce2281b6c8e60cab49ab4fa97e (patch)
treeb8693ce808a9ca2e7eaae5013644a1082fc7bb17 /crates/ra_parser/src/grammar/types.rs
parentd77175ce28da45960a89811f273b6c614d7a9413 (diff)
apply T! macro where it is possible
Diffstat (limited to 'crates/ra_parser/src/grammar/types.rs')
-rw-r--r--crates/ra_parser/src/grammar/types.rs84
1 files changed, 42 insertions, 42 deletions
diff --git a/crates/ra_parser/src/grammar/types.rs b/crates/ra_parser/src/grammar/types.rs
index 686c80f3c..438e3ab0e 100644
--- a/crates/ra_parser/src/grammar/types.rs
+++ b/crates/ra_parser/src/grammar/types.rs
@@ -17,18 +17,18 @@ pub(super) fn type_no_bounds(p: &mut Parser) {
17 17
18fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) { 18fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
19 match p.current() { 19 match p.current() {
20 L_PAREN => paren_or_tuple_type(p), 20 T!['('] => paren_or_tuple_type(p),
21 EXCL => never_type(p), 21 T![!] => never_type(p),
22 STAR => pointer_type(p), 22 T![*] => pointer_type(p),
23 L_BRACK => array_or_slice_type(p), 23 T!['['] => array_or_slice_type(p),
24 AMP => reference_type(p), 24 T![&] => reference_type(p),
25 UNDERSCORE => placeholder_type(p), 25 T![_] => placeholder_type(p),
26 FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), 26 T![fn] | T![unsafe] | T![extern] => fn_pointer_type(p),
27 FOR_KW => for_type(p), 27 T![for] => for_type(p),
28 IMPL_KW => impl_trait_type(p), 28 T![impl ] => impl_trait_type(p),
29 DYN_KW => dyn_trait_type(p), 29 T![dyn ] => dyn_trait_type(p),
30 // Some path types are not allowed to have bounds (no plus) 30 // Some path types are not allowed to have bounds (no plus)
31 L_ANGLE => path_type_(p, allow_bounds), 31 T![<] => path_type_(p, allow_bounds),
32 _ if paths::is_path_start(p) => path_or_macro_type_(p, allow_bounds), 32 _ if paths::is_path_start(p) => path_or_macro_type_(p, allow_bounds),
33 _ => { 33 _ => {
34 p.err_recover("expected type", TYPE_RECOVERY_SET); 34 p.err_recover("expected type", TYPE_RECOVERY_SET);
@@ -37,27 +37,27 @@ fn type_with_bounds_cond(p: &mut Parser, allow_bounds: bool) {
37} 37}
38 38
39pub(super) fn ascription(p: &mut Parser) { 39pub(super) fn ascription(p: &mut Parser) {
40 p.expect(COLON); 40 p.expect(T![:]);
41 type_(p) 41 type_(p)
42} 42}
43 43
44fn paren_or_tuple_type(p: &mut Parser) { 44fn paren_or_tuple_type(p: &mut Parser) {
45 assert!(p.at(L_PAREN)); 45 assert!(p.at(T!['(']));
46 let m = p.start(); 46 let m = p.start();
47 p.bump(); 47 p.bump();
48 let mut n_types: u32 = 0; 48 let mut n_types: u32 = 0;
49 let mut trailing_comma: bool = false; 49 let mut trailing_comma: bool = false;
50 while !p.at(EOF) && !p.at(R_PAREN) { 50 while !p.at(EOF) && !p.at(T![')']) {
51 n_types += 1; 51 n_types += 1;
52 type_(p); 52 type_(p);
53 if p.eat(COMMA) { 53 if p.eat(T![,]) {
54 trailing_comma = true; 54 trailing_comma = true;
55 } else { 55 } else {
56 trailing_comma = false; 56 trailing_comma = false;
57 break; 57 break;
58 } 58 }
59 } 59 }
60 p.expect(R_PAREN); 60 p.expect(T![')']);
61 61
62 let kind = if n_types == 1 && !trailing_comma { 62 let kind = if n_types == 1 && !trailing_comma {
63 // test paren_type 63 // test paren_type
@@ -77,14 +77,14 @@ fn paren_or_tuple_type(p: &mut Parser) {
77// test never_type 77// test never_type
78// type Never = !; 78// type Never = !;
79fn never_type(p: &mut Parser) { 79fn never_type(p: &mut Parser) {
80 assert!(p.at(EXCL)); 80 assert!(p.at(T![!]));
81 let m = p.start(); 81 let m = p.start();
82 p.bump(); 82 p.bump();
83 m.complete(p, NEVER_TYPE); 83 m.complete(p, NEVER_TYPE);
84} 84}
85 85
86fn pointer_type(p: &mut Parser) { 86fn pointer_type(p: &mut Parser) {
87 assert!(p.at(STAR)); 87 assert!(p.at(T![*]));
88 let m = p.start(); 88 let m = p.start();
89 p.bump(); 89 p.bump();
90 90
@@ -92,7 +92,7 @@ fn pointer_type(p: &mut Parser) {
92 // test pointer_type_mut 92 // test pointer_type_mut
93 // type M = *mut (); 93 // type M = *mut ();
94 // type C = *mut (); 94 // type C = *mut ();
95 MUT_KW | CONST_KW => p.bump(), 95 T![mut] | T![const] => p.bump(),
96 _ => { 96 _ => {
97 // test_err pointer_type_no_mutability 97 // test_err pointer_type_no_mutability
98 // type T = *(); 98 // type T = *();
@@ -108,7 +108,7 @@ fn pointer_type(p: &mut Parser) {
108} 108}
109 109
110fn array_or_slice_type(p: &mut Parser) { 110fn array_or_slice_type(p: &mut Parser) {
111 assert!(p.at(L_BRACK)); 111 assert!(p.at(T!['[']));
112 let m = p.start(); 112 let m = p.start();
113 p.bump(); 113 p.bump();
114 114
@@ -116,17 +116,17 @@ fn array_or_slice_type(p: &mut Parser) {
116 let kind = match p.current() { 116 let kind = match p.current() {
117 // test slice_type 117 // test slice_type
118 // type T = [()]; 118 // type T = [()];
119 R_BRACK => { 119 T![']'] => {
120 p.bump(); 120 p.bump();
121 SLICE_TYPE 121 SLICE_TYPE
122 } 122 }
123 123
124 // test array_type 124 // test array_type
125 // type T = [(); 92]; 125 // type T = [(); 92];
126 SEMI => { 126 T![;] => {
127 p.bump(); 127 p.bump();
128 expressions::expr(p); 128 expressions::expr(p);
129 p.expect(R_BRACK); 129 p.expect(T![']']);
130 ARRAY_TYPE 130 ARRAY_TYPE
131 } 131 }
132 // test_err array_type_missing_semi 132 // test_err array_type_missing_semi
@@ -144,11 +144,11 @@ fn array_or_slice_type(p: &mut Parser) {
144// type B = &'static (); 144// type B = &'static ();
145// type C = &mut (); 145// type C = &mut ();
146fn reference_type(p: &mut Parser) { 146fn reference_type(p: &mut Parser) {
147 assert!(p.at(AMP)); 147 assert!(p.at(T![&]));
148 let m = p.start(); 148 let m = p.start();
149 p.bump(); 149 p.bump();
150 p.eat(LIFETIME); 150 p.eat(LIFETIME);
151 p.eat(MUT_KW); 151 p.eat(T![mut]);
152 type_no_bounds(p); 152 type_no_bounds(p);
153 m.complete(p, REFERENCE_TYPE); 153 m.complete(p, REFERENCE_TYPE);
154} 154}
@@ -156,7 +156,7 @@ fn reference_type(p: &mut Parser) {
156// test placeholder_type 156// test placeholder_type
157// type Placeholder = _; 157// type Placeholder = _;
158fn placeholder_type(p: &mut Parser) { 158fn placeholder_type(p: &mut Parser) {
159 assert!(p.at(UNDERSCORE)); 159 assert!(p.at(T![_]));
160 let m = p.start(); 160 let m = p.start();
161 p.bump(); 161 p.bump();
162 m.complete(p, PLACEHOLDER_TYPE); 162 m.complete(p, PLACEHOLDER_TYPE);
@@ -169,18 +169,18 @@ fn placeholder_type(p: &mut Parser) {
169// type D = extern "C" fn ( u8 , ... ) -> u8; 169// type D = extern "C" fn ( u8 , ... ) -> u8;
170fn fn_pointer_type(p: &mut Parser) { 170fn fn_pointer_type(p: &mut Parser) {
171 let m = p.start(); 171 let m = p.start();
172 p.eat(UNSAFE_KW); 172 p.eat(T![unsafe]);
173 if p.at(EXTERN_KW) { 173 if p.at(T![extern]) {
174 abi(p); 174 abi(p);
175 } 175 }
176 // test_err fn_pointer_type_missing_fn 176 // test_err fn_pointer_type_missing_fn
177 // type F = unsafe (); 177 // type F = unsafe ();
178 if !p.eat(FN_KW) { 178 if !p.eat(T![fn]) {
179 m.abandon(p); 179 m.abandon(p);
180 p.error("expected `fn`"); 180 p.error("expected `fn`");
181 return; 181 return;
182 } 182 }
183 if p.at(L_PAREN) { 183 if p.at(T!['(']) {
184 params::param_list_opt_patterns(p); 184 params::param_list_opt_patterns(p);
185 } else { 185 } else {
186 p.error("expected parameters") 186 p.error("expected parameters")
@@ -192,9 +192,9 @@ fn fn_pointer_type(p: &mut Parser) {
192} 192}
193 193
194pub(super) fn for_binder(p: &mut Parser) { 194pub(super) fn for_binder(p: &mut Parser) {
195 assert!(p.at(FOR_KW)); 195 assert!(p.at(T![for]));
196 p.bump(); 196 p.bump();
197 if p.at(L_ANGLE) { 197 if p.at(T![<]) {
198 type_params::opt_type_param_list(p); 198 type_params::opt_type_param_list(p);
199 } else { 199 } else {
200 p.error("expected `<`"); 200 p.error("expected `<`");
@@ -206,12 +206,12 @@ pub(super) fn for_binder(p: &mut Parser) {
206// fn foo<T>(_t: &T) where for<'a> &'a T: Iterator {} 206// fn foo<T>(_t: &T) where for<'a> &'a T: Iterator {}
207// fn bar<T>(_t: &T) where for<'a> &'a mut T: Iterator {} 207// fn bar<T>(_t: &T) where for<'a> &'a mut T: Iterator {}
208pub(super) fn for_type(p: &mut Parser) { 208pub(super) fn for_type(p: &mut Parser) {
209 assert!(p.at(FOR_KW)); 209 assert!(p.at(T![for]));
210 let m = p.start(); 210 let m = p.start();
211 for_binder(p); 211 for_binder(p);
212 match p.current() { 212 match p.current() {
213 FN_KW | UNSAFE_KW | EXTERN_KW => fn_pointer_type(p), 213 T![fn] | T![unsafe] | T![extern] => fn_pointer_type(p),
214 AMP => reference_type(p), 214 T![&] => reference_type(p),
215 _ if paths::is_path_start(p) => path_type_(p, false), 215 _ if paths::is_path_start(p) => path_type_(p, false),
216 _ => p.error("expected a path"), 216 _ => p.error("expected a path"),
217 } 217 }
@@ -221,7 +221,7 @@ pub(super) fn for_type(p: &mut Parser) {
221// test impl_trait_type 221// test impl_trait_type
222// type A = impl Iterator<Item=Foo<'a>> + 'a; 222// type A = impl Iterator<Item=Foo<'a>> + 'a;
223fn impl_trait_type(p: &mut Parser) { 223fn impl_trait_type(p: &mut Parser) {
224 assert!(p.at(IMPL_KW)); 224 assert!(p.at(T![impl ]));
225 let m = p.start(); 225 let m = p.start();
226 p.bump(); 226 p.bump();
227 type_params::bounds_without_colon(p); 227 type_params::bounds_without_colon(p);
@@ -231,7 +231,7 @@ fn impl_trait_type(p: &mut Parser) {
231// test dyn_trait_type 231// test dyn_trait_type
232// type A = dyn Iterator<Item=Foo<'a>> + 'a; 232// type A = dyn Iterator<Item=Foo<'a>> + 'a;
233fn dyn_trait_type(p: &mut Parser) { 233fn dyn_trait_type(p: &mut Parser) {
234 assert!(p.at(DYN_KW)); 234 assert!(p.at(T![dyn ]));
235 let m = p.start(); 235 let m = p.start();
236 p.bump(); 236 p.bump();
237 type_params::bounds_without_colon(p); 237 type_params::bounds_without_colon(p);
@@ -251,11 +251,11 @@ pub(super) fn path_type(p: &mut Parser) {
251// type A = foo!(); 251// type A = foo!();
252// type B = crate::foo!(); 252// type B = crate::foo!();
253fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) { 253fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) {
254 assert!(paths::is_path_start(p) || p.at(L_ANGLE)); 254 assert!(paths::is_path_start(p) || p.at(T![<]));
255 let m = p.start(); 255 let m = p.start();
256 paths::type_path(p); 256 paths::type_path(p);
257 257
258 let kind = if p.at(EXCL) { 258 let kind = if p.at(T![!]) {
259 items::macro_call_after_excl(p); 259 items::macro_call_after_excl(p);
260 MACRO_CALL 260 MACRO_CALL
261 } else { 261 } else {
@@ -270,7 +270,7 @@ fn path_or_macro_type_(p: &mut Parser, allow_bounds: bool) {
270} 270}
271 271
272pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) { 272pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) {
273 assert!(paths::is_path_start(p) || p.at(L_ANGLE)); 273 assert!(paths::is_path_start(p) || p.at(T![<]));
274 let m = p.start(); 274 let m = p.start();
275 paths::type_path(p); 275 paths::type_path(p);
276 276
@@ -286,7 +286,7 @@ pub(super) fn path_type_(p: &mut Parser, allow_bounds: bool) {
286/// This turns a parsed PATH_TYPE optionally into a DYN_TRAIT_TYPE 286/// This turns a parsed PATH_TYPE optionally into a DYN_TRAIT_TYPE
287/// with a TYPE_BOUND_LIST 287/// with a TYPE_BOUND_LIST
288fn opt_path_type_bounds_as_dyn_trait_type(p: &mut Parser, path_type_marker: CompletedMarker) { 288fn opt_path_type_bounds_as_dyn_trait_type(p: &mut Parser, path_type_marker: CompletedMarker) {
289 if !p.at(PLUS) { 289 if !p.at(T![+]) {
290 return; 290 return;
291 } 291 }
292 292
@@ -298,7 +298,7 @@ fn opt_path_type_bounds_as_dyn_trait_type(p: &mut Parser, path_type_marker: Comp
298 298
299 // This gets consumed here so it gets properly set 299 // This gets consumed here so it gets properly set
300 // in the TYPE_BOUND_LIST 300 // in the TYPE_BOUND_LIST
301 p.eat(PLUS); 301 p.eat(T![+]);
302 302
303 // Parse rest of the bounds into the TYPE_BOUND_LIST 303 // Parse rest of the bounds into the TYPE_BOUND_LIST
304 let m = type_params::bounds_without_colon_m(p, m); 304 let m = type_params::bounds_without_colon_m(p, m);