Skip to content

Commit e66c7b3

Browse files
Merge #4737
4737: Parse default unsafe & default const r=matklad a=Avi-D-coder Closes: #4718 #4264 Co-authored-by: Avi Dessauer <[email protected]>
2 parents c19496f + c4fd463 commit e66c7b3

File tree

8 files changed

+143
-15
lines changed

8 files changed

+143
-15
lines changed

crates/ra_parser/src/grammar/items.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,17 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
118118
&& p.at_contextual_kw("default")
119119
&& (match p.nth(1) {
120120
T![impl] => true,
121-
T![fn] | T![type] => {
121+
T![unsafe] => {
122+
// test default_unsafe_impl
123+
// default unsafe impl Foo {}
124+
if p.nth(2) == T![impl] {
125+
p.bump_remap(T![default]);
126+
p.bump(T![unsafe]);
127+
has_mods = true;
128+
}
129+
false
130+
}
131+
T![fn] | T![type] | T![const] => {
122132
if let ItemFlavor::Mod = flavor {
123133
true
124134
} else {
@@ -198,6 +208,9 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker, flavor: ItemFlavor) -> Resul
198208
// default type T = Bar;
199209
// default fn foo() {}
200210
// }
211+
T![const] => {
212+
consts::const_def(p, m);
213+
}
201214

202215
// test unsafe_default_impl
203216
// unsafe default impl Foo {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait T {
2+
default const f: u8 = 0;
3+
}

crates/ra_syntax/test_data/parser/inline/err/0010_wrong_order_fns.rast

+20-14
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,29 @@ [email protected]
1717
1818
1919
20-
ERROR@25..31
20+
CONST_DEF@25..46
2121
22-
23-
22+
2423
2524
26-
25+
26+
2727
28-
29-
30-
31-
32-
33-
34-
35-
36-
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
3740
3841
error 6..6: expected existential, fn, trait or impl
39-
error 31..31: expected existential, fn, trait or impl
42+
error 38..38: expected a name
43+
error 40..40: expected COLON
44+
error 46..46: expected SEMICOLON
45+
error 47..47: expected an item
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default unsafe impl Foo {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
impl T for Foo {
2+
default const f: u8 = 0;
3+
}

0 commit comments

Comments
 (0)