rust-lang / rust-lang/rust

ICE with higher order associated types

Open
#129,372 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-associated-items A-GATs C-bug fixed-by-next-solver I-ICE S-bug-has-test T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
pub fn into_vec<'inner>(dummy: impl FromRow<'inner>) {
    let _f = dummy.prepare();
}

pub fn test() {
    into_vec(Assume(Some("test")));
}

pub trait FromRow<'t> {
    type Out<'a>;
    fn prepare(self) -> impl for<'a> FnMut(&'a ()) -> Self::Out<'a>;
}

impl<'t, T: Value<'t, Typ: MyTyp>> FromRow<'t> for T {
    type Out<'a> = <T::Typ as MyTyp>::Out<'a>;

    fn prepare(self) -> impl for<'a> FnMut(&'a ()) -> Self::Out<'a> {
        move |_| loop {}
    }
}

pub struct Assume<A>(pub(crate) A);

impl<'t, T, A: Value<'t, Typ = Option<T>>> Value<'t> for Assume<A> {
    type Typ = T;
}

pub trait Value<'t> {
    type Typ;
}

impl<'t> Value<'t> for &str {
    type Typ = String;
}

impl<'t, T: Value<'t, Typ = X>, X: MyTyp> Value<'t> for Option<T> {
    type Typ = Option<T::Typ>;
}

pub trait MyTyp: 'static {
    type Out<'t>;
}

impl MyTyp for String {
    type Out<'t> = Self;
}
Meta

rustc --version --verbose:

rustc 1.82.0-nightly (5aea14073 2024-08-20)
binary: rustc
commit-hash: 5aea14073eee9e403c3bb857490cd6aa4a395531
commit-date: 2024-08-20
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0
Error output
error: the compiler unexpectedly panicked. this is a bug.
Backtrace

thread 'rustc' panicked at compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs:52:9:
assertion `left == right` failed
  left: Closure(DefId(0:19 ~ rust_query[ff33]::{impl#0}::prepare::{closure#0}), ['{erased}, Assume<std::option::Option<&'{erased} str>>, i16, Binder { value: extern "RustCall" fn((&'^0 (),)) -> Alias(Projection, AliasTy { args: [std::string::String, '^0], def_id: DefId(0:37 ~ rust_query[ff33]::MyTyp::Out), .. }), bound_vars: [Region(BrAnon)] }, ()])
 right: Closure(DefId(0:19 ~ rust_query[ff33]::{impl#0}::prepare::{closure#0}), ['{erased}, Assume<std::option::Option<&'{erased} str>>, i16, Binder { value: extern "RustCall" fn((&'^0 (),)) -> std::string::String, bound_vars: [Region(BrAnon)] }, ()])
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed::<rustc_middle::ty::Ty, rustc_middle::ty::Ty>
   4: rustc_codegen_llvm::debuginfo::metadata::type_di_node
   5: rustc_codegen_ssa::mir::codegen_mir::<rustc_codegen_llvm::builder::Builder>
   6: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
   7: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::compile_codegen_unit
   8: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
   9: <rustc_interface::queries::Linker>::codegen_and_build_linker
  10: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

rustc-ice-2024-08-21T20_21_27-40569.txt

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied example with the reported rustc 1.82.0-nightly version and inspect the panic in compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs. Trace the differing closure types shown in the assertion and verify that compiling the example no longer causes an internal compiler error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.