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 +++++++++--------- .../parser/inline/err/0010_wrong_order_fns.rs | 2 +- .../parser/inline/err/0010_wrong_order_fns.txt | 12 ++++++------ .../test_data/parser/inline/ok/0128_combined_fns.rs | 2 +- .../test_data/parser/inline/ok/0128_combined_fns.txt | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-) (limited to 'crates') 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); diff --git a/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rs b/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rs index 16edee95d..731e58013 100644 --- a/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rs +++ b/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rs @@ -1,2 +1,2 @@ -async unsafe fn foo() {} +unsafe async fn foo() {} unsafe const fn bar() {} diff --git a/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.txt b/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.txt index 2ea6a566d..289193b9e 100644 --- a/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.txt +++ b/crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.txt @@ -1,9 +1,9 @@ SOURCE_FILE@[0; 50) - ERROR@[0; 5) - ASYNC_KW@[0; 5) "async" - WHITESPACE@[5; 6) " " - FN_DEF@[6; 24) - UNSAFE_KW@[6; 12) "unsafe" + ERROR@[0; 6) + UNSAFE_KW@[0; 6) "unsafe" + WHITESPACE@[6; 7) " " + FN_DEF@[7; 24) + ASYNC_KW@[7; 12) "async" WHITESPACE@[12; 13) " " FN_KW@[13; 15) "fn" WHITESPACE@[15; 16) " " @@ -37,5 +37,5 @@ SOURCE_FILE@[0; 50) L_CURLY@[47; 48) "{" R_CURLY@[48; 49) "}" WHITESPACE@[49; 50) "\n" -error 5: expected existential, fn, trait or impl +error 6: expected existential, fn, trait or impl error 31: expected existential, fn, trait or impl diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rs b/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rs index 46af91b82..126287145 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rs +++ b/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.rs @@ -1,2 +1,2 @@ -unsafe async fn foo() {} +async unsafe fn foo() {} const unsafe fn bar() {} diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.txt b/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.txt index cae75c41d..8a972cdb2 100644 --- a/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.txt +++ b/crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.txt @@ -1,8 +1,8 @@ SOURCE_FILE@[0; 50) FN_DEF@[0; 24) - UNSAFE_KW@[0; 6) "unsafe" - WHITESPACE@[6; 7) " " - ASYNC_KW@[7; 12) "async" + ASYNC_KW@[0; 5) "async" + WHITESPACE@[5; 6) " " + UNSAFE_KW@[6; 12) "unsafe" WHITESPACE@[12; 13) " " FN_KW@[13; 15) "fn" WHITESPACE@[15; 16) " " -- cgit v1.2.3