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

False positive in cast_sign_loss #2728

Closed
dtolnay opened this issue May 4, 2018 · 0 comments
Closed

False positive in cast_sign_loss #2728

dtolnay opened this issue May 4, 2018 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@dtolnay
Copy link
Member

dtolnay commented May 4, 2018

I have some code like this in serde_yaml:

error: casting i64 to u64 may lose the sign of the value
   --> src/number.rs:172:37
    |
172 |                             if n <= i64::max_value() as u64 {
    |                                     ^^^^^^^^^^^^^^^^^^^^^^^

It would be nice to suppress cast_sign_loss in cases where Clippy can determine that the value is nonnegative, for example i64::MAX and i64::max_value().

@phansch phansch added the C-bug Category: Clippy is not doing the correct thing label May 9, 2018
bors added a commit that referenced this issue Feb 4, 2019
Fix `cast_sign_loss` false positive

This checks if the value is a non-negative constant before linting about
losing the sign.

Because the `constant` function doesn't handle const functions, we check if
the value is from a call to a `max_value` function directly. A utility method
called `get_def_path` was added to make checking for the function paths
easier.

Fixes #2728
@bors bors closed this as completed in #3725 Feb 4, 2019
g-bartoszek pushed a commit to g-bartoszek/rust-clippy that referenced this issue Feb 7, 2019
This checks if the value is a non-negative constant before linting about
losing the sign.

Because the `constant` function doesn't handle const functions, we check if
the value is from a call to a `max_value` function directly. A utility method
called `get_def_path` was added to make checking for the function paths
easier.

Fixes rust-lang#2728
@rustbot rustbot added the I-false-positive Issue: The lint was triggered on code it shouldn't have label Sep 13, 2021
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 I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

3 participants