Skip to content

Discriminant enum 'as f64' passes Sema then fails MIR validation ('unsupported cast in MIR'); spec names only integer targets #1502

Closed

Description

@ehartford

Summary

A discriminant enum cast to a float type passes the checker and then fails the typed MIR validator: error: invalid MIR before codegen: unsupported cast in MIR. Either the checker rejects the cast with a user diagnostic, or it lowers; an internal MIR error on a program the checker accepted is neither.

Repro (installed nightly v0.15.2.1; origin/main stage1)

enum Kind: u8:
    Red = 1
    Hi = 200

fn main:
    let f = Kind.Hi as f64
    print(f)
error: invalid MIR before codegen: unsupported cast in MIR
 --> cast_f64.w:6:13

Spec

§4.4a: "Casting: value as i32 extracts the underlying integer (identity cast)." The spec names integer targets only; it does not say whether a float target is allowed (as the repr integer converted, 200.0) or rejected.

Found while fixing #1454 (unsigned-repr casts).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions