aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/grammar/params.rs
diff options
context:
space:
mode:
authorToby Dimmick <[email protected]>2020-02-07 12:36:33 +0000
committerToby Dimmick <[email protected]>2020-02-07 12:36:33 +0000
commit90ff2be4e820601a1d16ba5716916f7424dfa10d (patch)
tree2267d5456f9f16ced879da399586d7802e933d64 /crates/ra_parser/src/grammar/params.rs
parent0183952d2e1252a030aca3dafd8d7abe093be3a2 (diff)
PR tweaks
Diffstat (limited to 'crates/ra_parser/src/grammar/params.rs')
-rw-r--r--crates/ra_parser/src/grammar/params.rs35
1 files changed, 16 insertions, 19 deletions
diff --git a/crates/ra_parser/src/grammar/params.rs b/crates/ra_parser/src/grammar/params.rs
index d9fbc7c94..94edc7f35 100644
--- a/crates/ra_parser/src/grammar/params.rs
+++ b/crates/ra_parser/src/grammar/params.rs
@@ -7,14 +7,14 @@ use super::*;
7// fn b(x: i32) {} 7// fn b(x: i32) {}
8// fn c(x: i32, ) {} 8// fn c(x: i32, ) {}
9// fn d(x: i32, y: ()) {} 9// fn d(x: i32, y: ()) {}
10pub(super) fn param_list_fn(p: &mut Parser) { 10pub(super) fn param_list_fn_def(p: &mut Parser) {
11 list_(p, Flavor::Function) 11 list_(p, Flavor::FnDef)
12} 12}
13 13
14// test param_list_opt_patterns 14// test param_list_opt_patterns
15// fn foo<F: FnMut(&mut Foo<'a>)>(){} 15// fn foo<F: FnMut(&mut Foo<'a>)>(){}
16pub(super) fn param_list_impl_fn(p: &mut Parser) { 16pub(super) fn param_list_fn_trait(p: &mut Parser) {
17 list_(p, Flavor::ImplFn) 17 list_(p, Flavor::FnTrait)
18} 18}
19 19
20pub(super) fn param_list_fn_ptr(p: &mut Parser) { 20pub(super) fn param_list_fn_ptr(p: &mut Parser) {
@@ -27,8 +27,8 @@ pub(super) fn param_list_closure(p: &mut Parser) {
27 27
28#[derive(Debug, Clone, Copy)] 28#[derive(Debug, Clone, Copy)]
29enum Flavor { 29enum Flavor {
30 Function, // Includes trait fn params; omitted param idents are not supported 30 FnDef, // Includes trait fn params; omitted param idents are not supported
31 ImplFn, 31 FnTrait, // Params for `Fn(...)`/`FnMut(...)`/`FnOnce(...)` annotations
32 FnPointer, 32 FnPointer,
33 Closure, 33 Closure,
34} 34}
@@ -38,13 +38,13 @@ fn list_(p: &mut Parser, flavor: Flavor) {
38 38
39 let (bra, ket) = match flavor { 39 let (bra, ket) = match flavor {
40 Closure => (T![|], T![|]), 40 Closure => (T![|], T![|]),
41 Function | ImplFn | FnPointer => (T!['('], T![')']), 41 FnDef | FnTrait | FnPointer => (T!['('], T![')']),
42 }; 42 };
43 43
44 let m = p.start(); 44 let m = p.start();
45 p.bump(bra); 45 p.bump(bra);
46 46
47 if let Function = flavor { 47 if let FnDef = flavor {
48 // test self_param_outer_attr 48 // test self_param_outer_attr
49 // fn f(#[must_use] self) {} 49 // fn f(#[must_use] self) {}
50 attributes::outer_attributes(p); 50 attributes::outer_attributes(p);
@@ -56,10 +56,11 @@ fn list_(p: &mut Parser, flavor: Flavor) {
56 // fn f(#[attr1] pat: Type) {} 56 // fn f(#[attr1] pat: Type) {}
57 attributes::outer_attributes(p); 57 attributes::outer_attributes(p);
58 58
59 if let Function | FnPointer = flavor { 59 // test param_list_vararg
60 if p.at(T![...]) { 60 // extern "C" { fn printf(format: *const i8, ...) -> i32; }
61 break; 61 match flavor {
62 } 62 FnDef | FnPointer if p.eat(T![...]) => break,
63 _ => (),
63 } 64 }
64 65
65 if !p.at_ts(VALUE_PARAMETER_FIRST) { 66 if !p.at_ts(VALUE_PARAMETER_FIRST) {
@@ -71,11 +72,7 @@ fn list_(p: &mut Parser, flavor: Flavor) {
71 p.expect(T![,]); 72 p.expect(T![,]);
72 } 73 }
73 } 74 }
74 // test param_list_vararg 75
75 // extern "C" { fn printf(format: *const i8, ...) -> i32; }
76 if let Function | FnPointer = flavor {
77 p.eat(T![...]);
78 }
79 p.expect(ket); 76 p.expect(ket);
80 m.complete(p, PARAM_LIST); 77 m.complete(p, PARAM_LIST);
81} 78}
@@ -105,13 +102,13 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) {
105 // fn f3(NewType(a): NewType) {} 102 // fn f3(NewType(a): NewType) {}
106 // fn f4(&&a: &&usize) {} 103 // fn f4(&&a: &&usize) {}
107 // } 104 // }
108 Flavor::Function => { 105 Flavor::FnDef => {
109 patterns::pattern(p); 106 patterns::pattern(p);
110 types::ascription(p); 107 types::ascription(p);
111 } 108 }
112 // test value_parameters_no_patterns 109 // test value_parameters_no_patterns
113 // type F = Box<Fn(i32, &i32, &i32, ())>; 110 // type F = Box<Fn(i32, &i32, &i32, ())>;
114 Flavor::ImplFn => { 111 Flavor::FnTrait => {
115 types::type_(p); 112 types::type_(p);
116 } 113 }
117 // test fn_pointer_param_ident_path 114 // test fn_pointer_param_ident_path