Skip to content

False positive for cast_sign_loss #4743

Closed
@Luro02

Description

@Luro02

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingC-enhancementCategory: Enhancement of lints, like adding more cases or adding help messagesgood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions