rust-lang / rust-lang/rust

[ICE]: invalid `CoerceUnsized`

Open
#159,575 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug fixed-by-next-solver I-ICE needs-triage T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

snippet:

//@compile-flags: --edition=2021
use std::future::IntoFuture;
use std::sync::Arc;
use std::{future::Future, pin::Pin};
trait Access {
    type Lister;
    fn list(&self) -> impl Future<Output = Self::Lister> + Send {
        async { todo!() }
    }
}
trait AccessDyn: Send + Sync {}
impl Access for Arc<dyn AccessDyn> {
    type Lister = ();
}
struct OperatorFuture<F> {
    _f: F,
}
impl<F> OperatorFuture<F> {
    fn new(_: fn(Arc<dyn AccessDyn>) -> F) -> Self {
        todo!()
    }
}
impl<F> IntoFuture for OperatorFuture<F>
where
    F: Future<Output = ()>,
{
    type Output = ();
    type IntoFuture = F;
    fn into_future(self) -> Self::IntoFuture {
        todo!()
    }
}
async fn runner() {
    OperatorFuture::new(|v| async move { v.list().await }).await
}
struct BoxCloneService(Box<dyn Service<Future = Pin<Box<dyn Future<Output = ()>>>>>);
fn main() {
    let body = async {
        let svc = RuntimeServer(runner);
        let inner = svc.map_future(|f| -> Pin<Box<dyn Future<Output = ()>>> { Box::pin(f) });
        BoxCloneService(Box::new(inner))
    };
    Box::pin(body).as_mut().poll(make());
}
fn make<T>() -> T {
    todo!()
}
struct RuntimeServer<T: 'static>(T);
type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;
trait Runner: Send + Clone {}
impl<F, O> Runner for F
where
    F: FnOnce() -> O + Send + Clone,
    O: Send,
{
}
struct LoadSvc<T>(T);
impl<T: Runner> UnaryService for LoadSvc<T> {
    type Future = BoxFuture<()>;
}
impl<T> Service for RuntimeServer<T>
where
    T: Runner,
{
    type Future = BoxFuture<()>;
    fn call(&mut self) -> Self::Future {
        let inner = self.0.clone();
        let fut = async {
            unary(LoadSvc(inner)).await;
        };
        Box::pin(fut)
    }
}
trait Service {
    type Future: Future;
    fn call(&mut self) -> Self::Future;
    fn map_future<F>(self, _: F) -> MapFuture<Self, F>
    where
        Self: Sized,
    {
        todo!()
    }
}
trait UnaryService {
    type Future: Future;
    fn call(&mut self) -> Self::Future {
        todo!()
    }
}
impl<T> UnaryService for T
where
    T: Service,
{
    type Future = T::Future;
}
fn unary<S>(mut service: S) -> impl Future
where
    S: UnaryService,
{
    service.call()
}
struct MapFuture<S, F> {
    inner: S,
    f: F,
}
impl<S, F, Fut> Service for MapFuture<S, F>
where
    S: Service,
    F: FnMut(S::Future) -> Fut,
    Fut: Future,
{
    type Future = Fut;
    fn call(&mut self) -> Self::Future {
        (self.f)(self.inner.call())
    }
}

Version information

rustc 1.99.0-nightly (c7d7da342 2026-07-19)
binary: rustc
commit-hash: c7d7da3428c0e8b261e1ce1687e7228cf053cc62
commit-date: 2026-07-19
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 22.1.8

Possibly related line of code:
https://github.com/rust-lang/rust/blob/c7d7da3428c0e8b261e1ce1687e7228cf053cc62/compiler/rustc_monomorphize/src/lib.rs#L35-L47

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --edition=2021

Program output

warning: field `0` is never read
  --> /tmp/icemaker_global_tempdir.wAQJadqCZpHx/rustc_testrunner_tmpdir_reporting.6q6B574dtaBb/mvce.rs:35:24
   |
35 | struct BoxCloneService(Box<dyn Service<Future = Pin<Box<dyn Future<Output = ()>>>>>);
   |        --------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |        |
   |        field in this struct
   |
   = help: consider removing this field
   = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default

warning: struct `LoadSvc` is never constructed
  --> /tmp/icemaker_global_tempdir.wAQJadqCZpHx/rustc_testrunner_tmpdir_reporting.6q6B574dtaBb/mvce.rs:56:8
   |
56 | struct LoadSvc<T>(T);
   |        ^^^^^^^

warning: method `call` is never used
  --> /tmp/icemaker_global_tempdir.wAQJadqCZpHx/rustc_testrunner_tmpdir_reporting.6q6B574dtaBb/mvce.rs:75:8
   |
73 | trait Service {
   |       ------- method in this trait
74 |     type Future: Future;
75 |     fn call(&mut self) -> Self::Future;
   |        ^^^^

warning: trait `UnaryService` is never used
  --> /tmp/icemaker_global_tempdir.wAQJadqCZpHx/rustc_testrunner_tmpdir_reporting.6q6B574dtaBb/mvce.rs:83:7
   |
83 | trait UnaryService {
   |       ^^^^^^^^^^^^

warning: function `unary` is never used
  --> /tmp/icemaker_global_tempdir.wAQJadqCZpHx/rustc_testrunner_tmpdir_reporting.6q6B574dtaBb/mvce.rs:95:4
   |
95 | fn unary<S>(mut service: S) -> impl Future
   |    ^^^^^

warning: fields `inner` and `f` are never read
   --> /tmp/icemaker_global_tempdir.wAQJadqCZpHx/rustc_testrunner_tmpdir_reporting.6q6B574dtaBb/mvce.rs:102:5
    |
101 | struct MapFuture<S, F> {
    |        --------- fields in this struct
102 |     inner: S,
    |     ^^^^^
103 |     f: F,
    |     ^

warning: unused `Poll` that must be used
  --> /tmp/icemaker_global_tempdir.wAQJadqCZpHx/rustc_testrunner_tmpdir_reporting.6q6B574dtaBb/mvce.rs:42:5
   |
42 |     Box::pin(body).as_mut().poll(make());
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this `Poll` may be a `Pending` variant, which should be handled
   = note: `#[warn(unused_must_use)]` (part of `#[warn(unused)]`) on by default
help: use `let _ = ...` to ignore the resulting value
   |
42 |     let _ = Box::pin(body).as_mut().poll(make());
   |     +++++++

error: internal compiler error: /rustc-dev/c7d7da3428c0e8b261e1ce1687e7228cf053cc62/compiler/rustc_monomorphize/src/lib.rs:41:13: invalid `CoerceUnsized` from Pin<Box<{async block@/tmp/icemaker_global_tempdir.wAQJadqCZpHx/rustc_testrunner_tmpdir_reporting.6q6B574dtaBb/mvce.rs:67:19: 67:24}>> to Pin<Box<dyn Future<Output = ()> + Send>>: impl_source: Err(Unimplemented)


thread 'rustc' (2296251) panicked at /rustc-dev/c7d7da3428c0e8b261e1ce1687e7228cf053cc62/compiler/rustc_monomorphize/src/lib.rs:41:13:
Box<dyn Any>
stack backtrace:
   0:     0x7ff6ca8e2346 - <<std[bb656dee0c1a7164]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[cf8fb3d9e41ef217]::fmt::Display>::fmt
   1:     0x7ff6cb00a310 - core[cf8fb3d9e41ef217]::fmt::write
   2:     0x7ff6ca8f75ac - <std[bb656dee0c1a7164]::sys::stdio::unix::Stderr as core[cf8fb3d9e41ef217]::io::write::Write>::write_fmt
   3:     0x7ff6ca8b3fda - std[bb656dee0c1a7164]::panicking::default_hook::{closure#0}
   4:     0x7ff6ca8d4a73 - std[bb656dee0c1a7164]::panicking::default_hook
   5:     0x7ff6c988947b - std[bb656dee0c1a7164]::panicking::update_hook::<alloc[3446759d461fd26]::boxed::Box<rustc_driver_impl[a9408d480ad75656]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7ff6ca8d4f12 - std[bb656dee0c1a7164]::panicking::panic_with_hook
   7:     0x7ff6c98b6f31 - std[bb656dee0c1a7164]::panicking::begin_panic::<rustc_errors[d99abff1ac5e4022]::ExplicitBug>::{closure#0}
   8:     0x7ff6c98afca6 - std[bb656dee0c1a7164]::sys::backtrace::__rust_end_short_backtrace::<std[bb656dee0c1a7164]::panicking::begin_panic<rustc_errors[d99abff1ac5e4022]::ExplicitBug>::{closure#0}, !>
   9:     0x7ff6c98adce7 - std[bb656dee0c1a7164]::panicking::begin_panic::<rustc_errors[d99abff1ac5e4022]::ExplicitBug>
  10:     0x7ff6c98c20c1 - <rustc_errors[d99abff1ac5e4022]::diagnostic::BugAbort as rustc_errors[d99abff1ac5e4022]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7ff6c9e4bf09 - rustc_middle[1b51c4dae9648f9a]::util::bug::opt_span_bug_fmt::<rustc_span[3e8afa6d2baecbb6]::span_encoding::Span>::{closure#0}
  12:     0x7ff6c9e4c072 - rustc_middle[1b51c4dae9648f9a]::ty::context::tls::with_opt::<rustc_middle[1b51c4dae9648f9a]::util::bug::opt_span_bug_fmt<rustc_span[3e8afa6d2baecbb6]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7ff6c9e3744b - rustc_middle[1b51c4dae9648f9a]::ty::context::tls::with_context_opt::<rustc_middle[1b51c4dae9648f9a]::ty::context::tls::with_opt<rustc_middle[1b51c4dae9648f9a]::util::bug::opt_span_bug_fmt<rustc_span[3e8afa6d2baecbb6]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7ff6c73f84d4 - rustc_middle[1b51c4dae9648f9a]::util::bug::bug_fmt
  15:     0x7ff6cce628ed - rustc_monomorphize[57f929ef084c0ed2]::collector::find_tails_for_unsizing.cold
  16:     0x7ff6cb521643 - rustc_monomorphize[57f929ef084c0ed2]::collector::items_of_instance
  17:     0x7ff6cb51ca51 - rustc_query_impl[91105c57d45a8e7d]::query_impl::items_of_instance::invoke_provider_fn::__rust_begin_short_backtrace
  18:     0x7ff6cb50866d - rustc_query_impl[91105c57d45a8e7d]::execution::try_execute_query::<rustc_middle[1b51c4dae9648f9a]::query::caches::DefaultCache<(rustc_middle[1b51c4dae9648f9a]::ty::instance::Instance, rustc_middle[1b51c4dae9648f9a]::mono::CollectionMode), rustc_middle[1b51c4dae9648f9a]::query::erase::ErasedData<[u8; 32usize]>>, false>
  19:     0x7ff6cb5082db - rustc_query_impl[91105c57d45a8e7d]::query_impl::items_of_instance::execute_query_non_incr::__rust_end_short_backtrace
  20:     0x7ff6cb5150a4 - rustc_monomorphize[57f929ef084c0ed2]::collector::collect_items_rec::{closure#0}
  21:     0x7ff6cc425b7c - rustc_monomorphize[57f929ef084c0ed2]::collector::collect_items_rec
  22:     0x7ff6cc42751a - rustc_monomorphize[57f929ef084c0ed2]::collector::collect_items_rec
  23:     0x7ff6cc42751a - rustc_monomorphize[57f929ef084c0ed2]::collector::collect_items_rec
  24:     0x7ff6cc42751a - rustc_monomorphize[57f929ef084c0ed2]::collector::collect_items_rec
  25:     0x7ff6cb8a13f3 - rustc_monomorphize[57f929ef084c0ed2]::collector::collect_crate_mono_items::{closure#1}::{closure#0}
  26:     0x7ff6cbc89a39 - rustc_monomorphize[57f929ef084c0ed2]::partitioning::collect_and_partition_mono_items
  27:     0x7ff6cc1abce6 - rustc_query_impl[91105c57d45a8e7d]::query_impl::collect_and_partition_mono_items::invoke_provider_fn::__rust_begin_short_backtrace
  28:     0x7ff6cc1ab641 - rustc_query_impl[91105c57d45a8e7d]::execution::try_execute_query::<rustc_middle[1b51c4dae9648f9a]::query::caches::SingleCache<rustc_middle[1b51c4dae9648f9a]::query::erase::ErasedData<[u8; 24usize]>>, false>
  29:     0x7ff6cc1ab2fc - rustc_query_impl[91105c57d45a8e7d]::query_impl::collect_and_partition_mono_items::execute_query_non_incr::__rust_end_short_backtrace
  30:     0x7ff6cc275d44 - rustc_codegen_ssa[f243843144e2fa2b]::base::codegen_crate::<rustc_codegen_llvm[eab607b2a45fc094]::LlvmCodegenBackend, rustc_codegen_llvm[eab607b2a45fc094]::ModuleLlvm>
  31:     0x7ff6cc275a4d - <rustc_codegen_llvm[eab607b2a45fc094]::LlvmCodegenBackend as rustc_codegen_ssa[f243843144e2fa2b]::traits::backend::CodegenBackend>::codegen_crate
  32:     0x7ff6cc1d67a0 - <rustc_interface[bd87170b5770ef6e]::queries::Linker>::codegen_and_build_linker
  33:     0x7ff6cc1d0c4e - rustc_interface[bd87170b5770ef6e]::interface::run_compiler::<(), rustc_driver_impl[a9408d480ad75656]::run_compiler::{closure#0}>::{closure#2}
  34:     0x7ff6cc1764a4 - std[bb656dee0c1a7164]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[bd87170b5770ef6e]::util::run_in_thread_with_globals<rustc_interface[bd87170b5770ef6e]::util::run_in_thread_pool_with_globals<rustc_interface[bd87170b5770ef6e]::interface::run_compiler<(), rustc_driver_impl[a9408d480ad75656]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  35:     0x7ff6cc176273 - <std[bb656dee0c1a7164]::thread::lifecycle::spawn_unchecked<rustc_interface[bd87170b5770ef6e]::util::run_in_thread_with_globals<rustc_interface[bd87170b5770ef6e]::util::run_in_thread_pool_with_globals<rustc_interface[bd87170b5770ef6e]::interface::run_compiler<(), rustc_driver_impl[a9408d480ad75656]::run_compiler::{closure#0}>::{closure#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[cf8fb3d9e41ef217]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  36:     0x7ff6cc181048 - <std[bb656dee0c1a7164]::sys::thread::unix::Thread>::new::thread_start
  37:     0x7ff6c5897739 - <unknown>
  38:     0x7ff6c591bedc - <unknown>
  39:                0x0 - <unknown>

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: rustc 1.99.0-nightly (c7d7da342 2026-07-19) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir-dir=dir

query stack during panic:
#0 [items_of_instance] collecting items used by `<impl at /tmp/icemaker_global_tempdir.wAQJadqCZpHx/rustc_testrunner_tmpdir_reporting.6q6B574dtaBb/mvce.rs:60:1: 62:15>::call`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to 1 previous error; 7 warnings emitted


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

Start with the provided reproducer and run it using the listed rustc command to observe the invalid CoerceUnsized ICE. Then inspect compiler/rustc_monomorphize/src/lib.rs around lines 35-47 and trace how this unsizing case reaches the panic. Done means the reproducer no longer triggers an internal compiler error and receives appropriate compiler behavior.

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
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.