mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
commit
37ee4c4c2a
4 changed files with 44 additions and 4 deletions
|
@ -1,8 +1,8 @@
|
|||
use super::*;
|
||||
|
||||
pub(super) fn mod_contents(p: &mut Parser) {
|
||||
pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
|
||||
attributes::inner_attributes(p);
|
||||
while !p.at(EOF) {
|
||||
while !p.at(EOF) && !(stop_on_r_curly && p.at(R_CURLY)) {
|
||||
item(p);
|
||||
}
|
||||
}
|
||||
|
@ -152,7 +152,10 @@ fn mod_item(p: &mut Parser) {
|
|||
p.bump();
|
||||
|
||||
if p.expect(IDENT) && !p.eat(SEMI) {
|
||||
p.curly_block(mod_contents);
|
||||
if p.expect(L_CURLY) {
|
||||
mod_contents(p, true);
|
||||
p.expect(R_CURLY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ mod paths;
|
|||
pub(crate) fn file(p: &mut Parser) {
|
||||
let file = p.start();
|
||||
p.eat(SHEBANG);
|
||||
items::mod_contents(p);
|
||||
items::mod_contents(p, false);
|
||||
file.complete(p, FILE);
|
||||
}
|
||||
|
||||
|
|
9
tests/data/parser/err/0007_stray_curly_in_file.rs
Normal file
9
tests/data/parser/err/0007_stray_curly_in_file.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
}
|
||||
|
||||
struct S;
|
||||
|
||||
}
|
||||
|
||||
fn foo(){}
|
||||
|
||||
}
|
28
tests/data/parser/err/0007_stray_curly_in_file.txt
Normal file
28
tests/data/parser/err/0007_stray_curly_in_file.txt
Normal file
|
@ -0,0 +1,28 @@
|
|||
FILE@[0; 31)
|
||||
ERROR@[0; 3)
|
||||
err: `expected item`
|
||||
R_CURLY@[0; 1)
|
||||
WHITESPACE@[1; 3)
|
||||
STRUCT_ITEM@[3; 14)
|
||||
STRUCT_KW@[3; 9)
|
||||
WHITESPACE@[9; 10)
|
||||
IDENT@[10; 11)
|
||||
SEMI@[11; 12)
|
||||
WHITESPACE@[12; 14)
|
||||
ERROR@[14; 17)
|
||||
err: `expected item`
|
||||
R_CURLY@[14; 15)
|
||||
WHITESPACE@[15; 17)
|
||||
FN_ITEM@[17; 29)
|
||||
FN_KW@[17; 19)
|
||||
WHITESPACE@[19; 20)
|
||||
IDENT@[20; 23)
|
||||
L_PAREN@[23; 24)
|
||||
R_PAREN@[24; 25)
|
||||
L_CURLY@[25; 26)
|
||||
R_CURLY@[26; 27)
|
||||
WHITESPACE@[27; 29)
|
||||
ERROR@[29; 31)
|
||||
err: `expected item`
|
||||
R_CURLY@[29; 30)
|
||||
WHITESPACE@[30; 31)
|
Loading…
Reference in a new issue