Rollup merge of #57540 - estebank:eval-more, r=petrochenkov

Modify some parser diagnostics to continue evaluating beyond the parser

Continue evaluating further errors after parser errors on:
 - trailing type argument attribute
 - lifetime in incorrect location
 - incorrect binary literal
 - missing `for` in `impl Trait for Foo`
 - type argument in `where` clause
 - incorrect float literal
 - incorrect `..` in pattern
 - associated types
 - incorrect discriminator value variant error

and others. All of these were found by making `continue-parse-after-error` `true` by default to identify errors that would need few changes. There are now only a handful of errors that have any change with `continue-parse-after-error` enabled.

These changes make it so `rust` _won't_ stop evaluation after finishing parsing, enabling type checking errors to be displayed on the existing code without having to fix the parse errors.

Each commit has an individual diagnostic change with their corresponding tests.

CC #48724.
This commit is contained in:
Mazdak Farrokhzad 2019-01-14 20:31:55 +01:00 committed by GitHub
commit 2f7a226c4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
41 changed files with 344 additions and 141 deletions

View file

@ -2,7 +2,7 @@ error: trailing attribute after lifetime parameters
--> $DIR/attrs-with-no-formal-in-generics-1.rs:9:25
|
LL | impl<#[rustc_1] 'a, 'b, #[oops]> RefIntPair<'a, 'b> {
| ^^^^^^^
| ^^^^^^^ attributes must go before parameters
error: aborting due to previous error

View file

@ -2,7 +2,7 @@ error: trailing attribute after type parameters
--> $DIR/attrs-with-no-formal-in-generics-2.rs:9:35
|
LL | impl<#[rustc_1] 'a, #[rustc_2] T, #[oops]> RefAny<'a, T> {}
| ^^^^^^^
| ^^^^^^^ attributes must go before parameters
error: aborting due to previous error

View file

@ -5,12 +5,8 @@
struct RefIntPair<'a, 'b>(&'a u32, &'b u32);
fn hof_lt<Q>(_: Q)
where Q: for <#[rustc_1] 'a, 'b, #[oops]> Fn(RefIntPair<'a,'b>) -> &'b u32
where Q: for <#[allow(unused)] 'a, 'b, #[oops]> Fn(RefIntPair<'a,'b>) -> &'b u32
//~^ ERROR trailing attribute after lifetime parameters
{
{}
}
fn main() {
}
fn main() {}

View file

@ -1,8 +1,8 @@
error: trailing attribute after lifetime parameters
--> $DIR/attrs-with-no-formal-in-generics-3.rs:8:38
--> $DIR/attrs-with-no-formal-in-generics-3.rs:8:44
|
LL | where Q: for <#[rustc_1] 'a, 'b, #[oops]> Fn(RefIntPair<'a,'b>) -> &'b u32
| ^^^^^^^
LL | where Q: for <#[allow(unused)] 'a, 'b, #[oops]> Fn(RefIntPair<'a,'b>) -> &'b u32
| ^^^^^^^ attributes must go before parameters
error: aborting due to previous error

View file

@ -2,7 +2,7 @@ error: invalid suffix `is` for numeric literal
--> $DIR/old-suffixes-are-really-forbidden.rs:2:13
|
LL | let a = 1_is; //~ ERROR invalid suffix
| ^^^^
| ^^^^ invalid suffix `is`
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
@ -10,7 +10,7 @@ error: invalid suffix `us` for numeric literal
--> $DIR/old-suffixes-are-really-forbidden.rs:3:13
|
LL | let b = 2_us; //~ ERROR invalid suffix
| ^^^^
| ^^^^ invalid suffix `us`
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)

View file

@ -2,49 +2,49 @@ error: ABI spec with a suffix is invalid
--> $DIR/bad-lit-suffixes.rs:5:5
|
LL | "C"suffix //~ ERROR ABI spec with a suffix is invalid
| ^^^^^^^^^
| ^^^^^^^^^ ABI spec with a suffix is invalid
error: ABI spec with a suffix is invalid
--> $DIR/bad-lit-suffixes.rs:9:5
|
LL | "C"suffix //~ ERROR ABI spec with a suffix is invalid
| ^^^^^^^^^
| ^^^^^^^^^ ABI spec with a suffix is invalid
error: string literal with a suffix is invalid
--> $DIR/bad-lit-suffixes.rs:13:5
|
LL | ""suffix; //~ ERROR string literal with a suffix is invalid
| ^^^^^^^^
| ^^^^^^^^ string literal with a suffix is invalid
error: byte string literal with a suffix is invalid
--> $DIR/bad-lit-suffixes.rs:14:5
|
LL | b""suffix; //~ ERROR byte string literal with a suffix is invalid
| ^^^^^^^^^
| ^^^^^^^^^ byte string literal with a suffix is invalid
error: string literal with a suffix is invalid
--> $DIR/bad-lit-suffixes.rs:15:5
|
LL | r#""#suffix; //~ ERROR string literal with a suffix is invalid
| ^^^^^^^^^^^
| ^^^^^^^^^^^ string literal with a suffix is invalid
error: byte string literal with a suffix is invalid
--> $DIR/bad-lit-suffixes.rs:16:5
|
LL | br#""#suffix; //~ ERROR byte string literal with a suffix is invalid
| ^^^^^^^^^^^^
| ^^^^^^^^^^^^ byte string literal with a suffix is invalid
error: char literal with a suffix is invalid
--> $DIR/bad-lit-suffixes.rs:17:5
|
LL | 'a'suffix; //~ ERROR char literal with a suffix is invalid
| ^^^^^^^^^
| ^^^^^^^^^ char literal with a suffix is invalid
error: byte literal with a suffix is invalid
--> $DIR/bad-lit-suffixes.rs:18:5
|
LL | b'a'suffix; //~ ERROR byte literal with a suffix is invalid
| ^^^^^^^^^^
| ^^^^^^^^^^ byte literal with a suffix is invalid
error: invalid width `1024` for integer literal
--> $DIR/bad-lit-suffixes.rs:20:5
@ -82,7 +82,7 @@ error: invalid suffix `suffix` for numeric literal
--> $DIR/bad-lit-suffixes.rs:25:5
|
LL | 1234suffix; //~ ERROR invalid suffix `suffix` for numeric literal
| ^^^^^^^^^^
| ^^^^^^^^^^ invalid suffix `suffix`
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
@ -90,7 +90,7 @@ error: invalid suffix `suffix` for numeric literal
--> $DIR/bad-lit-suffixes.rs:26:5
|
LL | 0b101suffix; //~ ERROR invalid suffix `suffix` for numeric literal
| ^^^^^^^^^^^
| ^^^^^^^^^^^ invalid suffix `suffix`
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
@ -98,7 +98,7 @@ error: invalid suffix `suffix` for float literal
--> $DIR/bad-lit-suffixes.rs:27:5
|
LL | 1.0suffix; //~ ERROR invalid suffix `suffix` for float literal
| ^^^^^^^^^
| ^^^^^^^^^ invalid suffix `suffix`
|
= help: valid suffixes are `f32` and `f64`
@ -106,7 +106,7 @@ error: invalid suffix `suffix` for float literal
--> $DIR/bad-lit-suffixes.rs:28:5
|
LL | 1.0e10suffix; //~ ERROR invalid suffix `suffix` for float literal
| ^^^^^^^^^^^^
| ^^^^^^^^^^^^ invalid suffix `suffix`
|
= help: valid suffixes are `f32` and `f64`

View file

@ -1,5 +1,5 @@
fn foo(_: *()) {
//~^ expected mut or const in raw pointer type (use `*mut T` or `*const T` as appropriate)
//~^ ERROR expected mut or const in raw pointer type
}
fn main() {}

View file

