PR tweaks
This commit is contained in:
parent
0183952d2e
commit
90ff2be4e8
3 changed files with 18 additions and 21 deletions
|
@ -311,7 +311,7 @@ fn fn_def(p: &mut Parser) {
|
||||||
type_params::opt_type_param_list(p);
|
type_params::opt_type_param_list(p);
|
||||||
|
|
||||||
if p.at(T!['(']) {
|
if p.at(T!['(']) {
|
||||||
params::param_list_fn(p);
|
params::param_list_fn_def(p);
|
||||||
} else {
|
} else {
|
||||||
p.error("expected function arguments");
|
p.error("expected function arguments");
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,14 @@ use super::*;
|
||||||
// fn b(x: i32) {}
|
// fn b(x: i32) {}
|
||||||
// fn c(x: i32, ) {}
|
// fn c(x: i32, ) {}
|
||||||
// fn d(x: i32, y: ()) {}
|
// fn d(x: i32, y: ()) {}
|
||||||
pub(super) fn param_list_fn(p: &mut Parser) {
|
pub(super) fn param_list_fn_def(p: &mut Parser) {
|
||||||
list_(p, Flavor::Function)
|
list_(p, Flavor::FnDef)
|
||||||
}
|
}
|
||||||
|
|
||||||
// test param_list_opt_patterns
|
// test param_list_opt_patterns
|
||||||
// fn foo<F: FnMut(&mut Foo<'a>)>(){}
|
// fn foo<F: FnMut(&mut Foo<'a>)>(){}
|
||||||
pub(super) fn param_list_impl_fn(p: &mut Parser) {
|
pub(super) fn param_list_fn_trait(p: &mut Parser) {
|
||||||
list_(p, Flavor::ImplFn)
|
list_(p, Flavor::FnTrait)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn param_list_fn_ptr(p: &mut Parser) {
|
pub(super) fn param_list_fn_ptr(p: &mut Parser) {
|
||||||
|
@ -27,8 +27,8 @@ pub(super) fn param_list_closure(p: &mut Parser) {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
enum Flavor {
|
enum Flavor {
|
||||||
Function, // Includes trait fn params; omitted param idents are not supported
|
FnDef, // Includes trait fn params; omitted param idents are not supported
|
||||||
ImplFn,
|
FnTrait, // Params for `Fn(...)`/`FnMut(...)`/`FnOnce(...)` annotations
|
||||||
FnPointer,
|
FnPointer,
|
||||||
Closure,
|
Closure,
|
||||||
}
|
}
|
||||||
|
@ -38,13 +38,13 @@ fn list_(p: &mut Parser, flavor: Flavor) {
|
||||||
|
|
||||||
let (bra, ket) = match flavor {
|
let (bra, ket) = match flavor {
|
||||||
Closure => (T![|], T![|]),
|
Closure => (T![|], T![|]),
|
||||||
Function | ImplFn | FnPointer => (T!['('], T![')']),
|
FnDef | FnTrait | FnPointer => (T!['('], T![')']),
|
||||||
};
|
};
|
||||||
|
|
||||||
let m = p.start();
|
let m = p.start();
|
||||||
p.bump(bra);
|
p.bump(bra);
|
||||||
|
|
||||||
if let Function = flavor {
|
if let FnDef = flavor {
|
||||||
// test self_param_outer_attr
|
// test self_param_outer_attr
|
||||||
// fn f(#[must_use] self) {}
|
// fn f(#[must_use] self) {}
|
||||||
attributes::outer_attributes(p);
|
attributes::outer_attributes(p);
|
||||||
|
@ -56,10 +56,11 @@ fn list_(p: &mut Parser, flavor: Flavor) {
|
||||||
// fn f(#[attr1] pat: Type) {}
|
// fn f(#[attr1] pat: Type) {}
|
||||||
attributes::outer_attributes(p);
|
attributes::outer_attributes(p);
|
||||||
|
|
||||||
if let Function | FnPointer = flavor {
|
// test param_list_vararg
|
||||||
if p.at(T![...]) {
|
// extern "C" { fn printf(format: *const i8, ...) -> i32; }
|
||||||
break;
|
match flavor {
|
||||||
}
|
FnDef | FnPointer if p.eat(T![...]) => break,
|
||||||
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
if !p.at_ts(VALUE_PARAMETER_FIRST) {
|
if !p.at_ts(VALUE_PARAMETER_FIRST) {
|
||||||
|
@ -71,11 +72,7 @@ fn list_(p: &mut Parser, flavor: Flavor) {
|
||||||
p.expect(T![,]);
|
p.expect(T![,]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// test param_list_vararg
|
|
||||||
// extern "C" { fn printf(format: *const i8, ...) -> i32; }
|
|
||||||
if let Function | FnPointer = flavor {
|
|
||||||
p.eat(T![...]);
|
|
||||||
}
|
|
||||||
p.expect(ket);
|
p.expect(ket);
|
||||||
m.complete(p, PARAM_LIST);
|
m.complete(p, PARAM_LIST);
|
||||||
}
|
}
|
||||||
|
@ -105,13 +102,13 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) {
|
||||||
// fn f3(NewType(a): NewType) {}
|
// fn f3(NewType(a): NewType) {}
|
||||||
// fn f4(&&a: &&usize) {}
|
// fn f4(&&a: &&usize) {}
|
||||||
// }
|
// }
|
||||||
Flavor::Function => {
|
Flavor::FnDef => {
|
||||||
patterns::pattern(p);
|
patterns::pattern(p);
|
||||||
types::ascription(p);
|
types::ascription(p);
|
||||||
}
|
}
|
||||||
// test value_parameters_no_patterns
|
// test value_parameters_no_patterns
|
||||||
// type F = Box<Fn(i32, &i32, &i32, ())>;
|
// type F = Box<Fn(i32, &i32, &i32, ())>;
|
||||||
Flavor::ImplFn => {
|
Flavor::FnTrait => {
|
||||||
types::type_(p);
|
types::type_(p);
|
||||||
}
|
}
|
||||||
// test fn_pointer_param_ident_path
|
// test fn_pointer_param_ident_path
|
||||||
|
|
|
@ -99,7 +99,7 @@ fn opt_path_type_args(p: &mut Parser, mode: Mode) {
|
||||||
// test path_fn_trait_args
|
// test path_fn_trait_args
|
||||||
// type F = Box<Fn(i32) -> ()>;
|
// type F = Box<Fn(i32) -> ()>;
|
||||||
if p.at(T!['(']) {
|
if p.at(T!['(']) {
|
||||||
params::param_list_impl_fn(p);
|
params::param_list_fn_trait(p);
|
||||||
opt_fn_ret_type(p);
|
opt_fn_ret_type(p);
|
||||||
} else {
|
} else {
|
||||||
type_args::opt_type_arg_list(p, false)
|
type_args::opt_type_arg_list(p, false)
|
||||||
|
|
Loading…
Add table
Reference in a new issue