Skip to content

invalid_value misses some clearly bad enum initialization #102043

Closed
@RalfJung

Description

@RalfJung
Member

The invalid_value lint has no issue with the following type being zero-initialized or left uninit:

enum OneFruitNonzero {
    Apple(!),
    Banana(NonZeroU32),
}

That seems like a case we should be able to handle.

I think for non-is_multi_variant enums, we probably can compute the variant that does exist, and then we can recursively check if that one is valid? We'd also need a smarter is_multi_variant that can handle some dataful variants (ensuring they are definitely inhabited).

Cc @5225225

Activity

RalfJung

RalfJung commented on Sep 25, 2022

@RalfJung
MemberAuthor

Will be fixed by #102281

Rageking8

Rageking8 commented on Sep 26, 2022

@Rageking8
Contributor

@rustbot label +C-bug +A-lint

added
A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.
C-bugCategory: This is a bug.
on Sep 26, 2022
added a commit that references this issue on Sep 27, 2022

Rollup merge of rust-lang#102281 - RalfJung:invalid-enums, r=cjgillot

8d2faa2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @RalfJung@rustbot@Rageking8

      Issue actions

        invalid_value misses some clearly bad enum initialization · Issue #102043 · rust-lang/rust