From e38685cb48a44c3321922f5f7228072b503d2973 Mon Sep 17 00:00:00 2001 From: Avi Dessauer Date: Mon, 8 Jun 2020 17:49:06 -0400 Subject: Parse default unsafe fn --- crates/ra_parser/src/grammar/items.rs | 8 ++++- .../parser/inline/ok/0163_default_unsafe_fn.rast | 40 ++++++++++++++++++++++ .../parser/inline/ok/0163_default_unsafe_fn.rs | 3 ++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rast create mode 100644 crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rs diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 9c14b954a..56cfb509d 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -121,7 +121,13 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul T![unsafe] => { // test default_unsafe_impl // default unsafe impl Foo {} - if p.nth(2) == T![impl] { + + // test default_unsafe_fn + // impl T for Foo { + // default unsafe fn foo() {} + // } + let sk = p.nth(2); + if sk == T![impl] || sk == T![fn] { p.bump_remap(T![default]); p.bump(T![unsafe]); has_mods = true; diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rast b/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rast new file mode 100644 index 000000000..adb6159f4 --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rast @@ -0,0 +1,40 @@ +SOURCE_FILE@0..50 + IMPL_DEF@0..49 + 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 " " + ITEM_LIST@15..49 + L_CURLY@15..16 "{" + WHITESPACE@16..21 "\n " + FN_DEF@21..47 + DEFAULT_KW@21..28 "default" + WHITESPACE@28..29 " " + UNSAFE_KW@29..35 "unsafe" + WHITESPACE@35..36 " " + FN_KW@36..38 "fn" + WHITESPACE@38..39 " " + NAME@39..42 + IDENT@39..42 "foo" + PARAM_LIST@42..44 + L_PAREN@42..43 "(" + R_PAREN@43..44 ")" + WHITESPACE@44..45 " " + BLOCK_EXPR@45..47 + L_CURLY@45..46 "{" + R_CURLY@46..47 "}" + WHITESPACE@47..48 "\n" + R_CURLY@48..49 "}" + WHITESPACE@49..50 "\n" diff --git a/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rs b/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rs new file mode 100644 index 000000000..12926cd8a --- /dev/null +++ b/crates/ra_syntax/test_data/parser/inline/ok/0163_default_unsafe_fn.rs @@ -0,0 +1,3 @@ +impl T for Foo { + default unsafe fn foo() {} +} -- cgit v1.2.3 From 2785362a1f9a3436072152e5499ac5d7c4d98cc4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Jun 2020 10:50:25 +0200 Subject: Update crates/ra_parser/src/grammar/items.rs --- crates/ra_parser/src/grammar/items.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs index 56cfb509d..97642bc24 100644 --- a/crates/ra_parser/src/grammar/items.rs +++ b/crates/ra_parser/src/grammar/items.rs @@ -126,8 +126,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul // impl T for Foo { // default unsafe fn foo() {} // } - let sk = p.nth(2); - if sk == T![impl] || sk == T![fn] { + if p.nth(2) == T![impl] || p.nth(2) == T![fn] { p.bump_remap(T![default]); p.bump(T![unsafe]); has_mods = true; -- cgit v1.2.3