Auto merge of #46732 - estebank:silence-recovered-blocks, r=petrochenkov

Do not emit type errors on recovered blocks

When a parse error occurs on a block, the parser will recover and create
a block with the statements collected until that point. Now a flag
stating that a recovery has been performed in this block is propagated
so that the type checker knows that the type of the block (which will be
identified as `()`) shouldn't be checked against the expectation to
reduce the amount of irrelevant diagnostic errors shown to the user.

Fix #44579.
This commit is contained in:
bors 2017-12-22 07:22:33 +00:00
commit c2ecab1121
26 changed files with 113 additions and 42 deletions

View file

@ -11,5 +11,4 @@
fn main () {
let sr: Vec<(u32, _, _) = vec![]; //~ ERROR expected one of `,` or `>`, found `=`
let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect();
//~^ ERROR cannot find value `sr` in this scope
}

View file

@ -16,7 +16,6 @@ fn main() {
println!("Y {}",x);
return x;
};
//~^ ERROR expected item, found `;`
caller(bar_handler);
}

View file

@ -11,6 +11,10 @@
// compile-flags: -Z parse-only
fn main() {
struct::foo(); //~ ERROR expected identifier
mut::baz(); //~ ERROR expected expression, found keyword `mut`
struct::foo();
//~^ ERROR expected identifier
}
fn bar() {
mut::baz();
//~^ ERROR expected expression, found keyword `mut`
}

View file

@ -15,5 +15,4 @@
pub fn main() {
struct Foo { x: isize }
let mut Foo { x: x } = Foo { x: 3 }; //~ ERROR: expected one of `:`, `;`, `=`, or `@`, found `{`
//~^ ERROR expected item, found `=`
}

View file

@ -131,6 +131,7 @@ fn iter_exprs(depth: usize, f: &mut FnMut(P<Expr>)) {
id: DUMMY_NODE_ID,
rules: BlockCheckMode::Default,
span: DUMMY_SP,
recovered: false,
});
iter_exprs(depth - 1, &mut |e| g(ExprKind::If(e, block.clone(), None)));
},

View file

@ -17,11 +17,13 @@ pub fn main() {
0..;
..1;
0..1;
..=; //~ERROR inclusive range with no end
0..=; //~ERROR inclusive range with no end
..=1;
0..=1;
//~^HELP bounded at the end
}
fn _foo1() {
..=1;
0..=1;
0..=; //~ERROR inclusive range with no end
//~^HELP bounded at the end
}

View file

@ -1,15 +1,15 @@
error[E0586]: inclusive range with no end
--> $DIR/impossible_range.rs:21:8
--> $DIR/impossible_range.rs:20:8
|
21 | ..=; //~ERROR inclusive range with no end
20 | ..=; //~ERROR inclusive range with no end
| ^
|
= help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)
error[E0586]: inclusive range with no end
--> $DIR/impossible_range.rs:22:9
--> $DIR/impossible_range.rs:27:9
|
22 | 0..=; //~ERROR inclusive range with no end
27 | 0..=; //~ERROR inclusive range with no end
| ^
|
= help: inclusive ranges must be bounded at the end (`..=b` or `a..=b`)

View file

@ -13,5 +13,3 @@ error: expected type, found keyword `true`
18 | foo!(true); //~ ERROR expected type, found keyword
| ^^^^ expecting a type here because of type ascription
error: aborting due to 2 previous errors

View file

@ -43,5 +43,3 @@ error: expected expression, found reserved keyword `typeof`
26 | m!();
| ----- in this macro invocation
error: aborting due to 4 previous errors

View file

@ -0,0 +1,31 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::env;
pub struct Foo {
text: String
}
pub fn foo() -> Foo {
let args: Vec<String> = env::args().collect();
let text = args[1].clone();
pub Foo { text }
}
//~^^ ERROR missing `struct` for struct definition
pub fn bar() -> Foo {
fn
Foo { text: "".to_string() }
}
//~^^ ERROR expected one of `(` or `<`, found `{`
fn main() {}

View file

@ -0,0 +1,18 @@
error: missing `struct` for struct definition
--> $DIR/recovered-block.rs:21:8
|
21 | pub Foo { text }
| ^
help: add `struct` here to parse `Foo` as a public struct
|
21 | pub struct Foo { text }
| ^^^^^^
error: expected one of `(` or `<`, found `{`
--> $DIR/recovered-block.rs:27:9
|
27 | Foo { text: "".to_string() }
| ^ expected one of `(` or `<` here
error: aborting due to 2 previous errors

View file

@ -16,4 +16,3 @@ fn main() {
}
//~^ ERROR: incorrect close delimiter: `}`
//~| ERROR: incorrect close delimiter: `}`
//~| ERROR: expected expression, found `)`

View file

@ -28,11 +28,5 @@ error: expected expression, found `;`
14 | foo(bar(;
| ^
error: expected expression, found `)`
--> $DIR/token-error-correct.rs:16:1
|
16 | }
| ^
error: aborting due to 4 previous errors
error: aborting due to 3 previous errors