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

Suggest a float literal when dividing a floating-point type by {integer} #93829

Closed
scottmcm opened this issue Feb 9, 2022 · 1 comment · Fixed by #94078
Closed

Suggest a float literal when dividing a floating-point type by {integer} #93829

scottmcm opened this issue Feb 9, 2022 · 1 comment · Fixed by #94078
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

@scottmcm
Copy link
Member

scottmcm commented Feb 9, 2022

(This example is from https://users.rust-lang.org/t/beginner-question-make-a-function-that-divides-a-number-by-100/71577?u=scottmcm )

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=94518a0a52515b56b171089af22d07d9

fn divide_by_one_hundred(x: f32) -> f32 {
    x / 100
}

The current output is:

error[[E0277]](https://doc.rust-lang.org/nightly/error-index.html#E0277): cannot divide `f32` by `{integer}`
 [--> src/lib.rs:2:7
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
2 |     x / 100
  |       ^ no implementation for `f32 / {integer}`
  |
  = help: the trait `Div<{integer}>` is not implemented for `f32`

Ideally the output should have a suggested fix, perhaps something like

error[[E0277]](https://doc.rust-lang.org/nightly/error-index.html#E0277): cannot divide `f32` by `{integer}`
 [--> src/lib.rs:2:7
](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#)  |
2 |     x / 100
  |       ^ no implementation for `f32 / {integer}`
  |
  = help: the trait `Div<{integer}>` is not implemented for `f32`
  = suggestion: use a floating-point literal instead
2 |     x / 100.0
            ^^^^^
@scottmcm scottmcm 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 Feb 9, 2022
@HarrisonHemstreet
Copy link

Thank you!🥳

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 25, 2022
…loat-divided-by-integer, r=estebank

Suggest a float literal when dividing a floating-point type by `{integer}`

closes rust-lang#93829
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Feb 26, 2022
…loat-divided-by-integer, r=estebank

Suggest a float literal when dividing a floating-point type by `{integer}`

closes rust-lang#93829
@bors bors closed this as completed in 8c9640e Feb 26, 2022
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.

3 participants