mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Specialization for async traits
This commit is contained in:
parent
00d5a9563a
commit
95d239da99
5 changed files with 116 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
SOURCE_FILE@0..56
|
||||
IMPL@0..55
|
||||
IMPL_KW@0..4 "impl"
|
||||
WHITESPACE@4..5 " "
|
||||
PATH_TYPE@5..6
|
||||
PATH@5..6
|
||||
PATH_SEGMENT@5..6
|
||||
NAME_REF@5..6
|
||||
IDENT@5..6 "T"
|
||||
WHITESPACE@6..7 " "
|
||||
FOR_KW@7..10 "for"
|
||||
WHITESPACE@10..11 " "
|
||||
PATH_TYPE@11..14
|
||||
PATH@11..14
|
||||
PATH_SEGMENT@11..14
|
||||
NAME_REF@11..14
|
||||
IDENT@11..14 "Foo"
|
||||
WHITESPACE@14..15 " "
|
||||
ASSOC_ITEM_LIST@15..55
|
||||
L_CURLY@15..16 "{"
|
||||
WHITESPACE@16..21 "\n "
|
||||
FN@21..53
|
||||
DEFAULT_KW@21..28 "default"
|
||||
WHITESPACE@28..29 " "
|
||||
ASYNC_KW@29..34 "async"
|
||||
WHITESPACE@34..35 " "
|
||||
UNSAFE_KW@35..41 "unsafe"
|
||||
WHITESPACE@41..42 " "
|
||||
FN_KW@42..44 "fn"
|
||||
WHITESPACE@44..45 " "
|
||||
NAME@45..48
|
||||
IDENT@45..48 "foo"
|
||||
PARAM_LIST@48..50
|
||||
L_PAREN@48..49 "("
|
||||
R_PAREN@49..50 ")"
|
||||
WHITESPACE@50..51 " "
|
||||
BLOCK_EXPR@51..53
|
||||
L_CURLY@51..52 "{"
|
||||
R_CURLY@52..53 "}"
|
||||
WHITESPACE@53..54 "\n"
|
||||
R_CURLY@54..55 "}"
|
||||
WHITESPACE@55..56 "\n"
|
|
@ -0,0 +1,3 @@
|
|||
impl T for Foo {
|
||||
default async unsafe fn foo() {}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
SOURCE_FILE@0..49
|
||||
IMPL@0..48
|
||||
IMPL_KW@0..4 "impl"
|
||||
WHITESPACE@4..5 " "
|
||||
PATH_TYPE@5..6
|
||||
PATH@5..6
|
||||
PATH_SEGMENT@5..6
|
||||
NAME_REF@5..6
|
||||
IDENT@5..6 "T"
|
||||
WHITESPACE@6..7 " "
|
||||
FOR_KW@7..10 "for"
|
||||
WHITESPACE@10..11 " "
|
||||
PATH_TYPE@11..14
|
||||
PATH@11..14
|
||||
PATH_SEGMENT@11..14
|
||||
NAME_REF@11..14
|
||||
IDENT@11..14 "Foo"
|
||||
WHITESPACE@14..15 " "
|
||||
ASSOC_ITEM_LIST@15..48
|
||||
L_CURLY@15..16 "{"
|
||||
WHITESPACE@16..21 "\n "
|
||||
FN@21..46
|
||||
DEFAULT_KW@21..28 "default"
|
||||
WHITESPACE@28..29 " "
|
||||
ASYNC_KW@29..34 "async"
|
||||
WHITESPACE@34..35 " "
|
||||
FN_KW@35..37 "fn"
|
||||
WHITESPACE@37..38 " "
|
||||
NAME@38..41
|
||||
IDENT@38..41 "foo"
|
||||
PARAM_LIST@41..43
|
||||
L_PAREN@41..42 "("
|
||||
R_PAREN@42..43 ")"
|
||||
WHITESPACE@43..44 " "
|
||||
BLOCK_EXPR@44..46
|
||||
L_CURLY@44..45 "{"
|
||||
R_CURLY@45..46 "}"
|
||||
WHITESPACE@46..47 "\n"
|
||||
R_CURLY@47..48 "}"
|
||||
WHITESPACE@48..49 "\n"
|
|
@ -0,0 +1,3 @@
|
|||
impl T for Foo {
|
||||
default async fn foo() {}
|
||||
}
|
Loading…
Reference in a new issue