-
Notifications
You must be signed in to change notification settings - Fork 13.4k
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 5 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,12 @@ | ||
struct Foo { bar: f64, baz: i64, bat: i64 } | ||
|
||
fn main() { | ||
let _ = Foo { bar: .5, baz: 42 }; | ||
//~^ ERROR float literals must have an integer part | ||
//~| ERROR missing field `bat` in initializer of `Foo` | ||
let bar = 1.5f32; | ||
let _ = Foo { bar.into(), bat: -1, . }; | ||
//~^ ERROR expected one of | ||
//~| ERROR missing fields `bar`, `baz` in initializer of `Foo` | ||
//~| 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,37 @@ | ||
error: float literals must have an integer part | ||
--> $DIR/issue-52496.rs:4:24 | ||
| | ||
LL | let _ = Foo { bar: .5, baz: 42 }; | ||
| ^^ help: must have an integer part: `0.5` | ||
|
||
error: expected one of `,` or `}`, found `.` | ||
--> $DIR/issue-52496.rs:8: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:8:40 | ||
| | ||
LL | let _ = Foo { bar.into(), bat: -1, . }; | ||
| --- ^ expected identifier | ||
| | | ||
| while parsing this struct | ||
|
||
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[E0063]: missing fields `bar`, `baz` in initializer of `Foo` | ||
--> $DIR/issue-52496.rs:8:13 | ||
| | ||
LL | let _ = Foo { bar.into(), bat: -1, . }; | ||
| ^^^ missing `bar`, `baz` | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this 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
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`. |
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,11 @@ | ||
fn main() { | ||
let _: usize = .3; | ||
//~^ ERROR float literals must have an integer part | ||
//~| ERROR mismatched types | ||
let _: usize = .42f32; | ||
//~^ ERROR float literals must have an integer part | ||
//~| ERROR mismatched types | ||
let _: usize = .5f64; | ||
//~^ ERROR float literals must have an integer part | ||
//~| ERROR mismatched types | ||
} |
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,42 @@ | ||
error: float literals must have an integer part | ||
--> $DIR/recover-invalid-float.rs:2:20 | ||
| | ||
LL | let _: usize = .3; | ||
| ^^ help: must have an integer part: `0.3` | ||
|
||
error: float literals must have an integer part | ||
--> $DIR/recover-invalid-float.rs:5:20 | ||
| | ||
LL | let _: usize = .42f32; | ||
| ^^^^^^ help: must have an integer part: `0.42f32` | ||
|
||
error: float literals must have an integer part | ||
--> $DIR/recover-invalid-float.rs:8:20 | ||
| | ||
LL | let _: usize = .5f64; | ||
| ^^^^^ help: must have an integer part: `0.5f64` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/recover-invalid-float.rs:2:20 | ||
| | ||
LL | let _: usize = .3; | ||
| ^^ expected usize, found floating-point number | ||
| | ||
= note: expected type `usize` | ||
found type `{float}` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/recover-invalid-float.rs:5:20 | ||
| | ||
LL | let _: usize = .42f32; | ||
| ^^^^^^ expected usize, found f32 | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/recover-invalid-float.rs:8:20 | ||
| | ||
LL | let _: usize = .5f64; | ||
| ^^^^^ expected usize, found f64 | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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.