@ -1,8 +1,10 @@
error: expected mut or const in raw pointer type (use `*mut T` or `*const T` as appropriate)
error: expected mut or const in raw pointer type
--> $DIR/bad-pointer-type.rs:1:11
|
LL | fn foo(_: *()) {
| ^
| ^ expected mut or const in raw pointer type
|
= help: use `*mut T` or `*const T` as appropriate
error: aborting due to previous error

View file

@ -2,13 +2,13 @@ error: missing `for` in a trait impl
--> $DIR/impl-parsing.rs:6:11
|
LL | impl Trait Type {} //~ ERROR missing `for` in a trait impl
| ^
| ^ help: add `for` here
error: missing `for` in a trait impl
--> $DIR/impl-parsing.rs:7:11
|
LL | impl Trait .. {} //~ ERROR missing `for` in a trait impl
| ^
| ^ help: add `for` here
error: expected a trait, found type
--> $DIR/impl-parsing.rs:8:6

View file

@ -1,6 +1,17 @@
fn main() {
(0..4)
.map(|x| x * 2)
.collect::<Vec<'a, usize, 'b>>()
//~^ ERROR lifetime parameters must be declared prior to type parameters
// can't run rustfix because it doesn't handle multipart suggestions correctly
// compile-flags: -Zborrowck=mir
// we need the above to avoid ast borrowck failure in recovered code
struct S<'a, T> {
a: &'a T,
b: &'a T,
}
fn foo<'a, 'b>(start: &'a usize, end: &'a usize) {
let _x = (*start..*end)
.map(|x| S { a: start, b: end })
.collect::<Vec<S<_, 'a>>>();
//~^ ERROR lifetime parameters must be declared prior to type parameters
}
fn main() {}

View file

@ -1,8 +1,12 @@
error: lifetime parameters must be declared prior to type parameters
--> $DIR/issue-14303-fncall.rs:4:31
--> $DIR/issue-14303-fncall.rs:13:29
|
LL | .collect::<Vec<'a, usize, 'b>>()
| ^^
LL | .collect::<Vec<S<_, 'a>>>();
| ^^ must be declared prior to type parameters
help: move the lifetime parameter prior to the first type parameter
|
LL | .collect::<Vec<S<'a, _>>>();
| ^^^ --
error: aborting due to previous error

View file

@ -1,4 +1,13 @@
fn bar<'a, T>(x: mymodule::X<'a, T, 'b, 'c>) {}
mod foo {
pub struct X<'a, 'b, 'c, T> {
a: &'a str,
b: &'b str,
c: &'c str,
t: T,
}
}
fn bar<'a, 'b, 'c, T>(x: foo::X<'a, T, 'b, 'c>) {}
//~^ ERROR lifetime parameters must be declared prior to type parameters
fn main() {}

View file

@ -1,8 +1,14 @@
error: lifetime parameters must be declared prior to type parameters
--> $DIR/issue-14303-path.rs:1:37
--> $DIR/issue-14303-path.rs:10:40
|
LL | fn bar<'a, T>(x: mymodule::X<'a, T, 'b, 'c>) {}
| ^^
LL | fn bar<'a, 'b, 'c, T>(x: foo::X<'a, T, 'b, 'c>) {}
| ^^ ^^ must be declared prior to type parameters
| |
| must be declared prior to type parameters
help: move the lifetime parameters prior to the first type parameter
|
LL | fn bar<'a, 'b, 'c, T>(x: foo::X<'a, 'b, 'c, T>) {}
| ^^^ ^^^ --
error: aborting due to previous error

View file

@ -1,8 +1,7 @@
enum X {
A =
b'a' //~ ERROR discriminator values can only be used with a field-less enum
,
B(isize)
A = 3,
//~^ ERROR discriminator values can only be used with a field-less enum
B(usize)
}
fn main() {}

View file

@ -1,8 +1,8 @@
error: discriminator values can only be used with a field-less enum
--> $DIR/issue-17383.rs:3:9
--> $DIR/issue-17383.rs:2:9
|
LL | b'a' //~ ERROR discriminator values can only be used with a field-less enum
| ^^^^
LL | A = 3,
| ^ only valid in field-less enums
error: aborting due to previous error

View file

@ -1,4 +1,7 @@
// error-pattern:no valid digits found for number
fn log(a: i32, b: i32) {}
fn main() {
let error = 42;
log(error, 0b);
//~^ ERROR no valid digits found for number
}

View file

@ -1,5 +1,5 @@
error: no valid digits found for number
--> $DIR/issue-1802-1.rs:3:16
--> $DIR/issue-1802-1.rs:5:16
|
LL | log(error, 0b);
| ^^

View file

@ -1,4 +1,7 @@
// error-pattern:no valid digits found for number
fn log(a: i32, b: i32) {}
fn main() {
log(error, 0b_usize);
let error = 42;
log(error, 0b);
//~^ ERROR no valid digits found for number
}

View file

@ -1,8 +1,8 @@
error: no valid digits found for number
--> $DIR/issue-1802-2.rs:3:16
--> $DIR/issue-1802-2.rs:5:16
|
LL | log(error, 0b_usize);
| ^^^
LL | log(error, 0b);
| ^^
error: aborting due to previous error

View file

@ -1,3 +1,10 @@
impl A .. {} //~ ERROR
trait A {}
impl A .. {}
//~^ ERROR missing `for` in a trait impl
//~| ERROR `impl Trait for .. {}` is an obsolete syntax
impl A usize {}
//~^ ERROR missing `for` in a trait impl
fn main() {}

View file

@ -1,8 +1,22 @@
error: missing `for` in a trait impl
--> $DIR/issue-27255.rs:1:7
--> $DIR/issue-27255.rs:3:7
|
LL | impl A .. {} //~ ERROR
| ^
LL | impl A .. {}
| ^ help: add `for` here
error: aborting due to previous error
error: missing `for` in a trait impl
--> $DIR/issue-27255.rs:7:7
|
LL | impl A usize {}
| ^^^^^^ help: add `for` here
error: `impl Trait for .. {}` is an obsolete syntax
--> $DIR/issue-27255.rs:3:1
|
LL | impl A .. {}
| ^^^^^^^^^^^^
|
= help: use `auto trait Trait {}` instead
error: aborting due to 3 previous errors

View file

@ -2,7 +2,7 @@ error: type parameters must be declared prior to associated type bindings
--> $DIR/issue-32214.rs:5:34
|
LL | pub fn test<W, I: Trait<Item=(), W> >() {}
| ^
| ^ must be declared prior to associated type bindings
error: aborting due to previous error

View file

@ -110,7 +110,7 @@ error: octal float literal is not supported
--> $DIR/lex-bad-numeric-literals.rs:5:5
|
LL | 0o2f32; //~ ERROR: octal float literal is not supported
| ^^^^^^
| ^^^^^^ not supported
error: int literal is too large
--> $DIR/lex-bad-numeric-literals.rs:16:5
@ -128,13 +128,13 @@ error: octal float literal is not supported
--> $DIR/lex-bad-numeric-literals.rs:23:5
|
LL | 0o123f64; //~ ERROR: octal float literal is not supported
| ^^^^^^^^
| ^^^^^^^^ not supported
error: binary float literal is not supported
--> $DIR/lex-bad-numeric-literals.rs:25:5
|
LL | 0b101f64; //~ ERROR: binary float literal is not supported
| ^^^^^^^^
| ^^^^^^^^ not supported
error: aborting due to 23 previous errors

View file

@ -1,7 +1,8 @@
// error-pattern:binary float literal is not supported
fn main() {
0b101010f64;
//~^ ERROR binary float literal is not supported
0b101.010;
//~^ ERROR binary float literal is not supported
0b101p4f64;
//~^ ERROR invalid suffix `p4f64` for numeric literal
}

View file

@ -1,8 +1,22 @@
error: binary float literal is not supported
--> $DIR/no-binary-float-literal.rs:5:5
--> $DIR/no-binary-float-literal.rs:4:5
|
LL | 0b101.010;
| ^^^^^^^^^
error: aborting due to previous error
error: binary float literal is not supported
--> $DIR/no-binary-float-literal.rs:2:5
|
LL | 0b101010f64;
| ^^^^^^^^^^^ not supported
error: invalid suffix `p4f64` for numeric literal
--> $DIR/no-binary-float-literal.rs:6:5
|
LL | 0b101p4f64;
| ^^^^^^^^^^ invalid suffix `p4f64`
|
= help: the suffix must be one of the integral types (`u32`, `isize`, etc)
error: aborting due to 3 previous errors

View file

