Fix error blocks

This commit is contained in:
Aleksey Kladov 2018-08-27 21:10:02 +03:00
parent 7f4b07a907
commit b79c8b6d8a
6 changed files with 20 additions and 1 deletions

View file

@ -130,6 +130,7 @@ impl WorldState {
} }
} }
#[derive(Debug)]
pub enum QuickFix { pub enum QuickFix {
CreateFile(PathBuf), CreateFile(PathBuf),
} }

View file

@ -52,7 +52,8 @@ fn test_unresolved_module_diagnostic() {
let snap = world.snapshot(|_id, _path| None); let snap = world.snapshot(|_id, _path| None);
let diagnostics = snap.diagnostics(FileId(1)).unwrap(); let diagnostics = snap.diagnostics(FileId(1)).unwrap();
assert_eq_dbg( assert_eq_dbg(
r#"[Diagnostic { range: [4; 7), msg: "unresolved module" }]"#, r#"[(Diagnostic { range: [4; 7), msg: "unresolved module" },
Some(CreateFile("../foo.rs")))]"#,
&diagnostics, &diagnostics,
); );
} }

View file

@ -269,6 +269,10 @@ fn match_arm_list(p: &mut Parser) {
let m = p.start(); let m = p.start();
p.eat(L_CURLY); p.eat(L_CURLY);
while !p.at(EOF) && !p.at(R_CURLY) { while !p.at(EOF) && !p.at(R_CURLY) {
if p.at(L_CURLY) {
error_block(p, "expected match arm");
continue;
}
// test match_arms_commas // test match_arms_commas
// fn foo() { // fn foo() {
// match () { // match () {

View file

@ -433,6 +433,7 @@ fn named_field_list(p: &mut Parser) {
p.bump(); p.bump();
expr(p); expr(p);
} }
L_CURLY => error_block(p, "expected a field"),
_ => p.err_and_bump("expected identifier"), _ => p.err_and_bump("expected identifier"),
} }
if !p.at(R_CURLY) { if !p.at(R_CURLY) {

View file

@ -56,6 +56,10 @@ fn enum_variant_list(p: &mut Parser) {
let m = p.start(); let m = p.start();
p.bump(); p.bump();
while !p.at(EOF) && !p.at(R_CURLY) { while !p.at(EOF) && !p.at(R_CURLY) {
if p.at(L_CURLY) {
error_block(p, "expected enum variant");
continue;
}
let var = p.start(); let var = p.start();
attributes::outer_attributes(p); attributes::outer_attributes(p);
if p.at(IDENT) { if p.at(IDENT) {

View file

@ -30,6 +30,10 @@ fn trait_item_list(p: &mut Parser) {
let m = p.start(); let m = p.start();
p.bump(); p.bump();
while !p.at(EOF) && !p.at(R_CURLY) { while !p.at(EOF) && !p.at(R_CURLY) {
if p.at(L_CURLY) {
error_block(p, "expected an item");
continue;
}
item_or_macro(p, true, ItemFlavor::Trait); item_or_macro(p, true, ItemFlavor::Trait);
} }
p.expect(R_CURLY); p.expect(R_CURLY);
@ -76,6 +80,10 @@ fn impl_item_list(p: &mut Parser) {
p.bump(); p.bump();
while !p.at(EOF) && !p.at(R_CURLY) { while !p.at(EOF) && !p.at(R_CURLY) {
if p.at(L_CURLY) {
error_block(p, "expected an item");
continue;
}
item_or_macro(p, true, ItemFlavor::Mod); item_or_macro(p, true, ItemFlavor::Mod);
} }
p.expect(R_CURLY); p.expect(R_CURLY);