Skip to content

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 6 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reword message for incorrect float literal
  • Loading branch information
estebank committed Jan 20, 2019
commit e387597a8f789ab6e37e6ce1bf67c8c45d4827c3
4 changes: 2 additions & 2 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2002,10 +2002,10 @@ impl<'a> Parser<'a> {
self.bump();
let sp = lo.to(self.prev_span);
let mut err = self.diagnostic()
.struct_span_err(sp, "numeric float literals must have a significant");
.struct_span_err(sp, "float literals must have an integer part");
err.span_suggestion_with_applicability(
sp,
"numeric float literals must have a significant",
"must have an integer part",
format!("0.{}", val),
Applicability::MachineApplicable,
);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-52496.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ struct Foo { bar: f64, baz: i64, bat: i64 }

fn main() {
let _ = Foo { bar: .5, baz: 42 };
//~^ ERROR numeric float literals must have a significant
//~^ ERROR float literals must have an integer part
//~| ERROR missing field `bat` in initializer of `Foo`
//~| ERROR mismatched types
let bar = 1.5f32;
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-52496.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: numeric float literals must have a significant
error: float literals must have an integer part
--> $DIR/issue-52496.rs:4:24
|
LL | let _ = Foo { bar: .5, baz: 42 };
| ^^ help: numeric float literals must have a significant: `0.5`
| ^^ help: must have an integer part: `0.5`

error: expected one of `,` or `}`, found `.`
--> $DIR/issue-52496.rs:9:22
Expand Down