aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-16 14:16:47 +0000
committerGitHub <[email protected]>2021-02-16 14:16:47 +0000
commitb7a6d830beaa2669f6ddff3167eb94b941e73339 (patch)
tree623696cb6b985de75ddcf3809feba421a19128c6
parent88e8b0a5fa17075475c75941932056f7289c5bcf (diff)
parent95d239da99cb1b7ba60f5f20f6df54e1397a1bca (diff)
Merge #7687
7687: Specialization for async traits r=matklad a=arnaudgolfouse Fixes #7669. Adapting the parser seemed to be all that was needed, but I am not very experienced with the codebase. Is this enough ? Co-authored-by: Arnaud <[email protected]>
-rw-r--r--crates/parser/src/grammar/items.rs28
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0162_default_async_unsafe_fn.rast42
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0162_default_async_unsafe_fn.rs3
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0163_default_async_fn.rast40
-rw-r--r--crates/syntax/test_data/parser/inline/ok/0163_default_async_fn.rs3
5 files changed, 116 insertions, 0 deletions
diff --git a/crates/parser/src/grammar/items.rs b/crates/parser/src/grammar/items.rs
index 1d894e907..adec74ef3 100644
--- a/crates/parser/src/grammar/items.rs
+++ b/crates/parser/src/grammar/items.rs
@@ -83,6 +83,7 @@ pub(super) fn item_or_macro(p: &mut Parser, stop_on_r_curly: bool) {
83 } 83 }
84} 84}
85 85
86/// Try to parse an item, completing `m` in case of success.
86pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { 87pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
87 // test_err pub_expr 88 // test_err pub_expr
88 // fn foo() { pub 92; } 89 // fn foo() { pub 92; }
@@ -143,6 +144,33 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
143 has_mods = true; 144 has_mods = true;
144 } 145 }
145 } 146 }
147 T![async] => {
148 // test default_async_fn
149 // impl T for Foo {
150 // default async fn foo() {}
151 // }
152
153 // test default_async_unsafe_fn
154 // impl T for Foo {
155 // default async unsafe fn foo() {}
156 // }
157 let mut maybe_fn = p.nth(2);
158 let is_unsafe = if matches!(maybe_fn, T![unsafe]) {
159 maybe_fn = p.nth(3);
160 true
161 } else {
162 false
163 };
164
165 if matches!(maybe_fn, T![fn]) {
166 p.bump_remap(T![default]);
167 p.bump(T![async]);
168 if is_unsafe {
169 p.bump(T![unsafe])
170 }
171 has_mods = true;
172 }
173 }
146 _ => (), 174 _ => (),
147 } 175 }
148 } 176 }
diff --git a/crates/syntax/test_data/parser/inline/ok/0162_default_async_unsafe_fn.rast b/crates/syntax/test_data/parser/inline/ok/0162_default_async_unsafe_fn.rast
new file mode 100644
index 000000000..61c17333a
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0162_default_async_unsafe_fn.rast
@@ -0,0 +1,42 @@
1[email protected]
2 [email protected]
3 [email protected] "impl"
4 [email protected] " "
5 [email protected]
6 [email protected]
7 [email protected]
8 [email protected]
9 [email protected] "T"
10 [email protected] " "
11 [email protected] "for"
12 [email protected] " "
13 [email protected]
14 [email protected]
15 [email protected]
16 [email protected]
17 [email protected] "Foo"
18 [email protected] " "
19 [email protected]
20 [email protected] "{"
21 [email protected] "\n "
22 [email protected]
23 [email protected] "default"
24 [email protected] " "
25 [email protected] "async"
26 [email protected] " "
27 [email protected] "unsafe"
28 [email protected] " "
29 [email protected] "fn"
30 [email protected] " "
31 [email protected]
32 [email protected] "foo"
33 [email protected]
34 [email protected] "("
35 [email protected] ")"
36 [email protected] " "
37 [email protected]
38 [email protected] "{"
39 [email protected] "}"
40 [email protected] "\n"
41 [email protected] "}"
42 [email protected] "\n"
diff --git a/crates/syntax/test_data/parser/inline/ok/0162_default_async_unsafe_fn.rs b/crates/syntax/test_data/parser/inline/ok/0162_default_async_unsafe_fn.rs
new file mode 100644
index 000000000..05c20a68f
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0162_default_async_unsafe_fn.rs
@@ -0,0 +1,3 @@
1impl T for Foo {
2 default async unsafe fn foo() {}
3}
diff --git a/crates/syntax/test_data/parser/inline/ok/0163_default_async_fn.rast b/crates/syntax/test_data/parser/inline/ok/0163_default_async_fn.rast
new file mode 100644
index 000000000..9c43ccea5
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0163_default_async_fn.rast
@@ -0,0 +1,40 @@
1[email protected]
2 [email protected]
3 [email protected] "impl"
4 [email protected] " "
5 [email protected]
6 [email protected]
7 [email protected]
8 [email protected]
9 [email protected] "T"
10 [email protected] " "
11 [email protected] "for"
12 [email protected] " "
13 [email protected]
14 [email protected]
15 [email protected]
16 [email protected]
17 [email protected] "Foo"
18 [email protected] " "
19 [email protected]
20 [email protected] "{"
21 [email protected] "\n "
22 [email protected]
23 [email protected] "default"
24 [email protected] " "
25 [email protected] "async"
26 [email protected] " "
27 [email protected] "fn"
28 [email protected] " "
29 [email protected]
30 [email protected] "foo"
31 [email protected]
32 [email protected] "("
33 [email protected] ")"
34 [email protected] " "
35 [email protected]
36 [email protected] "{"
37 [email protected] "}"
38 [email protected] "\n"
39 [email protected] "}"
40 [email protected] "\n"
diff --git a/crates/syntax/test_data/parser/inline/ok/0163_default_async_fn.rs b/crates/syntax/test_data/parser/inline/ok/0163_default_async_fn.rs
new file mode 100644
index 000000000..78c3b4d85
--- /dev/null
+++ b/crates/syntax/test_data/parser/inline/ok/0163_default_async_fn.rs
@@ -0,0 +1,3 @@
1impl T for Foo {
2 default async fn foo() {}
3}