@ -1,7 +1,9 @@
// error-pattern:hexadecimal float literal is not supported
fn main() {
0xABC.Df;
//~^ ERROR `{integer}` is a primitive type and therefore doesn't have fields
0x567.89;
//~^ ERROR hexadecimal float literal is not supported
0xDEAD.BEEFp-2f;
//~^ ERROR invalid suffix `f` for float literal
//~| ERROR `{integer}` is a primitive type and therefore doesn't have fields
}

View file

@ -1,8 +1,29 @@
error: hexadecimal float literal is not supported
--> $DIR/no-hex-float-literal.rs:5:5
--> $DIR/no-hex-float-literal.rs:4:5
|
LL | 0x567.89;
| ^^^^^^^^
error: aborting due to previous error
error: invalid suffix `f` for float literal
--> $DIR/no-hex-float-literal.rs:6:18
|
LL | 0xDEAD.BEEFp-2f;
| ^^ invalid suffix `f`
|
= help: valid suffixes are `f32` and `f64`
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
--> $DIR/no-hex-float-literal.rs:2:11
|
LL | 0xABC.Df;
| ^^
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
--> $DIR/no-hex-float-literal.rs:6:12
|
LL | 0xDEAD.BEEFp-2f;
| ^^^^^
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0610`.

View file

@ -2,37 +2,37 @@ error: cannot pass `self` by raw pointer
--> $DIR/no-unsafe-self.rs:4:17
|
LL | fn foo(*mut self); //~ ERROR cannot pass `self` by raw pointer
| ^^^^
| ^^^^ cannot pass `self` by raw pointer
error: cannot pass `self` by raw pointer
--> $DIR/no-unsafe-self.rs:5:19
|
LL | fn baz(*const self); //~ ERROR cannot pass `self` by raw pointer
| ^^^^
| ^^^^ cannot pass `self` by raw pointer
error: cannot pass `self` by raw pointer
--> $DIR/no-unsafe-self.rs:6:13
|
LL | fn bar(*self); //~ ERROR cannot pass `self` by raw pointer
| ^^^^
| ^^^^ cannot pass `self` by raw pointer
error: cannot pass `self` by raw pointer
--> $DIR/no-unsafe-self.rs:11:17
|
LL | fn foo(*mut self) { } //~ ERROR cannot pass `self` by raw pointer
| ^^^^
| ^^^^ cannot pass `self` by raw pointer
error: cannot pass `self` by raw pointer
--> $DIR/no-unsafe-self.rs:12:19
|
LL | fn baz(*const self) { } //~ ERROR cannot pass `self` by raw pointer
| ^^^^
| ^^^^ cannot pass `self` by raw pointer
error: cannot pass `self` by raw pointer
--> $DIR/no-unsafe-self.rs:13:13
|
LL | fn bar(*self) { } //~ ERROR cannot pass `self` by raw pointer
| ^^^^
| ^^^^ cannot pass `self` by raw pointer
error: aborting due to 6 previous errors

View file

@ -1,5 +1,6 @@
fn main() {
match 0 {
(pat, ..,) => {} //~ ERROR trailing comma is not permitted after `..`
match (0, 1, 2) {
(pat, ..,) => {}
//~^ ERROR trailing comma is not permitted after `..`
}
}

View file

@ -1,8 +1,8 @@
error: trailing comma is not permitted after `..`
--> $DIR/pat-tuple-2.rs:3:17
|
LL | (pat, ..,) => {} //~ ERROR trailing comma is not permitted after `..`
| ^
LL | (pat, ..,) => {}
| ^ trailing comma is not permitted after `..`
error: aborting due to previous error

View file

@ -1,5 +1,6 @@
fn main() {
match 0 {
(.., pat, ..) => {} //~ ERROR `..` can only be used once per tuple or tuple struct pattern
match (0, 1, 2) {
(.., pat, ..) => {}
//~^ ERROR `..` can only be used once per tuple or tuple struct pattern
}
}

View file

@ -1,8 +1,8 @@
error: `..` can only be used once per tuple or tuple struct pattern
--> $DIR/pat-tuple-3.rs:3:19
|
LL | (.., pat, ..) => {} //~ ERROR `..` can only be used once per tuple or tuple struct pattern
| ^^
LL | (.., pat, ..) => {}
| ^^ can only be used once per pattern
error: aborting due to previous error

View file

@ -1,12 +1,11 @@
//error-pattern: discriminator values can only be used with a field-less enum
enum color {
red = 0xff0000,
green = 0x00ff00,
blue = 0x0000ff,
black = 0x000000,
white = 0xffffff,
other (str),
enum Color {
Red = 0xff0000,
//~^ ERROR discriminator values can only be used with a field-less enum
Green = 0x00ff00,
Blue = 0x0000ff,
Black = 0x000000,
White = 0xffffff,
Other(usize),
}
fn main() {}

View file

@ -1,8 +1,17 @@
error: discriminator values can only be used with a field-less enum
--> $DIR/tag-variant-disr-non-nullary.rs:8:13
--> $DIR/tag-variant-disr-non-nullary.rs:2:11
|
LL | white = 0xffffff,
| ^^^^^^^^
LL | Red = 0xff0000,
| ^^^^^^^^ only valid in field-less enums
LL | //~^ ERROR discriminator values can only be used with a field-less enum
LL | Green = 0x00ff00,
| ^^^^^^^^ only valid in field-less enums
LL | Blue = 0x0000ff,
| ^^^^^^^^ only valid in field-less enums
LL | Black = 0x000000,
| ^^^^^^^^ only valid in field-less enums
LL | White = 0xffffff,
| ^^^^^^^^ only valid in field-less enums
error: aborting due to previous error

View file

@ -1,4 +1,5 @@
fn foo<T>() where <T>::Item: ToString, T: Iterator { }
//~^ ERROR generic parameters on `where` clauses are reserved for future use
//~| ERROR cannot find type `Item` in the crate root
fn main() {}

View file

@ -2,7 +2,14 @@ error: generic parameters on `where` clauses are reserved for future use
--> $DIR/where_with_bound.rs:1:19
|
LL | fn foo<T>() where <T>::Item: ToString, T: Iterator { }
| ^^^
| ^^^ currently unsupported
error: aborting due to previous error
error[E0412]: cannot find type `Item` in the crate root
--> $DIR/where_with_bound.rs:1:24
|
LL | fn foo<T>() where <T>::Item: ToString, T: Iterator { }
| ^^^^ not found in the crate root
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0412`.

