Skip to content

Commit 4452f9e

Browse files
committed
internal: improve style
Group related stuff together, use only on path for parsing extern blocks (they actually have modifiers). Perhaps we should get rid of items_without_modifiers altogether? Better to handle these kinds on diagnostics in validation layer...
1 parent 8dc3b46 commit 4452f9e

File tree

5 files changed

+40
-43
lines changed

5 files changed

+40
-43
lines changed

crates/parser/src/grammar/items.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ pub(super) fn maybe_item(p: &mut Parser, m: Marker) -> Result<(), Marker> {
213213
type_alias(p, m);
214214
}
215215

216-
// test unsafe_extern_block
216+
// test extern_block
217217
// unsafe extern "C" {}
218+
// extern {}
218219
T!['{'] if has_extern => {
219220
extern_item_list(p);
220221
m.complete(p, EXTERN_BLOCK);
@@ -240,10 +241,11 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
240241
// test extern_crate
241242
// extern crate foo;
242243
T![extern] if la == T![crate] => extern_crate(p, m),
243-
T![type] => {
244-
type_alias(p, m);
245-
}
244+
T![use] => use_item::use_(p, m),
246245
T![mod] => mod_item(p, m),
246+
247+
T![type] => type_alias(p, m),
248+
247249
T![struct] => {
248250
// test struct_items
249251
// struct Foo;
@@ -256,14 +258,7 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
256258
// }
257259
adt::strukt(p, m);
258260
}
259-
// test pub_macro_def
260-
// pub macro m($:ident) {}
261-
T![macro] => {
262-
macro_def(p, m);
263-
}
264-
IDENT if p.at_contextual_kw("macro_rules") && p.nth(1) == BANG => {
265-
macro_rules(p, m);
266-
}
261+
T![enum] => adt::enum_(p, m),
267262
IDENT if p.at_contextual_kw("union") && p.nth(1) == IDENT => {
268263
// test union_items
269264
// union Foo {}
@@ -273,17 +268,19 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
273268
// }
274269
adt::union(p, m);
275270
}
276-
T![enum] => adt::enum_(p, m),
277-
T![use] => use_item::use_(p, m),
271+
272+
// test pub_macro_def
273+
// pub macro m($:ident) {}
274+
T![macro] => {
275+
macro_def(p, m);
276+
}
277+
IDENT if p.at_contextual_kw("macro_rules") && p.nth(1) == BANG => {
278+
macro_rules(p, m);
279+
}
280+
278281
T![const] if (la == IDENT || la == T![_] || la == T![mut]) => consts::konst(p, m),
279282
T![static] => consts::static_(p, m),
280-
// test extern_block
281-
// extern {}
282-
T![extern] if la == T!['{'] || (la == STRING && p.nth(2) == T!['{']) => {
283-
abi(p);
284-
extern_item_list(p);
285-
m.complete(p, EXTERN_BLOCK);
286-
}
283+
287284
_ => return Err(m),
288285
};
289286
Ok(())
@@ -292,6 +289,7 @@ fn items_without_modifiers(p: &mut Parser, m: Marker) -> Result<(), Marker> {
292289
fn extern_crate(p: &mut Parser, m: Marker) {
293290
assert!(p.at(T![extern]));
294291
p.bump(T![extern]);
292+
295293
assert!(p.at(T![crate]));
296294
p.bump(T![crate]);
297295

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
unsafe extern "C" {}
12
extern {}

crates/syntax/test_data/parser/inline/ok/0167_unsafe_extern_block.rast

Lines changed: 0 additions & 13 deletions
This file was deleted.

crates/syntax/test_data/parser/inline/ok/0167_unsafe_extern_block.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)