Skip to content

Commit 8337dcd

Browse files
bors[bot]kiljacken
andauthored
Merge #3047
3047: Update async unsafe fn ordering in parser r=matklad a=kiljacken 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 Co-authored-by: Emil Lauridsen <[email protected]>
2 parents 6d6a995 + 73ec2ab commit 8337dcd

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

crates/ra_parser/src/grammar/items.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,20 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
9191
// modifiers
9292
has_mods |= p.eat(T![const]);
9393

94-
// test_err unsafe_block_in_mod
95-
// fn foo(){} unsafe { } fn bar(){}
96-
if p.at(T![unsafe]) && p.nth(1) != T!['{'] {
97-
p.eat(T![unsafe]);
98-
has_mods = true;
99-
}
100-
10194
// test_err async_without_semicolon
10295
// fn foo() { let _ = async {} }
10396
if p.at(T![async]) && p.nth(1) != T!['{'] && p.nth(1) != T![move] && p.nth(1) != T![|] {
10497
p.eat(T![async]);
10598
has_mods = true;
10699
}
107100

101+
// test_err unsafe_block_in_mod
102+
// fn foo(){} unsafe { } fn bar(){}
103+
if p.at(T![unsafe]) && p.nth(1) != T!['{'] {
104+
p.eat(T![unsafe]);
105+
has_mods = true;
106+
}
107+
108108
if p.at(T![extern]) {
109109
has_mods = true;
110110
abi(p);
@@ -157,11 +157,11 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
157157
// unsafe fn foo() {}
158158

159159
// test combined_fns
160-
// unsafe async fn foo() {}
160+
// async unsafe fn foo() {}
161161
// const unsafe fn bar() {}
162162

163163
// test_err wrong_order_fns
164-
// async unsafe fn foo() {}
164+
// unsafe async fn foo() {}
165165
// unsafe const fn bar() {}
166166
T![fn] => {
167167
fn_def(p);
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
async unsafe fn foo() {}
1+
unsafe async fn foo() {}
22
unsafe const fn bar() {}

crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
SOURCE_FILE@[0; 50)
2-
ERROR@[0; 5)
3-
ASYNC_KW@[0; 5) "async"
4-
WHITESPACE@[5; 6) " "
5-
FN_DEF@[6; 24)
6-
UNSAFE_KW@[6; 12) "unsafe"
2+
ERROR@[0; 6)
3+
UNSAFE_KW@[0; 6) "unsafe"
4+
WHITESPACE@[6; 7) " "
5+
FN_DEF@[7; 24)
6+
ASYNC_KW@[7; 12) "async"
77
WHITESPACE@[12; 13) " "
88
FN_KW@[13; 15) "fn"
99
WHITESPACE@[15; 16) " "
@@ -37,5 +37,5 @@ SOURCE_FILE@[0; 50)
3737
L_CURLY@[47; 48) "{"
3838
R_CURLY@[48; 49) "}"
3939
WHITESPACE@[49; 50) "\n"
40-
error 5: expected existential, fn, trait or impl
40+
error 6: expected existential, fn, trait or impl
4141
error 31: expected existential, fn, trait or impl
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
unsafe async fn foo() {}
1+
async unsafe fn foo() {}
22
const unsafe fn bar() {}

crates/ra_syntax/test_data/parser/inline/ok/0128_combined_fns.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
SOURCE_FILE@[0; 50)
22
FN_DEF@[0; 24)
3-
UNSAFE_KW@[0; 6) "unsafe"
4-
WHITESPACE@[6; 7) " "
5-
ASYNC_KW@[7; 12) "async"
3+
ASYNC_KW@[0; 5) "async"
4+
WHITESPACE@[5; 6) " "
5+
UNSAFE_KW@[6; 12) "unsafe"
66
WHITESPACE@[12; 13) " "
77
FN_KW@[13; 15) "fn"
88
WHITESPACE@[15; 16) " "

0 commit comments

Comments
 (0)