From 7e66785859fc4a31fc3faf4848174699d3a2c020 Mon Sep 17 00:00:00 2001 From: Toby Dimmick Date: Thu, 6 Feb 2020 11:44:00 +0000 Subject: Rework value parameter parsing - `Fn__(...)` parameters with idents/patterns no longer parse - Trait function parameters with arbitrary patterns parse - Trait function parameters without idents/patterns no longer parse - `fn(...)` parameters no longer parse with patterns other than a single ident --- crates/ra_parser/src/grammar/items.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'crates/ra_parser/src/grammar/items.rs') diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 6e23d9b72..b20d224e8 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -164,7 +164,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul // async unsafe fn foo() {} // unsafe const fn bar() {} T![fn] => { - fn_def(p, flavor); + fn_def(p); m.complete(p, FN_DEF); } @@ -301,7 +301,7 @@ pub(crate) fn extern_item_list(p: &mut Parser) { m.complete(p, EXTERN_ITEM_LIST); } -fn fn_def(p: &mut Parser, flavor: ItemFlavor) { +fn fn_def(p: &mut Parser) { assert!(p.at(T![fn])); p.bump(T![fn]); @@ -311,10 +311,7 @@ fn fn_def(p: &mut Parser, flavor: ItemFlavor) { type_params::opt_type_param_list(p); if p.at(T!['(']) { - match flavor { - ItemFlavor::Mod => params::param_list(p), - ItemFlavor::Trait => params::param_list_opt_patterns(p), - } + params::param_list_fn(p); } else { p.error("expected function arguments"); } -- cgit v1.2.3 From 90ff2be4e820601a1d16ba5716916f7424dfa10d Mon Sep 17 00:00:00 2001 From: Toby Dimmick Date: Fri, 7 Feb 2020 12:36:33 +0000 Subject: PR tweaks --- crates/ra_parser/src/grammar/items.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_parser/src/grammar/items.rs') diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index b20d224e8..7263c4d69 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -311,7 +311,7 @@ fn fn_def(p: &mut Parser) { type_params::opt_type_param_list(p); if p.at(T!['(']) { - params::param_list_fn(p); + params::param_list_fn_def(p); } else { p.error("expected function arguments"); } -- cgit v1.2.3 From 73ec2ab184f6d8828ebcdca418a7ae83bb60b0bc Mon Sep 17 00:00:00 2001 From: Emil Lauridsen Date: Fri, 7 Feb 2020 13:51:51 +0100 Subject: Update async unsafe fn ordering. As of rust-lang/rust#61319 the correct order for functions that are both unsafe and async is: `async unsafe fn` and not `unsafe async fn`. This commit updates the parser tests to reflect this, and corrects parsing behavior to accept the correct ordering. Fixes #3025 --- crates/ra_parser/src/grammar/items.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'crates/ra_parser/src/grammar/items.rs') diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 6e23d9b72..a88206fa8 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -91,13 +91,6 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul // modifiers has_mods |= p.eat(T![const]); - // test_err unsafe_block_in_mod - // fn foo(){} unsafe { } fn bar(){} - if p.at(T![unsafe]) && p.nth(1) != T!['{'] { - p.eat(T![unsafe]); - has_mods = true; - } - // test_err async_without_semicolon // fn foo() { let _ = async {} } if p.at(T![async]) && p.nth(1) != T!['{'] && p.nth(1) != T![move] && p.nth(1) != T![|] { @@ -105,6 +98,13 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul has_mods = true; } + // test_err unsafe_block_in_mod + // fn foo(){} unsafe { } fn bar(){} + if p.at(T![unsafe]) && p.nth(1) != T!['{'] { + p.eat(T![unsafe]); + has_mods = true; + } + if p.at(T![extern]) { has_mods = true; abi(p); @@ -157,11 +157,11 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul // unsafe fn foo() {} // test combined_fns - // unsafe async fn foo() {} + // async unsafe fn foo() {} // const unsafe fn bar() {} // test_err wrong_order_fns - // async unsafe fn foo() {} + // unsafe async fn foo() {} // unsafe const fn bar() {} T![fn] => { fn_def(p, flavor); -- cgit v1.2.3