Skip to content

[ICE]: Transmuting a circularly defined GAT causes ICE with next-solver #155423

@theemathas

Description

@theemathas

Code

This ICE requires -Znext-solver to reproduce.

The type <Thing as Trait>::Assoc<Thing> is defined circularly as itself. This construction is the same as #149898.

For other issues with the transmute size check, see #155412 and #88290.

cc @RalfJung @lcnr

#![expect(unused)]

use std::mem::transmute;

trait Trait {
    type Assoc<T: Trait>;
}

struct Thing;
impl Trait for Thing {
    type Assoc<T: Trait> = T::Assoc<T>;
}

fn foo<T: Trait>() -> impl Sized {
    let value: *const <T as Trait>::Assoc<T> = panic!();
    value
}

fn main() {
    let mut x = foo::<Thing>();
    // transmute the type to that same type
    x = unsafe { transmute::<_, _>(foo::<Thing>()) }
}

Meta

rustc --version --verbose:

rustc 1.97.0-nightly (7af3402cd 2026-04-16)
binary: rustc
commit-hash: 7af3402cda75aaead39f72516fd6cbb2f3ee0dbd
commit-date: 2026-04-16
host: aarch64-apple-darwin
release: 1.97.0-nightly
LLVM version: 22.1.2

Error output

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: tried to normalize non-wf type Alias(
                                    AliasTy {
                                        args: [
                                            Thing,
                                        ],
                                        kind: Opaque {
                                            def_id: DefId(0:14 ~ foo[3a50]::foo::{opaque#0}),
                                        },
                                        ..
                                    },
                                ) in check_transmute
  --> src/main.rs:22:18
   |
22 |     x = unsafe { transmute::<_, _>(foo::<Thing>()) }
   |                  ^^^^^^^^^^^^^^^^^
   |
Backtrace

note: delayed at /rustc-dev/7af3402cda75aaead39f72516fd6cbb2f3ee0dbd/compiler/rustc_hir_typeck/src/intrinsicck.rs:84:13
         0: <std::backtrace::Backtrace>::create
         1: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         2: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         3: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         4: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, alloc::string::String>
         5: rustc_hir_typeck::intrinsicck::check_transmute::{closure#1}
         6: rustc_hir_typeck::intrinsicck::check_transmutes
         7: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 0]>, rustc_middle::dep_graph::graph::DepNodeIndex>, true>
         8: rustc_query_impl::query_impl::check_transmutes::execute_query_incr::__rust_end_short_backtrace
         9: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
        10: rustc_interface::passes::analysis
        11: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 0]>>, true>
        12: rustc_query_impl::query_impl::analysis::execute_query_incr::__rust_end_short_backtrace
        13: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
        14: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        15: std::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        16: <std::thread::lifecycle::spawn_unchecked<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        17: <std::sys::thread::unix::Thread>::new::thread_start
        18: __pthread_cond_wait
      
  --> src/main.rs:22:18
   |
22 |     x = unsafe { transmute::<_, _>(foo::<Thing>()) }
   |                  ^^^^^^^^^^^^^^^^^

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: please attach the file at `/Users/timch/foo/rustc-ice-2026-04-17T08_52_39-4824.txt` to your bug report

note: rustc 1.97.0-nightly (7af3402cd 2026-04-16) running on aarch64-apple-darwin

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED] -Z next-solver=globally

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `foo` (bin "foo")

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-GATsArea: Generic associated types (GATs)A-associated-itemsArea: Associated items (types, constants & functions)A-layoutArea: Memory layout of typesA-trait-systemArea: Trait systemC-bugCategory: This is a bug.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.T-typesRelevant to the types team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions