Skip to content

"as uint" works on bare constructors of non-C-like enums #18154

Closed
@kmcallister

Description

@kmcallister

rustc 0.13.0-dev (222ae8b 2014-10-18 00:47:22 +0000)

enum Tag {
    Dynamic,
    Inline(u8),
    Static,
}

#[test]
fn f() {
    assert_eq!(Inline as uint, 1);
}

compiles and produces

task 'f' failed at 'assertion failed: `(left == right) && (right == left)` (left: `140041300628448`, right: `1`)', foo.rs:9

I think it's casting the constructor function itself as a function pointer? But this is super confusing behavior (caused a segfault in unsafe code) when I just refactored an enum to be not C-like and I want to get rid of remaining occurrences of as uint.

Also it doesn't warn for as u8, even though it's too small for a function pointer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.P-lowLow priorityT-compilerRelevant to the compiler 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