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 for cast_sign_loss #4743

Closed
Luro02 opened this issue Oct 27, 2019 · 2 comments
Closed

False positive for cast_sign_loss #4743

Luro02 opened this issue Oct 27, 2019 · 2 comments
Labels
C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@Luro02
Copy link

Luro02 commented Oct 27, 2019

cargo clippy -V

clippy 0.0.212 (52cebb1 2019-10-15)

Example code

#![warn(clippy::cast_sign_loss)]

fn main() {
    let value = i64::min_value().checked_abs().unwrap_or(0) as u64;
    
    assert_eq!(value, 0);
}

Playground

Problem

Clippy does warn, that the sign could be lost implicitly, even though it is done explicitly with checked_abs, which either returns Some(positive i64) or None.

Expected behavior

Clippy should ignore this case.

@flip1995
Copy link
Member

Easy extension of #4614

@flip1995 flip1995 added good-first-issue These issues are a good way to get started with Clippy C-bug Category: Clippy is not doing the correct thing C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages labels Oct 27, 2019
flip1995 added a commit to flip1995/rust-clippy that referenced this issue Nov 23, 2019
Allow casts from the result of `checked_abs` to unsigned

Fixes rust-lang#4743.
bors added a commit that referenced this issue Dec 12, 2019
…lse-positive, r=flip1995

Fix false positive with cast_sign_loss lint

`cast_sign_loss` lint incorrectly suggests that the result of `checked_abs`, `rem_euclid` and `checked_rem_euclid` cannot be casted to an unsigned integer without loss.

Fixes #4818 #4764 #4743

changelog: Fix false positives in `cast_sign_loss` lint
@phansch
Copy link
Member

phansch commented Dec 12, 2019

This should be fixed with #4883

@phansch phansch closed this as completed Dec 12, 2019
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 C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants