Skip to content

ICE when casting constant float to usize in Index position #54348

Closed
@oberien

Description

@oberien

Not that this should ever be done / occur in actual code, but here it is.

Code (playground):

fn main() {
    [1][1.5 as usize];
}

Error (formatted):

error: internal compiler error: librustc_mir/transform/const_prop.rs:619: const index not primitive: (
  ByRef(
    Ptr(
      Pointer {
        alloc_id: AllocId(0),
        offset: Size {
          raw: 0
        }
      }
    ),
    Align {
      abi_pow2: 3,
      pref_pow2: 3
    }
  ),
  TyLayout {
    ty: usize,
    details: LayoutDetails {
      variants: Single {
        index: 0
      },
      fields: Union(0),
      abi: Scalar(
        Scalar {
          value: Int(I64, false),
          valid_range: 0..=18446744073709551615
        }
      ),
      align: Align {
        abi_pow2: 3,
        pref_pow2: 3
      },
      size: Size {
        raw: 8
      }
    }
  }, src/main.rs:2:9: 2:12
)

Compiler version: rustc 1.29.0 (aa3ca19 2018-09-11) running on x86_64-unknown-linux-gnu
Compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions