Skip to content

ICE when doing some casts on constant expressions #9867

@LeoTestard

Description

@LeoTestard

The following code does not compile :

extern
{
    fn foo();
}

static a: u64 = foo as u64;

fn main()
{
    println!("{:u}", a};
}

It fails with the following message :

test.rs:6:18: 6:28 error: internal compiler error: Impossible case reached: bad combination of types for cast
test.rs:6 static baz: u64 = foo as u64;

Where as the following code, that does the same type of cast but in a non-constant expression, is valid :

extern
{
    fn foo();
}

fn main()
{
    let a: u64 = foo as u64;
    println!("{:u}", a};
}

Maybe I'm missing some point, but I don't see any good reason to disallow this type of casts at compile-time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationI-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