1 //! FIXME: write short doc here
9 // fn d(x: i32, y: ()) {}
10 pub(super) fn param_list_fn_def(p: &mut Parser) {
11 list_(p, Flavor::FnDef)
14 // test param_list_opt_patterns
15 // fn foo<F: FnMut(&mut Foo<'a>)>(){}
16 pub(super) fn param_list_fn_trait(p: &mut Parser) {
17 list_(p, Flavor::FnTrait)
20 pub(super) fn param_list_fn_ptr(p: &mut Parser) {
21 list_(p, Flavor::FnPointer)
24 pub(super) fn param_list_closure(p: &mut Parser) {
25 list_(p, Flavor::Closure)
28 #[derive(Debug, Clone, Copy)]
30 FnDef, // Includes trait fn params; omitted param idents are not supported
31 FnTrait, // Params for `Fn(...)`/`FnMut(...)`/`FnOnce(...)` annotations
36 fn list_(p: &mut Parser, flavor: Flavor) {
39 let (bra, ket) = match flavor {
40 Closure => (T![|], T![|]),
41 FnDef | FnTrait | FnPointer => (T!['('], T![')']),
47 if let FnDef = flavor {
48 // test self_param_outer_attr
49 // fn f(#[must_use] self) {}
50 attributes::outer_attrs(p);
54 while !p.at(EOF) && !p.at(ket) {
55 // test param_outer_arg
56 // fn f(#[attr1] pat: Type) {}
57 attributes::outer_attrs(p);
59 if !p.at_ts(PARAM_FIRST) {
60 p.error("expected value parameter");
63 let param = param(p, flavor);
67 if let Variadic(true) = param {
73 m.complete(p, PARAM_LIST);
76 const PARAM_FIRST: TokenSet = patterns::PATTERN_FIRST.union(types::TYPE_FIRST);
78 struct Variadic(bool);
80 fn param(p: &mut Parser, flavor: Flavor) -> Variadic {
81 let mut res = Variadic(false);
84 // test param_list_vararg
85 // extern "C" { fn printf(format: *const i8, ...) -> i32; }
86 Flavor::FnDef | Flavor::FnPointer if p.eat(T![...]) => res = Variadic(true),
89 // fn foo((x, y): (i32, i32)) {}
92 if variadic_param(p) {
98 // test value_parameters_no_patterns
99 // type F = Box<Fn(i32, &i32, &i32, ())>;
103 // test fn_pointer_param_ident_path
104 // type Foo = fn(Bar::Baz);
105 // type Qux = fn(baz: Bar::Baz);
107 // test fn_pointer_unnamed_arg
108 // type Foo = fn(_: bar);
109 Flavor::FnPointer => {
110 if (p.at(IDENT) || p.at(UNDERSCORE)) && p.nth(1) == T![:] && !p.nth_at(1, T![::]) {
111 patterns::pattern_single(p);
112 if variadic_param(p) {
115 types::ascription(p);
121 // test closure_params
123 // let foo = |bar, baz: Baz, qux: Qux::Quux| ();
126 patterns::pattern_single(p);
127 if p.at(T![:]) && !p.at(T![::]) {
128 types::ascription(p);
132 m.complete(p, PARAM);
136 fn variadic_param(p: &mut Parser) -> bool {
137 if p.at(T![:]) && p.nth_at(1, T![...]) {
150 // fn c(&'a self,) {}
151 // fn d(&'a mut self, x: i32) {}
154 fn opt_self_param(p: &mut Parser) {
156 if p.at(T![self]) || p.at(T![mut]) && p.nth(1) == T![self] {
160 // test arb_self_types
162 // fn a(self: &Self) {}
163 // fn b(mut self: Box<Self>) {}
166 types::ascription(p);
172 let n_toks = match (p.current(), la1, la2, la3) {
173 (T![&], T![self], _, _) => 2,
174 (T![&], T![mut], T![self], _) => 3,
175 (T![&], LIFETIME, T![self], _) => 3,
176 (T![&], LIFETIME, T![mut], T![self]) => 4,
184 m.complete(p, SELF_PARAM);