Skip to content

Commit 90ff2be

Browse files
committed
PR tweaks
1 parent 0183952 commit 90ff2be

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

crates/ra_parser/src/grammar/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ fn fn_def(p: &mut Parser) {
311311
type_params::opt_type_param_list(p);
312312

313313
if p.at(T!['(']) {
314-
params::param_list_fn(p);
314+
params::param_list_fn_def(p);
315315
} else {
316316
p.error("expected function arguments");
317317
}

crates/ra_parser/src/grammar/params.rs

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use super::*;
77
// fn b(x: i32) {}
88
// fn c(x: i32, ) {}
99
// fn d(x: i32, y: ()) {}
10-
pub(super) fn param_list_fn(p: &mut Parser) {
11-
list_(p, Flavor::Function)
10+
pub(super) fn param_list_fn_def(p: &mut Parser) {
11+
list_(p, Flavor::FnDef)
1212
}
1313

1414
// test param_list_opt_patterns
1515
// fn foo<F: FnMut(&mut Foo<'a>)>(){}
16-
pub(super) fn param_list_impl_fn(p: &mut Parser) {
17-
list_(p, Flavor::ImplFn)
16+
pub(super) fn param_list_fn_trait(p: &mut Parser) {
17+
list_(p, Flavor::FnTrait)
1818
}
1919

2020
pub(super) fn param_list_fn_ptr(p: &mut Parser) {
@@ -27,8 +27,8 @@ pub(super) fn param_list_closure(p: &mut Parser) {
2727

2828
#[derive(Debug, Clone, Copy)]
2929
enum Flavor {
30-
Function, // Includes trait fn params; omitted param idents are not supported
31-
ImplFn,
30+
FnDef, // Includes trait fn params; omitted param idents are not supported
31+
FnTrait, // Params for `Fn(...)`/`FnMut(...)`/`FnOnce(...)` annotations
3232
FnPointer,
3333
Closure,
3434
}
@@ -38,13 +38,13 @@ fn list_(p: &mut Parser, flavor: Flavor) {
3838

3939
let (bra, ket) = match flavor {
4040
Closure => (T![|], T![|]),
41-
Function | ImplFn | FnPointer => (T!['('], T![')']),
41+
FnDef | FnTrait | FnPointer => (T!['('], T![')']),
4242
};
4343

4444
let m = p.start();
4545
p.bump(bra);
4646

47-
if let Function = flavor {
47+
if let FnDef = flavor {
4848
// test self_param_outer_attr
4949
// fn f(#[must_use] self) {}
5050
attributes::outer_attributes(p);
@@ -56,10 +56,11 @@ fn list_(p: &mut Parser, flavor: Flavor) {
5656
// fn f(#[attr1] pat: Type) {}
5757
attributes::outer_attributes(p);
5858

59-
if let Function | FnPointer = flavor {
60-
if p.at(T![...]) {
61-
break;
62-
}
59+
// test param_list_vararg
60+
// extern "C" { fn printf(format: *const i8, ...) -> i32; }
61+
match flavor {
62+
FnDef | FnPointer if p.eat(T![...]) => break,
63+
_ => (),
6364
}
6465

6566
if !p.at_ts(VALUE_PARAMETER_FIRST) {
@@ -71,11 +72,7 @@ fn list_(p: &mut Parser, flavor: Flavor) {
7172
p.expect(T![,]);
7273
}
7374
}
74-
// test param_list_vararg
75-
// extern "C" { fn printf(format: *const i8, ...) -> i32; }
76-
if let Function | FnPointer = flavor {
77-
p.eat(T![...]);
78-
}
75+
7976
p.expect(ket);
8077
m.complete(p, PARAM_LIST);
8178
}
@@ -105,13 +102,13 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) {
105102
// fn f3(NewType(a): NewType) {}
106103
// fn f4(&&a: &&usize) {}
107104
// }
108-
Flavor::Function => {
105+
Flavor::FnDef => {
109106
patterns::pattern(p);
110107
types::ascription(p);
111108
}
112109
// test value_parameters_no_patterns
113110
// type F = Box<Fn(i32, &i32, &i32, ())>;
114-
Flavor::ImplFn => {
111+
Flavor::FnTrait => {
115112
types::type_(p);
116113
}
117114
// test fn_pointer_param_ident_path

crates/ra_parser/src/grammar/paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ fn opt_path_type_args(p: &mut Parser, mode: Mode) {
9999
// test path_fn_trait_args
100100
// type F = Box<Fn(i32) -> ()>;
101101
if p.at(T!['(']) {
102-
params::param_list_impl_fn(p);
102+
params::param_list_fn_trait(p);
103103
opt_fn_ret_type(p);
104104
} else {
105105
type_args::opt_type_arg_list(p, false)

0 commit comments

Comments
 (0)