-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Recover from parse errors in literal struct fields and incorrect float literals #57779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b1f169f
Recover from parse errors in struct literal fields
estebank acbda76
Recover with suggestion from writing `.42` instead of `0.42`
estebank e387597
Reword message for incorrect float literal
estebank 15bad8b
Extend incorrect float literal recovery to account for suffixes
estebank defa61f
Tweak field parse error recovery
estebank 4745b86
Accept more invalid code that is close to correct fields
estebank File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,14 @@ | ||
struct Foo { bar: f64, baz: i64, bat: i64 } | ||
|
||
fn main() { | ||
let _ = Foo { bar: .5, baz: 42 }; | ||
//~^ ERROR numeric float literals must have a significant | ||
estebank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//~| ERROR missing field `bat` in initializer of `Foo` | ||
//~| ERROR mismatched types | ||
let bar = 1.5f32; | ||
let _ = Foo { bar.into(), bat: -1, . }; | ||
//~^ ERROR expected one of | ||
//~| ERROR mismatched types | ||
//~| ERROR missing field `baz` in initializer of `Foo` | ||
estebank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//~| ERROR expected identifier, found `.` | ||
} |
This file contains hidden or 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,58 @@ | ||
error: numeric float literals must have a significant | ||
--> $DIR/issue-52496.rs:4:24 | ||
| | ||
LL | let _ = Foo { bar: .5, baz: 42 }; | ||
| ^^ help: numeric float literals must have a significant: `0.5` | ||
|
||
error: expected one of `,` or `}`, found `.` | ||
--> $DIR/issue-52496.rs:9:22 | ||
| | ||
LL | let _ = Foo { bar.into(), bat: -1, . }; | ||
| --- ^ expected one of `,` or `}` here | ||
| | | ||
| while parsing this struct | ||
|
||
error: expected identifier, found `.` | ||
--> $DIR/issue-52496.rs:9:40 | ||
| | ||
LL | let _ = Foo { bar.into(), bat: -1, . }; | ||
| --- ^ expected identifier | ||
| | | ||
| while parsing this struct | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-52496.rs:4:24 | ||
| | ||
LL | let _ = Foo { bar: .5, baz: 42 }; | ||
| ^^ expected f64, found f32 | ||
help: change the type of the numeric literal from `f32` to `f64` | ||
| | ||
LL | let _ = Foo { bar: .5f64, baz: 42 }; | ||
| ^^^^^ | ||
|
||
error[E0063]: missing field `bat` in initializer of `Foo` | ||
--> $DIR/issue-52496.rs:4:13 | ||
| | ||
LL | let _ = Foo { bar: .5, baz: 42 }; | ||
| ^^^ missing `bat` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-52496.rs:9:19 | ||
| | ||
LL | let _ = Foo { bar.into(), bat: -1, . }; | ||
| ^^^ expected f64, found f32 | ||
estebank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
help: you can cast an `f32` to `f64` in a lossless way | ||
| | ||
LL | let _ = Foo { bar.into().into(), bat: -1, . }; | ||
| ^^^^^^^^^^ | ||
|
||
error[E0063]: missing field `baz` in initializer of `Foo` | ||
--> $DIR/issue-52496.rs:9:13 | ||
| | ||
LL | let _ = Foo { bar.into(), bat: -1, . }; | ||
| ^^^ missing `baz` | ||
|
||
error: aborting due to 7 previous errors | ||
|
||
Some errors occurred: E0063, E0308. | ||
For more information about an error, try `rustc --explain E0063`. |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
struct Rgb(u8, u8, u8); | ||
|
||
fn main() { | ||
let _ = Rgb { 0, 1, 2 }; //~ ERROR expected identifier, found `0` | ||
//~| ERROR missing fields `0`, `1`, `2` in initializer of `Rgb` | ||
let _ = Rgb { 0, 1, 2 }; | ||
//~^ ERROR expected identifier, found `0` | ||
//~| ERROR expected identifier, found `1` | ||
//~| ERROR expected identifier, found `2` | ||
//~| ERROR missing fields `0`, `1`, `2` in initializer of `Rgb` | ||
} |
This file contains hidden or 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 |
---|---|---|
@@ -1,17 +1,33 @@ | ||
error: expected identifier, found `0` | ||
--> $DIR/struct-field-numeric-shorthand.rs:4:19 | ||
| | ||
LL | let _ = Rgb { 0, 1, 2 }; //~ ERROR expected identifier, found `0` | ||
LL | let _ = Rgb { 0, 1, 2 }; | ||
| --- ^ expected identifier | ||
| | | ||
| while parsing this struct | ||
|
||
error: expected identifier, found `1` | ||
--> $DIR/struct-field-numeric-shorthand.rs:4:22 | ||
| | ||
LL | let _ = Rgb { 0, 1, 2 }; | ||
| --- ^ expected identifier | ||
| | | ||
| while parsing this struct | ||
|
||
error: expected identifier, found `2` | ||
--> $DIR/struct-field-numeric-shorthand.rs:4:25 | ||
| | ||
LL | let _ = Rgb { 0, 1, 2 }; | ||
| --- ^ expected identifier | ||
| | | ||
| while parsing this struct | ||
|
||
error[E0063]: missing fields `0`, `1`, `2` in initializer of `Rgb` | ||
--> $DIR/struct-field-numeric-shorthand.rs:4:13 | ||
| | ||
LL | let _ = Rgb { 0, 1, 2 }; //~ ERROR expected identifier, found `0` | ||
LL | let _ = Rgb { 0, 1, 2 }; | ||
| ^^^ missing `0`, `1`, `2` | ||
|
||
error: aborting due to 2 previous errors | ||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0063`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.