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

BUG: Incorrect mistyped literal suffix on long floats. #4706

Closed
Michael-J-Ward opened this issue Oct 20, 2019 · 5 comments · Fixed by #6114
Closed

BUG: Incorrect mistyped literal suffix on long floats. #4706

Michael-J-Ward opened this issue Oct 20, 2019 · 5 comments · Fixed by #6114
Labels
C-bug Category: Clippy is not doing the correct thing

Comments

@Michael-J-Ward
Copy link

I have a long literal float, which clippy warns that it lacks literal separators:

warning: long literal lacking separators
  --> src/lib.rs:58:35
   |
58 |     const EARTH_YEAR_RATIO: f64 = 164.79132032;
   |                                   ^^^^^^^^^^^^ help: consider: `164.791_320_32`
   |
   = note: `#[warn(clippy::unreadable_literal)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal

But after fixing it, clippy gives an error saying mistyped literal suffix

error: mistyped literal suffix
  --> src/lib.rs:58:35
   |
58 |     const EARTH_YEAR_RATIO: f64 = 164.791_320_32;
   |                                   ^^^^^^^^^^^^^^ help: did you mean to write: `164.791_320_f32`
   |
   = note: `#[deny(clippy::mistyped_literal_suffixes)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mistyped_literal_suffixes

Related to: #3091

$ cargo clippy -V
clippy 0.0.212 (3aea860 2019-09-03)
@hellow554
Copy link
Contributor

Reduced:

const A: f64 = 0.0_32;

this is because of

fn is_mistyped_suffix(suffix: &str) -> bool {
["_8", "_16", "_32", "_64"].contains(&suffix)
}

@flip1995 flip1995 added the C-bug Category: Clippy is not doing the correct thing label Oct 21, 2019
@ghost
Copy link

ghost commented Oct 22, 2019

I think we shouldn't check for possibly mistyped suffixes in the digits in the fractional part of a literal.

@ghost
Copy link

ghost commented Oct 23, 2019

I have some ideas on simplifying the mistyped literal code. If it works out, I'll fix this next.

@rustbot claim

@flip1995 flip1995 assigned ghost Oct 23, 2019
@Michael-J-Ward
Copy link
Author

Just a thought as the user- the thing that surprised me was the cycle: i.e. one fix suggestion triggered another error. Is it feasible / desirable to catch this by running the suggested fix itself back through clippy?

@flip1995
Copy link
Member

flip1995 commented Oct 24, 2019

We do this, if applicable. No idea, why we don't do this here.

Probably it's just that we forgot to add a test case for this.

bors added a commit that referenced this issue Oct 5, 2020
Do not lint float fractions in `mistyped_literal_suffixes`

As suggested in #4706 (comment), the fractional part is now ignored (the integer part is checked instead).

Fixes: #4706

changelog: `mistyped_literal_suffixes` no longer warns on the fractional part of a float (e.g. 713.23_64)
bors added a commit that referenced this issue Oct 5, 2020
Do not lint float fractions in `mistyped_literal_suffixes`

As suggested in #4706 (comment), the fractional part is now ignored (the integer part is checked instead).

Fixes: #4706

changelog: `mistyped_literal_suffixes` no longer warns on the fractional part of a float (e.g. 713.23_64)
@bors bors closed this as completed in 78695bd Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants