Skip to content

[ICE]: Nested generic with default type referencing associated type panics in impl_trait_overcaptures #155405

@ealmloff

Description

@ealmloff

Code

trait T {
    type A;
    fn n() -> M<(), M<(), ()>> {
        loop {}
    }
}

struct M<O, V, F = fn(&<V as T>::A) -> &O>(F, V, O);

impl<O, V, F> T for M<O, V, F> {
    type A = O;
}

impl T for () {
    type A = ();
}

Note inlining the type alias fixes the ICE:

trait T {
    type A;
    fn n() -> M<(), M<(), (), fn(&()) -> &()>, fn(&()) -> &()> {
        loop {}
    }
}

struct M<O, V, F>(F, V, O);

impl<O, V, F> T for M<O, V, F> {
    type A = O;
}

impl T for () {
    type A = ();
}

Meta

rustc --version --verbose:

rustc 1.95.0 (59807616e 2026-04-14)
binary: rustc
commit-hash: 59807616e1fa2540724bfbac14d7976d7e4a3860
commit-date: 2026-04-14
host: aarch64-apple-darwin
release: 1.95.0
LLVM version: 22.1.2

Also panics in the playground in nightly and beta versions

Error output

thread 'rustc' (35053010) panicked at /rustc-dev/59807616e1fa2540724bfbac14d7976d7e4a3860/compiler/rustc_lint/src/impl_trait_overcaptures.rs:220:21:
assertion `left == right` failed
  left: Some(Late)
 right: None
stack backtrace:
<backtrace bellow>

error: the compiler unexpectedly panicked. This is a bug

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: rustc 1.95.0 (59807616e 2026-04-14) running on aarch64-apple-darwin

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED]

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

query stack during panic:
#0 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on crate `ice_mre`
end of query stack
warning: `ice-mre` (lib) generated 2 warnings
error: could not compile `ice-mre` (lib); 2 warnings emitted

Caused by:
  process didn't exit successfully: `/Users/evanalmloff/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name ice_mre --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=68 --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=020aeb126a8b5469 -C extra-filename=-1b832e7c6e9ed08d --out-dir /private/tmp/ice-mre/target/debug/deps -C incremental=/private/tmp/ice-mre/target/debug/incremental -L dependency=/private/tmp/ice-mre/target/debug/deps` (exit status: 101)
Backtrace

thread 'rustc' (35053010) panicked at /rustc-dev/59807616e1fa2540724bfbac14d7976d7e4a3860/compiler/rustc_lint/src/impl_trait_overcaptures.rs:220:21:
assertion `left == right` failed
  left: Some(Late)
 right: None
stack backtrace:
   0:        0x11405ddc0 - <<std[bb513d90a5cee88a]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[f63e075e1375d836]::fmt::Display>::fmt
   1:        0x11127ec28 - core[f63e075e1375d836]::fmt::write
   2:        0x1140755b0 - <std[bb513d90a5cee88a]::sys::stdio::unix::Stderr as std[bb513d90a5cee88a]::io::Write>::write_fmt
   3:        0x11403448c - std[bb513d90a5cee88a]::panicking::default_hook::{closure#0}
   4:        0x1140502a8 - std[bb513d90a5cee88a]::panicking::default_hook
   5:        0x111edcaf0 - std[bb513d90a5cee88a]::panicking::update_hook::<alloc[1519c0c6343f008f]::boxed::Box<rustc_driver_impl[5c335eb20a4751f4]::install_ice_hook::{closure#1}>>::{closure#0}
   6:        0x11405060c - std[bb513d90a5cee88a]::panicking::panic_with_hook
   7:        0x114034534 - std[bb513d90a5cee88a]::panicking::panic_handler::{closure#0}
   8:        0x11402aed8 - std[bb513d90a5cee88a]::sys::backtrace::__rust_end_short_backtrace::<std[bb513d90a5cee88a]::panicking::panic_handler::{closure#0}, !>
   9:        0x114035b04 - __rustc[b7974e8690430dd9]::rust_begin_unwind
  10:        0x1170715b8 - core[f63e075e1375d836]::panicking::panic_fmt
  11:        0x1170714b8 - core[f63e075e1375d836]::panicking::assert_failed_inner
  12:        0x11711a304 - core[f63e075e1375d836]::panicking::assert_failed::<core[f63e075e1375d836]::option::Option<rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::ParamKind>, core[f63e075e1375d836]::option::Option<rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::ParamKind>>
  13:        0x112a324f0 - <rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::VisitOpaqueTypes<rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::check_fn::{closure#0}, rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::check_fn::{closure#1}> as rustc_type_ir[8d0b5b963df9ae4c]::visit::TypeVisitor<rustc_middle[9aaee1f0dbfe40d5]::ty::context::TyCtxt>>::visit_ty
  14:        0x112a3197c - <rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::VisitOpaqueTypes<rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::check_fn::{closure#0}, rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::check_fn::{closure#1}> as rustc_type_ir[8d0b5b963df9ae4c]::visit::TypeVisitor<rustc_middle[9aaee1f0dbfe40d5]::ty::context::TyCtxt>>::visit_ty
  15:        0x112a32458 - <rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::VisitOpaqueTypes<rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::check_fn::{closure#0}, rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::check_fn::{closure#1}> as rustc_type_ir[8d0b5b963df9ae4c]::visit::TypeVisitor<rustc_middle[9aaee1f0dbfe40d5]::ty::context::TyCtxt>>::visit_ty
  16:        0x112a32168 - <rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::VisitOpaqueTypes<rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::check_fn::{closure#0}, rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::check_fn::{closure#1}> as rustc_type_ir[8d0b5b963df9ae4c]::visit::TypeVisitor<rustc_middle[9aaee1f0dbfe40d5]::ty::context::TyCtxt>>::visit_ty
  17:        0x112a3197c - <rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::VisitOpaqueTypes<rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::check_fn::{closure#0}, rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::check_fn::{closure#1}> as rustc_type_ir[8d0b5b963df9ae4c]::visit::TypeVisitor<rustc_middle[9aaee1f0dbfe40d5]::ty::context::TyCtxt>>::visit_ty
  18:        0x112990c00 - rustc_lint[a262a1f834353f3d]::impl_trait_overcaptures::check_fn
  19:        0x112a1b190 - <rustc_lint[a262a1f834353f3d]::BuiltinCombinedModuleLateLintPass as rustc_lint[a262a1f834353f3d]::passes::LateLintPass>::check_trait_item
  20:        0x1128a5200 - <rustc_lint[a262a1f834353f3d]::late::LateContextAndPass<rustc_lint[a262a1f834353f3d]::BuiltinCombinedModuleLateLintPass>>::with_param_env::<<rustc_lint[a262a1f834353f3d]::late::LateContextAndPass<rustc_lint[a262a1f834353f3d]::BuiltinCombinedModuleLateLintPass> as rustc_hir[7869d174a46fdaaa]::intravisit::Visitor>::visit_item::{closure#0}::{closure#0}>
  21:        0x112a34564 - <rustc_lint[a262a1f834353f3d]::late::LateContextAndPass<rustc_lint[a262a1f834353f3d]::BuiltinCombinedModuleLateLintPass> as rustc_hir[7869d174a46fdaaa]::intravisit::Visitor>::visit_item
  22:        0x112963100 - rustc_lint[a262a1f834353f3d]::lint_mod
  23:        0x113506b24 - rustc_query_impl[1f4f3f960cb79e6b]::execution::try_execute_query::<rustc_middle[9aaee1f0dbfe40d5]::query::caches::DefaultCache<rustc_span[c6548ed10a46efff]::def_id::LocalModDefId, rustc_middle[9aaee1f0dbfe40d5]::query::erase::ErasedData<[u8; 0usize]>>, true>
  24:        0x113689928 - rustc_query_impl[1f4f3f960cb79e6b]::query_impl::lint_mod::execute_query_incr::__rust_end_short_backtrace
  25:        0x1129422ec - rustc_lint[a262a1f834353f3d]::late::check_crate::{closure#1}
  26:        0x112990f74 - rustc_lint[a262a1f834353f3d]::late::check_crate
  27:        0x1127d578c - rustc_interface[c32df345b14bfa6e]::passes::analysis::{closure#0}::{closure#0}::{closure#2}
  28:        0x111e7f47c - rustc_data_structures[66f2c8724ec626e5]::sync::parallel::par_fns
  29:        0x1127d79e8 - rustc_interface[c32df345b14bfa6e]::passes::analysis::{closure#0}::{closure#0}
  30:        0x111e7f47c - rustc_data_structures[66f2c8724ec626e5]::sync::parallel::par_fns
  31:        0x11280d634 - rustc_interface[c32df345b14bfa6e]::passes::analysis
  32:        0x1134a7f18 - rustc_query_impl[1f4f3f960cb79e6b]::execution::try_execute_query::<rustc_middle[9aaee1f0dbfe40d5]::query::caches::SingleCache<rustc_middle[9aaee1f0dbfe40d5]::query::erase::ErasedData<[u8; 0usize]>>, true>
  33:        0x113688d68 - rustc_query_impl[1f4f3f960cb79e6b]::query_impl::analysis::execute_query_incr::__rust_end_short_backtrace
  34:        0x111e96a68 - rustc_interface[c32df345b14bfa6e]::passes::create_and_enter_global_ctxt::<core[f63e075e1375d836]::option::Option<rustc_interface[c32df345b14bfa6e]::queries::Linker>, rustc_driver_impl[5c335eb20a4751f4]::run_compiler::{closure#0}::{closure#2}>
  35:        0x111ee0958 - rustc_interface[c32df345b14bfa6e]::interface::run_compiler::<(), rustc_driver_impl[5c335eb20a4751f4]::run_compiler::{closure#0}>::{closure#1}
  36:        0x111ed66f0 - std[bb513d90a5cee88a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c32df345b14bfa6e]::util::run_in_thread_with_globals<rustc_interface[c32df345b14bfa6e]::util::run_in_thread_pool_with_globals<rustc_interface[c32df345b14bfa6e]::interface::run_compiler<(), rustc_driver_impl[5c335eb20a4751f4]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  37:        0x111ee6764 - <std[bb513d90a5cee88a]::thread::lifecycle::spawn_unchecked<rustc_interface[c32df345b14bfa6e]::util::run_in_thread_with_globals<rustc_interface[c32df345b14bfa6e]::util::run_in_thread_pool_with_globals<rustc_interface[c32df345b14bfa6e]::interface::run_compiler<(), rustc_driver_impl[5c335eb20a4751f4]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[f63e075e1375d836]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:        0x11405b33c - <std[bb513d90a5cee88a]::sys::thread::unix::Thread>::new::thread_start
  39:        0x194947c08 - __pthread_cond_wait

error: the compiler unexpectedly panicked. This is a bug

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: rustc 1.95.0 (59807616e 2026-04-14) running on aarch64-apple-darwin

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED]

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

query stack during panic:
#0 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on crate `ice_mre`
end of query stack
warning: `ice-mre` (lib) generated 2 warnings
error: could not compile `ice-mre` (lib); 2 warnings emitted

Caused by:
  process didn't exit successfully: `/Users/evanalmloff/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name ice_mre --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=68 --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=020aeb126a8b5469 -C extra-filename=-1b832e7c6e9ed08d --out-dir /private/tmp/ice-mre/target/debug/deps -C incremental=/private/tmp/ice-mre/target/debug/incremental -L dependency=/private/tmp/ice-mre/target/debug/deps` (exit status: 101)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-bisectionStatus: A bisection has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    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