Rollup merge of #88729 - estebank:struct-literal-using-parens, r=oli-obk
Recover from `Foo(a: 1, b: 2)` Detect likely `struct` literal using parentheses as delimiters and emit targeted suggestion instead of type ascription parse error. Fix #61326.
This commit is contained in:
commit
2c7d48b900
7 changed files with 133 additions and 34 deletions
|
|
@ -6,5 +6,5 @@ enum Test {
|
|||
|
||||
fn main() {
|
||||
Test::Drill(field: 42);
|
||||
//~^ ERROR expected type, found
|
||||
//~^ ERROR invalid `struct` delimiters or `fn` call arguments
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
error: expected type, found `42`
|
||||
--> $DIR/issue-34255-1.rs:8:24
|
||||
error: invalid `struct` delimiters or `fn` call arguments
|
||||
--> $DIR/issue-34255-1.rs:8:5
|
||||
|
|
||||
LL | Test::Drill(field: 42);
|
||||
| - ^^ expected type
|
||||
| |
|
||||
| tried to parse a type due to this type ascription
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
|
||||
= note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information
|
||||
help: if `Test::Drill` is a struct, use braces as delimiters
|
||||
|
|
||||
LL | Test::Drill { field: 42 };
|
||||
| ~ ~
|
||||
help: if `Test::Drill` is a function, use the arguments directly
|
||||
|
|
||||
LL - Test::Drill(field: 42);
|
||||
LL + Test::Drill(42);
|
||||
|
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
macro_rules! foo {
|
||||
($rest: tt) => {
|
||||
bar(baz: $rest)
|
||||
bar(baz: $rest) //~ ERROR invalid `struct` delimiters or `fn` call arguments
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo!(true); //~ ERROR expected type, found keyword
|
||||
foo!(true);
|
||||
//~^ ERROR expected identifier, found keyword
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,17 +9,25 @@ help: you can escape reserved keywords to use them as identifiers
|
|||
LL | foo!(r#true);
|
||||
| ~~~~~~
|
||||
|
||||
error: expected type, found keyword `true`
|
||||
--> $DIR/issue-44406.rs:8:10
|
||||
error: invalid `struct` delimiters or `fn` call arguments
|
||||
--> $DIR/issue-44406.rs:3:9
|
||||
|
|
||||
LL | bar(baz: $rest)
|
||||
| - help: try using a semicolon: `;`
|
||||
| ^^^^^^^^^^^^^^^
|
||||
...
|
||||
LL | foo!(true);
|
||||
| ^^^^ expected type
|
||||
| ----------- in this macro invocation
|
||||
|
|
||||
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
|
||||
= note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information
|
||||
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: if `bar` is a struct, use braces as delimiters
|
||||
|
|
||||
LL | bar { }
|
||||
| ~
|
||||
help: if `bar` is a function, use the arguments directly
|
||||
|
|
||||
LL - bar(baz: $rest)
|
||||
LL + bar(true);
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ enum Enum {
|
|||
|
||||
fn main() {
|
||||
let x = Enum::Foo(a: 3, b: 4);
|
||||
//~^ ERROR expected type, found `3`
|
||||
//~^ ERROR invalid `struct` delimiters or `fn` call arguments
|
||||
match x {
|
||||
Enum::Foo(a, b) => {}
|
||||
//~^ ERROR expected tuple struct or tuple variant, found struct variant `Enum::Foo`
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
error: expected type, found `3`
|
||||
--> $DIR/recover-from-bad-variant.rs:7:26
|
||||
error: invalid `struct` delimiters or `fn` call arguments
|
||||
--> $DIR/recover-from-bad-variant.rs:7:13
|
||||
|
|
||||
LL | let x = Enum::Foo(a: 3, b: 4);
|
||||
| - ^ expected type
|
||||
| |
|
||||
| tried to parse a type due to this type ascription
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
|
||||
= note: see issue #23416 <https://github.com/rust-lang/rust/issues/23416> for more information
|
||||
help: if `Enum::Foo` is a struct, use braces as delimiters
|
||||
|
|
||||
LL | let x = Enum::Foo { a: 3, b: 4 };
|
||||
| ~ ~
|
||||
help: if `Enum::Foo` is a function, use the arguments directly
|
||||
|
|
||||
LL - let x = Enum::Foo(a: 3, b: 4);
|
||||
LL + let x = Enum::Foo(3, 4);
|
||||
|
|
||||
|
||||
error[E0532]: expected tuple struct or tuple variant, found struct variant `Enum::Foo`
|
||||
--> $DIR/recover-from-bad-variant.rs:10:9
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue