Skip to content

LLVM Error: broken function found #71659

Closed
@RustyYato

Description

@RustyYato

Code

playground

#![feature(unsize)]

use core::marker::Unsize;

pub trait CastTo<T: ?Sized>: Unsize<T> {
    fn cast_to(&self) -> &T;
}

impl<T: ?Sized, U: ?Sized + Unsize<T>> CastTo<T> for U {
    fn cast_to(&self) -> &T {
        self
    }
}

impl<T: ?Sized> Cast for T {}
pub trait Cast {
    fn cast<T: ?Sized>(&self) -> &T
    where
        Self: CastTo<T>,
    {
        self
    }
}

pub trait Foo: CastTo<[i32]> {}
impl Foo for [i32; 0] {}

fn main() {
    let x: &dyn Foo = &[];
    let x = x.cast::<[i32]>();
}

Meta

rustc --version --verbose:

rustc 1.44.0-nightly (7f3df5772 2020-04-16)
binary: rustc
commit-hash: 7f3df5772439eee1c512ed2eb540beef1124d236
commit-date: 2020-04-16
host: x86_64-pc-windows-msvc
release: 1.44.0-nightly
LLVM version: 9.0

Error output

   Compiling trait-cast v0.1.0 (E:\Programming\Rust\trait-cast)
warning: unused variable: `x`
  --> src\main.rs:30:9
   |
30 |     let x = x.cast::<[i32]>();
   |         ^ help: if this is intentional, prefix it with an underscore: `_x`
   |
   = note: `#[warn(unused_variables)]` on by default

Invalid InsertValueInst operands!
  %8 = insertvalue { [0 x i32]*, i64 } %7, [3 x i64]* %1, 1, !dbg !59
in function _ZN10trait_cast4Cast4cast17hfff2a44740d96fd4E
LLVM ERROR: Broken function found, compilation aborted!
error: could not compile `trait-cast`.

To learn more, run the command again with --verbose.

Backtrace

N/a there was no backtrace

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions