Skip to content

Commit

Permalink
Merge #4803
Browse files Browse the repository at this point in the history
4803: Parse default unsafe fn r=matklad a=Avi-D-coder



Co-authored-by: Avi Dessauer <avi.the.coder@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
  • Loading branch information
3 people authored Jun 9, 2020
2 parents 7ae2228 + 2785362 commit 6f0cc91
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/ra_parser/src/grammar/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ 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() {}
// }
if p.nth(2) == T![impl] || p.nth(2) == T![fn] {
p.bump_remap(T![default]);
p.bump(T![unsafe]);
has_mods = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
impl T for Foo {
default unsafe fn foo() {}
}

0 comments on commit 6f0cc91

Please sign in to comment.