View file

@ -1,8 +1,6 @@
// A few contrived examples where lifetime should (or should not) be parsed as an object type.
// Lifetimes parsed as types are still rejected later by semantic checks.
// compile-flags: -Z continue-parse-after-error
struct S<'a, T>(&'a u8, T);
fn main() {

View file

@ -1,29 +1,33 @@
error: lifetime parameters must be declared prior to type parameters
--> $DIR/trait-object-vs-lifetime.rs:16:25
--> $DIR/trait-object-vs-lifetime.rs:14:25
|
LL | let _: S<'static +, 'static>;
| ^^^^^^^
| ^^^^^^^ must be declared prior to type parameters
help: move the lifetime parameter prior to the first type parameter
|
LL | let _: S<'static, 'static +>;
| ^^^^^^^^ --
error[E0224]: at least one non-builtin trait is required for an object type
--> $DIR/trait-object-vs-lifetime.rs:11:23
--> $DIR/trait-object-vs-lifetime.rs:9:23
|
LL | let _: S<'static, 'static +>;
| ^^^^^^^^^
error[E0107]: wrong number of lifetime arguments: expected 1, found 2
--> $DIR/trait-object-vs-lifetime.rs:13:23
--> $DIR/trait-object-vs-lifetime.rs:11:23
|
LL | let _: S<'static, 'static>;
| ^^^^^^^ unexpected lifetime argument
error[E0107]: wrong number of type arguments: expected 1, found 0
--> $DIR/trait-object-vs-lifetime.rs:13:12
--> $DIR/trait-object-vs-lifetime.rs:11:12
|
LL | let _: S<'static, 'static>;
| ^^^^^^^^^^^^^^^^^^^ expected 1 type argument
error[E0224]: at least one non-builtin trait is required for an object type
--> $DIR/trait-object-vs-lifetime.rs:16:14
--> $DIR/trait-object-vs-lifetime.rs:14:14
|
LL | let _: S<'static +, 'static>;
| ^^^^^^^^^