Auto merge of #62643 - estebank:parse-recovery-type-errs, r=petrochenkov
Do not emit type errors after parse error in last statement of block When recovering from a parse error inside a block, do not emit type errors generating on that block's recovered return expression. Fix #57383.
This commit is contained in:
commit
d82fd9ecd3
9 changed files with 42 additions and 61 deletions
|
@ -4675,6 +4675,9 @@ impl<'a> Parser<'a> {
|
||||||
{
|
{
|
||||||
e.emit();
|
e.emit();
|
||||||
self.recover_stmt();
|
self.recover_stmt();
|
||||||
|
// Don't complain about type errors in body tail after parse error (#57383).
|
||||||
|
let sp = expr.span.to(self.prev_span);
|
||||||
|
stmt.node = StmtKind::Expr(DummyResult::raw_expr(sp, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4692,8 +4695,7 @@ impl<'a> Parser<'a> {
|
||||||
if self.eat(&token::Semi) {
|
if self.eat(&token::Semi) {
|
||||||
stmt = stmt.add_trailing_semicolon();
|
stmt = stmt.add_trailing_semicolon();
|
||||||
}
|
}
|
||||||
|
stmt.span = stmt.span.to(self.prev_span);
|
||||||
stmt.span = stmt.span.with_hi(self.prev_span.hi());
|
|
||||||
Ok(Some(stmt))
|
Ok(Some(stmt))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let (x, y) = (0, 0);
|
let (x, y) = (0, 0);
|
||||||
x <- y; //~ ERROR expected one of
|
x <- y; //~ ERROR expected one of
|
||||||
//~^ ERROR mismatched types
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -5,23 +5,10 @@ LL | x <- y;
|
||||||
| ^^ expected one of 8 possible tokens here
|
| ^^ expected one of 8 possible tokens here
|
||||||
|
|
||||||
error: expected expression, found keyword `in`
|
error: expected expression, found keyword `in`
|
||||||
--> $DIR/bad.rs:11:5
|
--> $DIR/bad.rs:10:5
|
||||||
|
|
|
|
||||||
LL | in(foo) { bar };
|
LL | in(foo) { bar };
|
||||||
| ^^ expected expression
|
| ^^ expected expression
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error: aborting due to 2 previous errors
|
||||||
--> $DIR/bad.rs:5:5
|
|
||||||
|
|
|
||||||
LL | fn foo() {
|
|
||||||
| - possibly return type missing here?
|
|
||||||
LL | let (x, y) = (0, 0);
|
|
||||||
LL | x <- y;
|
|
||||||
| ^ expected (), found integer
|
|
||||||
|
|
|
||||||
= note: expected type `()`
|
|
||||||
found type `{integer}`
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
fn main() {
|
fn main() { // we don't complain about the return type being `{integer}`
|
||||||
let t = (42, 42);
|
let t = (42, 42);
|
||||||
t.0::<isize>; //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `::`
|
t.0::<isize>; //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `::`
|
||||||
//~| ERROR mismatched types
|
}
|
||||||
|
|
||||||
|
fn foo() -> usize { // we don't complain about the return type being unit
|
||||||
|
let t = (42, 42);
|
||||||
|
t.0::<isize>; //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `::`
|
||||||
|
42;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,18 +4,11 @@ error: expected one of `.`, `;`, `?`, `}`, or an operator, found `::`
|
||||||
LL | t.0::<isize>;
|
LL | t.0::<isize>;
|
||||||
| ^^ expected one of `.`, `;`, `?`, `}`, or an operator here
|
| ^^ expected one of `.`, `;`, `?`, `}`, or an operator here
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `::`
|
||||||
--> $DIR/issue-19096.rs:3:5
|
--> $DIR/issue-19096.rs:8:8
|
||||||
|
|
|
|
||||||
LL | fn main() {
|
|
||||||
| - expected `()` because of default return type
|
|
||||||
LL | let t = (42, 42);
|
|
||||||
LL | t.0::<isize>;
|
LL | t.0::<isize>;
|
||||||
| ^^^ expected (), found integer
|
| ^^ expected one of `.`, `;`, `?`, `}`, or an operator here
|
||||||
|
|
|
||||||
= note: expected type `()`
|
|
||||||
found type `{integer}`
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
|
||||||
|
|
|
@ -1,16 +1,25 @@
|
||||||
fn test_if() {
|
fn test_if() {
|
||||||
r#if true { } //~ ERROR found `true`
|
r#if true { } //~ ERROR found `true`
|
||||||
//~| ERROR cannot find value `if` in this scope
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_struct() {
|
fn test_struct() {
|
||||||
r#struct Test; //~ ERROR found `Test`
|
r#struct Test; //~ ERROR found `Test`
|
||||||
//~| ERROR cannot find value `struct` in this scope
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_union() {
|
fn test_union() {
|
||||||
r#union Test; //~ ERROR found `Test`
|
r#union Test; //~ ERROR found `Test`
|
||||||
//~| ERROR cannot find value `union` in this scope
|
}
|
||||||
|
|
||||||
|
fn test_if_2() {
|
||||||
|
let _ = r#if; //~ ERROR cannot find value `if` in this scope
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_struct_2() {
|
||||||
|
let _ = r#struct; //~ ERROR cannot find value `struct` in this scope
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_union_2() {
|
||||||
|
let _ = r#union; //~ ERROR cannot find value `union` in this scope
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -5,34 +5,34 @@ LL | r#if true { }
|
||||||
| ^^^^ expected one of 8 possible tokens here
|
| ^^^^ expected one of 8 possible tokens here
|
||||||
|
|
||||||
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test`
|
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test`
|
||||||
--> $DIR/raw-literal-keywords.rs:7:14
|
--> $DIR/raw-literal-keywords.rs:6:14
|
||||||
|
|
|
|
||||||
LL | r#struct Test;
|
LL | r#struct Test;
|
||||||
| ^^^^ expected one of 8 possible tokens here
|
| ^^^^ expected one of 8 possible tokens here
|
||||||
|
|
||||||
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test`
|
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `Test`
|
||||||
--> $DIR/raw-literal-keywords.rs:12:13
|
--> $DIR/raw-literal-keywords.rs:10:13
|
||||||
|
|
|
|
||||||
LL | r#union Test;
|
LL | r#union Test;
|
||||||
| ^^^^ expected one of 8 possible tokens here
|
| ^^^^ expected one of 8 possible tokens here
|
||||||
|
|
||||||
error[E0425]: cannot find value `if` in this scope
|
error[E0425]: cannot find value `if` in this scope
|
||||||
--> $DIR/raw-literal-keywords.rs:2:5
|
--> $DIR/raw-literal-keywords.rs:14:13
|
||||||
|
|
|
|
||||||
LL | r#if true { }
|
LL | let _ = r#if;
|
||||||
| ^^^^ not found in this scope
|
| ^^^^ not found in this scope
|
||||||
|
|
||||||
error[E0425]: cannot find value `struct` in this scope
|
error[E0425]: cannot find value `struct` in this scope
|
||||||
--> $DIR/raw-literal-keywords.rs:7:5
|
--> $DIR/raw-literal-keywords.rs:18:13
|
||||||
|
|
|
|
||||||
LL | r#struct Test;
|
LL | let _ = r#struct;
|
||||||
| ^^^^^^^^ not found in this scope
|
| ^^^^^^^^ not found in this scope
|
||||||
|
|
||||||
error[E0425]: cannot find value `union` in this scope
|
error[E0425]: cannot find value `union` in this scope
|
||||||
--> $DIR/raw-literal-keywords.rs:12:5
|
--> $DIR/raw-literal-keywords.rs:22:13
|
||||||
|
|
|
|
||||||
LL | r#union Test;
|
LL | let _ = r#union;
|
||||||
| ^^^^^^^ not found in this scope
|
| ^^^^^^^ not found in this scope
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@ pub mod raw {
|
||||||
callback(path.as_ref();
|
callback(path.as_ref();
|
||||||
//~^ ERROR expected one of
|
//~^ ERROR expected one of
|
||||||
fs::create_dir_all(path.as_ref()).map(|()| true)
|
fs::create_dir_all(path.as_ref()).map(|()| true)
|
||||||
//~^ ERROR mismatched types
|
|
||||||
} else {
|
} else {
|
||||||
//~^ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
|
//~^ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
|
||||||
Ok(false);
|
Ok(false);
|
||||||
|
|
|
@ -7,11 +7,10 @@ LL | callback(path.as_ref();
|
||||||
| unclosed delimiter
|
| unclosed delimiter
|
||||||
|
|
||||||
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
|
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
|
||||||
--> $DIR/token-error-correct-3.rs:19:9
|
--> $DIR/token-error-correct-3.rs:18:9
|
||||||
|
|
|
|
||||||
LL | fs::create_dir_all(path.as_ref()).map(|()| true)
|
LL | fs::create_dir_all(path.as_ref()).map(|()| true)
|
||||||
| - expected one of `.`, `;`, `?`, `}`, or an operator here
|
| - expected one of `.`, `;`, `?`, `}`, or an operator here
|
||||||
LL |
|
|
||||||
LL | } else {
|
LL | } else {
|
||||||
| ^ unexpected token
|
| ^ unexpected token
|
||||||
|
|
||||||
|
@ -21,18 +20,6 @@ error[E0425]: cannot find function `is_directory` in this scope
|
||||||
LL | if !is_directory(path.as_ref()) {
|
LL | if !is_directory(path.as_ref()) {
|
||||||
| ^^^^^^^^^^^^ not found in this scope
|
| ^^^^^^^^^^^^ not found in this scope
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error: aborting due to 3 previous errors
|
||||||
--> $DIR/token-error-correct-3.rs:17:13
|
|
||||||
|
|
|
||||||
LL | fs::create_dir_all(path.as_ref()).map(|()| true)
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: try adding a semicolon: `;`
|
|
||||||
| |
|
|
||||||
| expected (), found enum `std::result::Result`
|
|
||||||
|
|
|
||||||
= note: expected type `()`
|
|
||||||
found type `std::result::Result<bool, std::io::Error>`
|
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
For more information about this error, try `rustc --explain E0425`.
|
||||||
|
|
||||||
Some errors have detailed explanations: E0308, E0425.
|
|
||||||
For more information about an error, try `rustc --explain E0308`.
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue