Skip to content

ICE with higher order associated types #129372

Open
@LHolten

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)A-associated-itemsArea: Associated items (types, constants & functions)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions