Skip to content
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

Extend invalid floating point literal suffix suggestion #100527

Closed
Rageking8 opened this issue Aug 14, 2022 · 3 comments · Fixed by #100609
Closed

Extend invalid floating point literal suffix suggestion #100527

Rageking8 opened this issue Aug 14, 2022 · 3 comments · Fixed by #100609
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Rageking8
Copy link
Contributor

Rageking8 commented Aug 14, 2022

Given the following code: link

fn main() {
    let a = 12.f;
    let b = 34.F;
    let c = 56.l;
    let d = 78.L;
}

The current output is:

Compiling playground v0.0.1 (/playground)
error[[E0610]](https://doc.rust-lang.org/nightly/error-index.html#E0610): `{integer}` is a primitive type and therefore doesn't have fields
 --> src/main.rs:2:16
  |
2 |     let a = 12.f;
  |                ^

error[[E0610]](https://doc.rust-lang.org/nightly/error-index.html#E0610): `{integer}` is a primitive type and therefore doesn't have fields
 --> src/main.rs:3:16
  |
3 |     let b = 34.F;
  |                ^

error[[E0610]](https://doc.rust-lang.org/nightly/error-index.html#E0610): `{integer}` is a primitive type and therefore doesn't have fields
 --> src/main.rs:4:16
  |
4 |     let c = 56.l;
  |                ^

error[[E0610]](https://doc.rust-lang.org/nightly/error-index.html#E0610): `{integer}` is a primitive type and therefore doesn't have fields
 --> src/main.rs:5:16
  |
5 |     let d = 78.L;
  |                ^

For more information about this error, try `rustc --explain E0610`.
error: could not compile `playground` due to 4 previous errors

Ideally for all the above invalid ways to writing a floating point literal, the complier should highlight that there are only 2 valid floating point literal suffix "f32" and "f64". Additionally, it may also include a note informing the user that a trailing '0' must be present in floating point literals.

@Rageking8 Rageking8 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 14, 2022
@chenyukang
Copy link
Member

why would

 let c = 56.l;
 let d = 78.L;

suggest to write float?

I think l or L maybe means to write integer.

@Rageking8
Copy link
Contributor Author

@chenyukang It's because that's the "long double" floating point literal suffix for C++.

@chenyukang
Copy link
Member

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants