rust-lang / rust-lang/rust

[ICE]: `dyn compatibility during coercion`

Open
#158,285 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-coercions A-dyn-compatibility C-bug fixed-by-next-solver I-ICE S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
type A = ();

fn f<T>(f: impl FnOnce(&A) -> T) -> impl for<'a> FnOnce(&'a A) -> Box<dyn Sized + 'a> {
    move |a| Box::new(f(a))
}

fn main() {}

A mutant of glacier2's fixed/125891.rs

Meta

rustc --version --verbose:

rustc 1.98.0-nightly (91fe22da8 2026-06-21)
binary: rustc
commit-hash: 91fe22da8084a1c9e993d78d4a56f22ab8396236
commit-date: 2026-06-21
host: x86_64-apple-darwin
release: 1.98.0-nightly
LLVM version: 22.1.7
Error output

command: env RUST_BACKTRACE=1 rustc abcd.rs

warning: type alias `A` is never used
 --> abcd.rs:1:6
  |
1 | type A = ();
  |      ^
  |
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: function `f` is never used
 --> abcd.rs:3:4
  |
3 | fn f<T>(f: impl FnOnce(&A) -> T) -> impl for<'a> FnOnce(&'a A) -> Box<dyn Sized + 'a> {
  |    ^

warning: 2 warnings emitted

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: dyn compatibility during coercion
 --> abcd.rs:4:14
  |
4 |     move |a| Box::new(f(a))
  |              ^^^^^^^^^^^^^^
  |
note: delayed at /rustc-dev/91fe22da8084a1c9e993d78d4a56f22ab8396236/compiler/rustc_hir_typeck/src/coercion.rs:805:30
Backtrace

note: delayed at /rustc-dev/91fe22da8084a1c9e993d78d4a56f22ab8396236/compiler/rustc_hir_typeck/src/coercion.rs:805:30
         0: <std::backtrace::Backtrace>::create
         1: <std::backtrace::Backtrace>::capture
         2: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         3: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         4: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         5: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         6: <rustc_hir_typeck::coercion::Coerce>::coerce_unsized_old_solver
         7: <rustc_hir_typeck::coercion::Coerce>::coerce
         8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::coerce
         9: <rustc_hir_typeck::coercion::CoerceMany>::coerce_inner::<<rustc_hir_typeck::coercion::CoerceMany>::coerce::{closure#0}>
        10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_or_body_tail
        11: rustc_hir_typeck::check::check_fn
        12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
        13: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
        14: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_block::{closure#0}
        15: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_block
        16: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
        17: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_or_body_tail
        18: rustc_hir_typeck::check::check_fn
        19: rustc_hir_typeck::typeck_with_inspect::{closure#0}
        20: rustc_hir_typeck::typeck_root
        21: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 8]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        22: rustc_query_impl::query_impl::typeck_root::execute_query_non_incr::__rust_end_short_backtrace
        23: <rustc_middle::ty::context::TyCtxt>::typeck::<rustc_span::def_id::LocalDefId>
        24: rustc_mir_build::thir::pattern::check_match::check_match
        25: rustc_query_impl::query_impl::check_match::invoke_provider_fn::__rust_begin_short_backtrace
        26: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 1]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        27: rustc_query_impl::query_impl::check_match::execute_query_non_incr::__rust_end_short_backtrace
        28: rustc_mir_build::builder::build_mir_inner_impl
        29: rustc_mir_transform::mir_built
        30: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 8]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        31: rustc_query_impl::query_impl::mir_built::execute_query_non_incr::__rust_end_short_backtrace
        32: rustc_mir_transform::ffi_unwind_calls::has_ffi_unwind_calls
        33: rustc_query_impl::query_impl::has_ffi_unwind_calls::invoke_provider_fn::__rust_begin_short_backtrace
        34: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 1]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        35: rustc_query_impl::query_impl::has_ffi_unwind_calls::execute_query_non_incr::__rust_end_short_backtrace
        36: rustc_mir_transform::mir_promoted
        37: rustc_query_impl::query_impl::mir_promoted::invoke_provider_fn::__rust_begin_short_backtrace
        38: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 16]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        39: rustc_query_impl::query_impl::mir_promoted::execute_query_non_incr::__rust_end_short_backtrace
        40: rustc_borrowck::mir_borrowck
        41: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 8]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        42: rustc_query_impl::query_impl::mir_borrowck::execute_query_non_incr::__rust_end_short_backtrace
        43: rustc_hir_analysis::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit
        44: rustc_hir_analysis::collect::type_of::type_of_opaque
        45: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefIdCache<rustc_middle::query::erase::ErasedData<[u8; 8]>>, false>
        46: rustc_query_impl::query_impl::type_of_opaque::execute_query_non_incr::__rust_end_short_backtrace
        47: rustc_hir_analysis::collect::type_of::type_of
        48: rustc_query_impl::query_impl::type_of::invoke_provider_fn::__rust_begin_short_backtrace
        49: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::DefIdCache<rustc_middle::query::erase::ErasedData<[u8; 8]>>, false>
        50: rustc_query_impl::query_impl::type_of::execute_query_non_incr::__rust_end_short_backtrace
        51: rustc_hir_analysis::check::check::check_opaque
        52: rustc_hir_analysis::check::check::check_item_type
        53: rustc_hir_analysis::check::wfcheck::check_well_formed
        54: rustc_query_impl::query_impl::check_well_formed::invoke_provider_fn::__rust_begin_short_backtrace
        55: rustc_query_impl::execution::try_execute_query::<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::ErasedData<[u8; 1]>, rustc_middle::dep_graph::graph::DepNodeIndex>, false>
        56: rustc_query_impl::query_impl::check_well_formed::execute_query_non_incr::__rust_end_short_backtrace
        57: rustc_hir_analysis::check::wfcheck::check_type_wf
        58: rustc_query_impl::query_impl::check_type_wf::invoke_provider_fn::__rust_begin_short_backtrace
        59: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 1]>>, false>
        60: rustc_query_impl::query_impl::check_type_wf::execute_query_non_incr::__rust_end_short_backtrace
        61: rustc_hir_analysis::check_crate
        62: rustc_interface::passes::analysis
        63: rustc_query_impl::execution::try_execute_query::<rustc_middle::query::caches::SingleCache<rustc_middle::query::erase::ErasedData<[u8; 0]>>, false>
        64: rustc_query_impl::query_impl::analysis::execute_query_non_incr::__rust_end_short_backtrace
        65: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
        66: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        67: 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}, ()>
        68: <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}
        69: <std::sys::thread::unix::Thread>::new::thread_start
        70: __pthread_start
      
 --> abcd.rs:4:14
  |
4 |     move |a| Box::new(f(a))
  |              ^^^^^^^^^^^^^^

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 `/Volumes/T7/workspace/260622_ice_case_review_2/tmp/rustc-ice-2026-06-23T04_57_28-24005.txt` to your bug report

note: rustc 1.98.0-nightly (91fe22da8 2026-06-21) running on x86_64-apple-darwin

query stack during panic:
end of query stack

Note

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 report by compiling the provided Rust snippet with the noted nightly compiler, then inspect rustc_hir_typeck/src/coercion.rs around line 805 and the stack frames leading to the delayed bug. Done means the example no longer produces an internal compiler error and the relevant compiler behavior is covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.