From 95d239da99cb1b7ba60f5f20f6df54e1397a1bca Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 15 Feb 2021 18:11:10 +0100 Subject: Specialization for async traits --- crates/parser/src/grammar/items.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'crates/parser') 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) { } } +/// Try to parse an item, completing `m` in case of success. pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { // test_err pub_expr // fn foo() { pub 92; } @@ -143,6 +144,33 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> { has_mods = true; } } + T![async] => { + // test default_async_fn + // impl T for Foo { + // default async fn foo() {} + // } + + // test default_async_unsafe_fn + // impl T for Foo { + // default async unsafe fn foo() {} + // } + let mut maybe_fn = p.nth(2); + let is_unsafe = if matches!(maybe_fn, T![unsafe]) { + maybe_fn = p.nth(3); + true + } else { + false + }; + + if matches!(maybe_fn, T![fn]) { + p.bump_remap(T![default]); + p.bump(T![async]); + if is_unsafe { + p.bump(T![unsafe]) + } + has_mods = true; + } + } _ => (), } } -- cgit v1.2.3