-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #69180 - Aaron1011:feature/comma-struct-init, r=petro…
…chenkov Suggest a comma if a struct initializer field fails to parse Currently, we emit a "try adding a comma" suggestion if a comma is missing in a struct definition. However, we emit no such suggestion if a comma is missing in a struct initializer. This commit adds a "try adding a comma" suggestion when we don't find a comma during the parsing of a struct initializer field. The change to `src/test/ui/parser/removed-syntax-with-1.stderr` isn't great, but I don't see a good way of avoiding it.
- Loading branch information
Showing
4 changed files
with
46 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
struct Foo { | ||
first: bool, | ||
second: u8, | ||
} | ||
|
||
fn main() { | ||
let a = Foo { | ||
//~^ ERROR missing field | ||
first: true | ||
second: 25 | ||
//~^ ERROR expected one of | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
error: expected one of `,`, `.`, `?`, `}`, or an operator, found `second` | ||
--> $DIR/struct-initializer-comma.rs:10:9 | ||
| | ||
LL | let a = Foo { | ||
| --- while parsing this struct | ||
LL | | ||
LL | first: true | ||
| - | ||
| | | ||
| expected one of `,`, `.`, `?`, `}`, or an operator | ||
| help: try adding a comma: `,` | ||
LL | second: 25 | ||
| ^^^^^^ unexpected token | ||
|
||
error[E0063]: missing field `second` in initializer of `Foo` | ||
--> $DIR/struct-initializer-comma.rs:7:13 | ||
| | ||
LL | let a = Foo { | ||
| ^^^ missing `second` | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0063`. |