Skip to content

Commit 8a11da4

Browse files
committed
Parse unsafe extern block
1 parent cadf0e9 commit 8a11da4

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

crates/parser/src/grammar/items.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
112112
has_mods = true;
113113
}
114114

115-
if p.at(T![extern]) {
115+
if p.at(T![extern]) && p.nth(1) != T!['{'] && (p.nth(1) != STRING || p.nth(2) != T!['{']) {
116116
has_mods = true;
117117
abi(p);
118118
}
@@ -181,6 +181,14 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
181181
T![type] => {
182182
type_alias(p, m);
183183
}
184+
185+
// unsafe extern "C" {}
186+
T![extern] => {
187+
abi(p);
188+
extern_item_list(p);
189+
m.complete(p, EXTERN_BLOCK);
190+
}
191+
184192
_ => {
185193
if !has_visibility && !has_mods {
186194
return Err(m);

crates/syntax/test_data/parser/ok/0068_item_modifiers.rast

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SOURCE_FILE@0..304
1+
SOURCE_FILE@0..328
22
33
44
@@ -215,4 +215,16 @@ [email protected]
215215
216216
217217
218-
218+
219+
220+
221+
222+
223+
224+
225+
226+
227+
228+
229+
230+

crates/syntax/test_data/parser/ok/0068_item_modifiers.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ unsafe auto trait T {}
1414
unsafe impl Foo {}
1515
default impl Foo {}
1616
unsafe default impl Foo {}
17+
18+
unsafe extern "C++" {}

0 commit comments

Comments
 (0)