Skip to content

warn on casting enum to numeric value #542

@durka

Description

@durka

This code

#![warn(clippy)]
#![warn(clippy_pedantic)]

fn it_works() {
    enum Foo { Bar = 300 }

    let x = 300i32 as u8;
    let y = Foo::Bar as u8;
}

hits a warning on x but not on y, even though both are truncated. Probably one of the cast_* lints should trigger whenever a repr(rust) enum is as-casted (or if e.g. a repr(i32) is casted to a u8), optionally checking to see if the enum actually has numeric variants that would cause problems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.T-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions