diff --git a/src/grammar/mod.rs b/src/grammar/mod.rs index b6da0d0133a..1e7d04ce93d 100644 --- a/src/grammar/mod.rs +++ b/src/grammar/mod.rs @@ -55,34 +55,43 @@ impl BlockLike { } fn visibility(p: &mut Parser) { - if p.at(PUB_KW) { - let vis = p.start(); - p.bump(); - if p.at(L_PAREN) { - match p.nth(1) { - // test crate_visibility - // pub(crate) struct S; - // pub(self) struct S; - // pub(self) struct S; - // pub(self) struct S; - CRATE_KW | SELF_KW | SUPER_KW => { - p.bump(); - p.bump(); - p.expect(R_PAREN); + match p.current() { + PUB_KW => { + let m = p.start(); + p.bump(); + if p.at(L_PAREN) { + match p.nth(1) { + // test crate_visibility + // pub(crate) struct S; + // pub(self) struct S; + // pub(self) struct S; + // pub(self) struct S; + CRATE_KW | SELF_KW | SUPER_KW => { + p.bump(); + p.bump(); + p.expect(R_PAREN); + } + IN_KW => { + p.bump(); + p.bump(); + paths::use_path(p); + p.expect(R_PAREN); + } + _ => (), } - IN_KW => { - p.bump(); - p.bump(); - paths::use_path(p); - p.expect(R_PAREN); - } - _ => (), } + m.complete(p, VISIBILITY); } - vis.complete(p, VISIBILITY); + // test crate_keyword_vis + // crate fn main() { } + CRATE_KW => { + let m = p.start(); + p.bump(); + m.complete(p, VISIBILITY); + } + _ => (), } } - fn alias(p: &mut Parser) -> bool { if p.at(AS_KW) { let alias = p.start(); diff --git a/tests/data/parser/inline/0099_crate_keyword_vis.rs b/tests/data/parser/inline/0099_crate_keyword_vis.rs new file mode 100644 index 00000000000..660d927cf01 --- /dev/null +++ b/tests/data/parser/inline/0099_crate_keyword_vis.rs @@ -0,0 +1 @@ +crate fn main() { } diff --git a/tests/data/parser/inline/0099_crate_keyword_vis.txt b/tests/data/parser/inline/0099_crate_keyword_vis.txt new file mode 100644 index 00000000000..25e6d175930 --- /dev/null +++ b/tests/data/parser/inline/0099_crate_keyword_vis.txt @@ -0,0 +1,18 @@ +FILE@[0; 20) + FN_ITEM@[0; 19) + VISIBILITY@[0; 5) + CRATE_KW@[0; 5) + WHITESPACE@[5; 6) + FN_KW@[6; 8) + WHITESPACE@[8; 9) + NAME@[9; 13) + IDENT@[9; 13) "main" + PARAM_LIST@[13; 15) + L_PAREN@[13; 14) + R_PAREN@[14; 15) + WHITESPACE@[15; 16) + BLOCK_EXPR@[16; 19) + L_CURLY@[16; 17) + WHITESPACE@[17; 18) + R_CURLY@[18; 19) + WHITESPACE@[19; 20)