From 0e10e77a7820d08332744d91e44940a2321138c3 Mon Sep 17 00:00:00 2001 From: Han Mertens Date: Wed, 12 Feb 2020 21:40:05 +0100 Subject: [PATCH 1/4] Support unnamed arguments in function pointers Fixes #3089 --- crates/ra_parser/src/grammar/params.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ra_parser/src/grammar/params.rs b/crates/ra_parser/src/grammar/params.rs index ed4f93347a..4abd61be73 100644 --- a/crates/ra_parser/src/grammar/params.rs +++ b/crates/ra_parser/src/grammar/params.rs @@ -115,7 +115,7 @@ fn value_parameter(p: &mut Parser, flavor: Flavor) { // type Foo = fn(Bar::Baz); // type Qux = fn(baz: Bar::Baz); 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 { From b435fe8b771c00d5df1f781b21ddae55d64ded42 Mon Sep 17 00:00:00 2001 From: Han Mertens Date: Wed, 12 Feb 2020 22:55:37 +0100 Subject: [PATCH 2/4] Add test for unnamed argument in function pointer --- crates/ra_parser/src/grammar/params.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/ra_parser/src/grammar/params.rs b/crates/ra_parser/src/grammar/params.rs index 4abd61be73..272661b1da 100644 --- a/crates/ra_parser/src/grammar/params.rs +++ b/crates/ra_parser/src/grammar/params.rs @@ -114,6 +114,9 @@ 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.at(UNDERSCORE)) && p.nth(1) == T![:] && !p.nth_at(1, T![::]) { patterns::pattern_single(p); From 537da096fefb35a2b91670eb8a1ffe16e4330962 Mon Sep 17 00:00:00 2001 From: Han Mertens Date: Wed, 12 Feb 2020 23:09:13 +0100 Subject: [PATCH 3/4] Run cargo xtask codegen --- .../test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.rs | 1 + 1 file changed, 1 insertion(+) create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.rs 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 0000000000..1ebbe5b035 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.rs @@ -0,0 +1 @@ +type Foo = fn(_: bar); From bed9c083de54283779a889fed4accc55f84483dc Mon Sep 17 00:00:00 2001 From: Han Mertens Date: Wed, 12 Feb 2020 23:15:48 +0100 Subject: [PATCH 4/4] Run cargo test --- .../inline/ok/0157_fn_pointer_unnamed_arg.txt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0157_fn_pointer_unnamed_arg.txt 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 0000000000..52d8f21a47 --- /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"