mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-27 04:15:08 +00:00
Parse default unsafe & default const
This commit is contained in:
parent
65a3cc21ed
commit
fb632c747d
2 changed files with 45 additions and 15 deletions
|
@ -118,7 +118,15 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
|
||||||
&& p.at_contextual_kw("default")
|
&& p.at_contextual_kw("default")
|
||||||
&& (match p.nth(1) {
|
&& (match p.nth(1) {
|
||||||
T![impl] => true,
|
T![impl] => true,
|
||||||
T![fn] | T![type] => {
|
T![unsafe] => {
|
||||||
|
if T![impl] == p.nth(2) {
|
||||||
|
p.bump_remap(T![default]);
|
||||||
|
p.bump_remap(T![unsafe]);
|
||||||
|
has_mods = true;
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
T![fn] | T![type] | T![const] => {
|
||||||
if let ItemFlavor::Mod = flavor {
|
if let ItemFlavor::Mod = flavor {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
|
@ -187,6 +195,9 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
|
||||||
// test default_impl
|
// test default_impl
|
||||||
// default impl Foo {}
|
// default impl Foo {}
|
||||||
|
|
||||||
|
// test default_unsafe_impl
|
||||||
|
// default unsafe impl Foo {}
|
||||||
|
|
||||||
// test_err default_fn_type
|
// test_err default_fn_type
|
||||||
// trait T {
|
// trait T {
|
||||||
// default type T = Bar;
|
// default type T = Bar;
|
||||||
|
@ -199,6 +210,19 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
|
||||||
// default fn foo() {}
|
// default fn foo() {}
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// test_err default_const
|
||||||
|
// trait T {
|
||||||
|
// default const f: u8 = 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// test default_const
|
||||||
|
// impl T for Foo {
|
||||||
|
// default const f: u8 = 0;
|
||||||
|
// }
|
||||||
|
T![const] => {
|
||||||
|
consts::const_def(p, m);
|
||||||
|
}
|
||||||
|
|
||||||
// test unsafe_default_impl
|
// test unsafe_default_impl
|
||||||
// unsafe default impl Foo {}
|
// unsafe default impl Foo {}
|
||||||
T![impl] => {
|
T![impl] => {
|
||||||
|
|
|
@ -17,23 +17,29 @@ SOURCE_FILE@0..50
|
||||||
L_CURLY@22..23 "{"
|
L_CURLY@22..23 "{"
|
||||||
R_CURLY@23..24 "}"
|
R_CURLY@23..24 "}"
|
||||||
WHITESPACE@24..25 "\n"
|
WHITESPACE@24..25 "\n"
|
||||||
ERROR@25..31
|
CONST_DEF@25..46
|
||||||
UNSAFE_KW@25..31 "unsafe"
|
UNSAFE_KW@25..31 "unsafe"
|
||||||
WHITESPACE@31..32 " "
|
WHITESPACE@31..32 " "
|
||||||
FN_DEF@32..49
|
|
||||||
CONST_KW@32..37 "const"
|
CONST_KW@32..37 "const"
|
||||||
WHITESPACE@37..38 " "
|
WHITESPACE@37..38 " "
|
||||||
FN_KW@38..40 "fn"
|
ERROR@38..40
|
||||||
|
FN_KW@38..40 "fn"
|
||||||
WHITESPACE@40..41 " "
|
WHITESPACE@40..41 " "
|
||||||
NAME@41..44
|
PATH_TYPE@41..46
|
||||||
IDENT@41..44 "bar"
|
PATH@41..46
|
||||||
PARAM_LIST@44..46
|
PATH_SEGMENT@41..46
|
||||||
L_PAREN@44..45 "("
|
NAME_REF@41..44
|
||||||
R_PAREN@45..46 ")"
|
IDENT@41..44 "bar"
|
||||||
WHITESPACE@46..47 " "
|
PARAM_LIST@44..46
|
||||||
BLOCK_EXPR@47..49
|
L_PAREN@44..45 "("
|
||||||
L_CURLY@47..48 "{"
|
R_PAREN@45..46 ")"
|
||||||
R_CURLY@48..49 "}"
|
WHITESPACE@46..47 " "
|
||||||
|
ERROR@47..49
|
||||||
|
L_CURLY@47..48 "{"
|
||||||
|
R_CURLY@48..49 "}"
|
||||||
WHITESPACE@49..50 "\n"
|
WHITESPACE@49..50 "\n"
|
||||||
error 6..6: expected existential, fn, trait or impl
|
error 6..6: expected existential, fn, trait or impl
|
||||||
error 31..31: expected existential, fn, trait or impl
|
error 38..38: expected a name
|
||||||
|
error 40..40: expected COLON
|
||||||
|
error 46..46: expected SEMICOLON
|
||||||
|
error 47..47: expected an item
|
||||||
|
|
Loading…
Reference in a new issue