Skip to content

Can't as cast Void to usize  #75647

Closed
@digama0

Description

@digama0
enum Void { }
fn void_as_usize(x: Void) -> usize { x as usize } // fails, non-primitive cast

As reported on Zulip: https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/void.20as.20usize

This works for simple enums with one or more variants, but for zero it fails, possibly due to interaction with #[repr(C)]. This kind of code can come up in macro code.

cc @RalfJung

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions