diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-12 22:26:35 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-12 22:26:35 +0000 |
| commit | 5e464d058b5043c663b0fe14bd9291c7b7b44d43 (patch) | |
| tree | 6ba56780c62ab3ab6544499831f73e203263bbfb | |
| parent | 3da53ab3e75b0486c1b2e4f74babea10992c4747 (diff) | |
| parent | bed9c083de54283779a889fed4accc55f84483dc (diff) | |
| download | rust-5e464d058b5043c663b0fe14bd9291c7b7b44d43.tar.gz rust-5e464d058b5043c663b0fe14bd9291c7b7b44d43.zip | |
Merge #3127
3127: Support unnamed arguments in function pointers r=edwin0cheng a=hanmertens Fixes #3089 Co-authored-by: Han Mertens <hanmertens@outlook.com>
3 files changed, 31 insertions, 1 deletions
diff --git a/crates/ra_parser/src/grammar/params.rs b/crates/ra_parser/src/grammar/params.rs index ed4f93347a2..272661b1da4 100644 --- a/crates/ra_parser/src/grammar/params.rs +++ b/crates/ra_parser/src/grammar/params.rs @@ -114,8 +114,11 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) { // test fn_pointer_param_ident_path // type Foo = fn(Bar::Baz); // type Qux = fn(baz: Bar::Baz); + + // test fn_pointer_unnamed_arg + // type Foo = fn(_: bar); Flavor::FnPointer => { - if p.at(IDENT) && p.nth(1) == T![:] && !p.nth_at(1, T![::]) { + if (p.at(IDENT) || p.at(UNDERSCORE)) && p.nth(1) == T![:] && !p.nth_at(1, T![::]) { patterns::pattern_single(p); types::ascription(p); } else { diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.rs b/crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.rs new file mode 100644 index 00000000000..1ebbe5b0355 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.rs @@ -0,0 +1 @@ +type Foo = fn(_: bar); diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.txt b/crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.txt new file mode 100644 index 00000000000..52d8f21a471 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.txt @@ -0,0 +1,26 @@ +SOURCE_FILE@[0; 23) + TYPE_ALIAS_DEF@[0; 22) + TYPE_KW@[0; 4) "type" + WHITESPACE@[4; 5) " " + NAME@[5; 8) + IDENT@[5; 8) "Foo" + WHITESPACE@[8; 9) " " + EQ@[9; 10) "=" + WHITESPACE@[10; 11) " " + FN_POINTER_TYPE@[11; 21) + FN_KW@[11; 13) "fn" + PARAM_LIST@[13; 21) + L_PAREN@[13; 14) "(" + PARAM@[14; 20) + PLACEHOLDER_PAT@[14; 15) + UNDERSCORE@[14; 15) "_" + COLON@[15; 16) ":" + WHITESPACE@[16; 17) " " + PATH_TYPE@[17; 20) + PATH@[17; 20) + PATH_SEGMENT@[17; 20) + NAME_REF@[17; 20) + IDENT@[17; 20) "bar" + R_PAREN@[20; 21) ")" + SEMI@[21; 22) ";" + WHITESPACE@[22; 23) "\n" |
