aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-04-03 16:33:58 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-04-03 16:33:58 +0100
commit84d8665e13007b0ee27e2a42ff74db815923cdce (patch)
treef60577c56dc805a54683359ecc6f2e08575fd65e /crates/ra_parser/src
parentf1ac9c8f558832f260bdd8b998fb1d7fbbcb6db5 (diff)
parent636270f4a4f80f5d24571147bcadfbeaa29310a0 (diff)
Merge #1101
1101: Parse unsafe async / const unsafe fns properly r=matklad a=robojumper Also adds tests that `unsafe async fn` as well as `const unsafe fn` parse properly and that these keywords in the reversed order cause parse errors. [Playground link to verify that this is the correct order.](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=7850b8d92579de31c38f835f76afa4ce) Closes #1086. Co-authored-by: robojumper <[email protected]>
Diffstat (limited to 'crates/ra_parser/src')
-rw-r--r--crates/ra_parser/src/grammar/items.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs
index c4b8ef3c7..318fd69a1 100644
--- a/crates/ra_parser/src/grammar/items.rs
+++ b/crates/ra_parser/src/grammar/items.rs
@@ -79,19 +79,22 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
79 let mut has_mods = false; 79 let mut has_mods = false;
80 80
81 // modifiers 81 // modifiers
82 // test_err async_without_semicolon
83 // fn foo() { let _ = async {} }
84 has_mods |= p.eat(CONST_KW); 82 has_mods |= p.eat(CONST_KW);
85 if p.at(ASYNC_KW) && p.nth(1) != L_CURLY && p.nth(1) != MOVE_KW && p.nth(1) != PIPE { 83
86 p.eat(ASYNC_KW);
87 has_mods = true;
88 }
89 // test_err unsafe_block_in_mod 84 // test_err unsafe_block_in_mod
90 // fn foo(){} unsafe { } fn bar(){} 85 // fn foo(){} unsafe { } fn bar(){}
91 if p.at(UNSAFE_KW) && p.nth(1) != L_CURLY { 86 if p.at(UNSAFE_KW) && p.nth(1) != L_CURLY {
92 p.eat(UNSAFE_KW); 87 p.eat(UNSAFE_KW);
93 has_mods = true; 88 has_mods = true;
94 } 89 }
90
91 // test_err async_without_semicolon
92 // fn foo() { let _ = async {} }
93 if p.at(ASYNC_KW) && p.nth(1) != L_CURLY && p.nth(1) != MOVE_KW && p.nth(1) != PIPE {
94 p.eat(ASYNC_KW);
95 has_mods = true;
96 }
97
95 if p.at(EXTERN_KW) { 98 if p.at(EXTERN_KW) {
96 has_mods = true; 99 has_mods = true;
97 abi(p); 100 abi(p);
@@ -124,6 +127,14 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
124 127
125 // test unsafe_fn 128 // test unsafe_fn
126 // unsafe fn foo() {} 129 // unsafe fn foo() {}
130
131 // test combined_fns
132 // unsafe async fn foo() {}
133 // const unsafe fn bar() {}
134
135 // test_err wrong_order_fns
136 // async unsafe fn foo() {}
137 // unsafe const fn bar() {}
127 FN_KW => { 138 FN_KW => {
128 fn_def(p, flavor); 139 fn_def(p, flavor);
129 m.complete(p, FN_DEF); 140 m.complete(p, FN_DEF);