Skip to content

ICE: broken MIR Unsize coercion in "runtime-optimized" phase (async block !Sync to Sync trait object) #150378

@canmi21

Description

@canmi21

Code

I am unable to provide a minimal, standalone reproduction code.

I attempted to extract the offending logic into a minimal reproduction (creating a !Sync async block and coercing it into a Pin<Box<dyn Future + Send + Sync>>), but the compiler correctly identified the type error and refused to compile without crashing.

However, in my full project (which involves hyper, tokio, and more complex control flow/enum wrapping), the compiler fails to catch this at the type-checking stage and instead crashes (ICE) during the MIR optimization phase.

Reproduction:

I have pushed the state of the project that triggers the ICE to a repository. You can reproduce it as follows:

  1. Clone the repository:
    git clone https://github.com/canmi21/vane.git
  2. Checkout the ICE state branch:
    cd vane
    git checkout future_sync_ice
  3. Run the compiler to reproduce the ICE:
    cargo check

Context of the crashing code:

The crash happens when trying to assign a !Sync future (due to hyper::upgrade::Upgraded) into a struct field that expects Send + Sync.

// In src/modules/stack/protocol/application/http/httpx.rs (approx line 160)

// 'tunnel_future' captures 'client_io' (hyper::upgrade::Upgraded) which is !Sync.
let tunnel_future = Box::pin(async move {
    // Logic holding !Sync types across await points
    match tokio::try_join!(client_upgrade, upstream_upgrade) {
       // ...
    }
});

// The crash happens here, when moving this future into a field expecting Sync:
// payload is an Enum variant where 'tunnel_task' is Option<Pin<Box<dyn Future + Send + Sync>>>
payload = PayloadState::Http(VaneBody::UpgradeBridge {
    tunnel_task: Some(tunnel_future), // ICE triggers here
});

Meta

rustc --version --verbose:

rustc 1.92.0 (ded5c06cf 2025-12-08)
binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: aarch64-apple-darwin
release: 1.92.0
LLVM version: 21.1.3

Error output

(vane) canmi@xyy ~/C/P/vane (latest)> cargo c
   Compiling vane v0.6.7 (/Users/canmi/Canmi/Project/vane)
error: internal compiler error: compiler/rustc_mir_transform/src/validate.rs:81:25: broken MIR in Item(DefId(0:1845 ~ vane[1ecf]::modules::stack::protocol::application::http::httpx::serve_request::{closure#0})) (after phase change to runtime-optimized) at bb107[0]:
                                Unsize coercion, but `std::pin::Pin<std::boxed::Box<{async block@src/modules/stack/protocol/application/http/httpx.rs:134:35: 134:45}>>` isn't coercible to `std::pin::Pin<std::boxed::Box<dyn futures_util::Future<Output = ()> + std::marker::Send + std::marker::Sync>>`
   --> src/modules/stack/protocol/application/http/httpx.rs:167:25
    |
167 |                         tunnel_task: Some(tunnel_future),
    |                                           ^^^^^^^^^^^^^


thread 'rustc' (518628) panicked at compiler/rustc_mir_transform/src/validate.rs:81:25:
Box<dyn Any>
Backtrace

thread 'rustc' (519641) panicked at compiler/rustc_mir_transform/src/validate.rs:81:25:
Box<dyn Any>
stack backtrace:
   0:        0x110f29384 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h2808c764b780ef77
   1:        0x10e36b6d8 - core::fmt::write::h164e2e78980a3344
   2:        0x110ee2504 - std::io::Write::write_fmt::hc5b2a4d160c11c86
   3:        0x110ef45a8 - std::sys::backtrace::BacktraceLock::print::h765d16e49e83c7b3
   4:        0x110efae2c - std::panicking::default_hook::{{closure}}::hf5d7ef6cefa10586
   5:        0x110efaacc - std::panicking::default_hook::h8781bd6c5c54e4cc
   6:        0x10ef19ae0 - std[dc0ae436bb89db06]::panicking::update_hook::<alloc[bc4fa8be2c1bb627]::boxed::Box<rustc_driver_impl[50cf2a748b5c59a1]::install_ice_hook::{closure#1}>>::{closure#0}
   7:        0x110efb354 - std::panicking::panic_with_hook::h93c775fc227522dd
   8:        0x10ef9ae04 - std[dc0ae436bb89db06]::panicking::begin_panic::<rustc_errors[49e2b406ffe14c44]::ExplicitBug>::{closure#0}
   9:        0x10ef8859c - std[dc0ae436bb89db06]::sys::backtrace::__rust_end_short_backtrace::<std[dc0ae436bb89db06]::panicking::begin_panic<rustc_errors[49e2b406ffe14c44]::ExplicitBug>::{closure#0}, !>
  10:        0x113cc7218 - std[dc0ae436bb89db06]::panicking::begin_panic::<rustc_errors[49e2b406ffe14c44]::ExplicitBug>
  11:        0x113cc7dc8 - <rustc_errors[49e2b406ffe14c44]::diagnostic::BugAbort as rustc_errors[49e2b406ffe14c44]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:        0x113d3393c - <rustc_errors[49e2b406ffe14c44]::DiagCtxtHandle>::span_bug::<rustc_span[b61ca60f5275f53a]::span_encoding::Span, alloc[bc4fa8be2c1bb627]::string::String>
  13:        0x113d349a8 - rustc_middle[3debd01596c306bb]::util::bug::opt_span_bug_fmt::<rustc_span[b61ca60f5275f53a]::span_encoding::Span>::{closure#0}
  14:        0x10fb5dc04 - rustc_middle[3debd01596c306bb]::ty::context::tls::with_opt::<rustc_middle[3debd01596c306bb]::util::bug::opt_span_bug_fmt<rustc_span[b61ca60f5275f53a]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:        0x10fb36a68 - rustc_middle[3debd01596c306bb]::ty::context::tls::with_context_opt::<rustc_middle[3debd01596c306bb]::ty::context::tls::with_opt<rustc_middle[3debd01596c306bb]::util::bug::opt_span_bug_fmt<rustc_span[b61ca60f5275f53a]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:        0x113d33c64 - rustc_middle[3debd01596c306bb]::util::bug::span_bug_fmt::<rustc_span[b61ca60f5275f53a]::span_encoding::Span>
  17:        0x10fe1ad7c - <rustc_mir_transform[30feda94a763ca72]::validate::CfgChecker>::fail::<alloc[bc4fa8be2c1bb627]::string::String>
  18:        0x10ff43240 - <rustc_mir_transform[30feda94a763ca72]::validate::Validator as rustc_mir_transform[30feda94a763ca72]::pass_manager::MirPass>::run_pass
  19:        0x10fed4a3c - rustc_mir_transform[30feda94a763ca72]::pass_manager::run_passes_inner
  20:        0x10fe92928 - rustc_mir_transform[30feda94a763ca72]::run_optimization_passes
  21:        0x10fe91cb8 - rustc_mir_transform[30feda94a763ca72]::optimized_mir
  22:        0x1103abf30 - rustc_query_impl[1913c4dc82019177]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1913c4dc82019177]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3debd01596c306bb]::query::erase::Erased<[u8; 8usize]>>
  23:        0x1103f4e54 - rustc_query_system[55b68c9b31defbbe]::query::plumbing::try_execute_query::<rustc_query_impl[1913c4dc82019177]::DynamicConfig<rustc_query_system[55b68c9b31defbbe]::query::caches::DefIdCache<rustc_middle[3debd01596c306bb]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[1913c4dc82019177]::plumbing::QueryCtxt, true>
  24:        0x1103a056c - rustc_query_impl[1913c4dc82019177]::plumbing::force_from_dep_node::<rustc_query_impl[1913c4dc82019177]::DynamicConfig<rustc_query_system[55b68c9b31defbbe]::query::caches::DefIdCache<rustc_middle[3debd01596c306bb]::query::erase::Erased<[u8; 8usize]>>, false, false, false>>
  25:        0x11066c1a0 - <rustc_query_impl[1913c4dc82019177]::plumbing::query_callback<rustc_query_impl[1913c4dc82019177]::query_impl::optimized_mir::QueryType>::{closure#0} as core[efaf33ed1a5ac28d]::ops::function::FnOnce<(rustc_middle[3debd01596c306bb]::ty::context::TyCtxt, rustc_query_system[55b68c9b31defbbe]::dep_graph::dep_node::DepNode, rustc_query_system[55b68c9b31defbbe]::dep_graph::serialized::SerializedDepNodeIndex)>>::call_once
  26:        0x110390780 - <rustc_query_system[55b68c9b31defbbe]::dep_graph::graph::DepGraphData<rustc_middle[3debd01596c306bb]::dep_graph::DepsType>>::try_mark_previous_green::<rustc_query_impl[1913c4dc82019177]::plumbing::QueryCtxt>
  27:        0x11039072c - <rustc_query_system[55b68c9b31defbbe]::dep_graph::graph::DepGraphData<rustc_middle[3debd01596c306bb]::dep_graph::DepsType>>::try_mark_previous_green::<rustc_query_impl[1913c4dc82019177]::plumbing::QueryCtxt>
  28:        0x11039072c - <rustc_query_system[55b68c9b31defbbe]::dep_graph::graph::DepGraphData<rustc_middle[3debd01596c306bb]::dep_graph::DepsType>>::try_mark_previous_green::<rustc_query_impl[1913c4dc82019177]::plumbing::QueryCtxt>
  29:        0x1103905d8 - <rustc_query_system[55b68c9b31defbbe]::dep_graph::graph::DepGraphData<rustc_middle[3debd01596c306bb]::dep_graph::DepsType>>::try_mark_green::<rustc_query_impl[1913c4dc82019177]::plumbing::QueryCtxt>
  30:        0x11040735c - rustc_query_system[55b68c9b31defbbe]::query::plumbing::try_execute_query::<rustc_query_impl[1913c4dc82019177]::DynamicConfig<rustc_query_system[55b68c9b31defbbe]::query::caches::DefaultCache<rustc_middle[3debd01596c306bb]::ty::PseudoCanonicalInput<rustc_middle[3debd01596c306bb]::ty::Ty>, rustc_middle[3debd01596c306bb]::query::erase::Erased<[u8; 16usize]>>, false, true, false>, rustc_query_impl[1913c4dc82019177]::plumbing::QueryCtxt, true>
  31:        0x11056ada8 - rustc_query_impl[1913c4dc82019177]::query_impl::layout_of::get_query_incr::__rust_end_short_backtrace
  32:        0x110e85b5c - <rustc_middle[3debd01596c306bb]::ty::layout::LayoutCx as rustc_middle[3debd01596c306bb]::ty::layout::LayoutOf>::spanned_layout_of
  33:        0x110e495bc - <core[efaf33ed1a5ac28d]::iter::adapters::GenericShunt<core[efaf33ed1a5ac28d]::iter::adapters::by_ref_sized::ByRefSized<core[efaf33ed1a5ac28d]::iter::adapters::map::Map<core[efaf33ed1a5ac28d]::slice::iter::Iter<rustc_middle[3debd01596c306bb]::mir::query::CoroutineSavedTy>, rustc_ty_utils[f20e79acf91c0c4d]::layout::layout_of_uncached::{closure#12}>>, core[efaf33ed1a5ac28d]::result::Result<core[efaf33ed1a5ac28d]::convert::Infallible, &rustc_middle[3debd01596c306bb]::ty::layout::LayoutError>> as core[efaf33ed1a5ac28d]::iter::traits::iterator::Iterator>::next
  34:        0x110e04a58 - core[efaf33ed1a5ac28d]::iter::adapters::try_process::<core[efaf33ed1a5ac28d]::iter::adapters::by_ref_sized::ByRefSized<core[efaf33ed1a5ac28d]::iter::adapters::map::Map<core[efaf33ed1a5ac28d]::slice::iter::Iter<rustc_middle[3debd01596c306bb]::mir::query::CoroutineSavedTy>, rustc_ty_utils[f20e79acf91c0c4d]::layout::layout_of_uncached::{closure#12}>>, rustc_abi[b9b81dfdd0cd95d4]::layout::ty::TyAndLayout<rustc_middle[3debd01596c306bb]::ty::Ty>, core[efaf33ed1a5ac28d]::result::Result<core[efaf33ed1a5ac28d]::convert::Infallible, &rustc_middle[3debd01596c306bb]::ty::layout::LayoutError>, <core[efaf33ed1a5ac28d]::iter::adapters::map::Map<core[efaf33ed1a5ac28d]::slice::iter::Iter<rustc_middle[3debd01596c306bb]::mir::query::CoroutineSavedTy>, rustc_ty_utils[f20e79acf91c0c4d]::layout::layout_of_uncached::{closure#12}> as core[efaf33ed1a5ac28d]::iter::traits::iterator::Iterator>::try_collect<rustc_index[3b6d27c33e9a86b4]::vec::IndexVec<rustc_middle[3debd01596c306bb]::mir::query::CoroutineSavedLocal, rustc_abi[b9b81dfdd0cd95d4]::layout::ty::TyAndLayout<rustc_middle[3debd01596c306bb]::ty::Ty>>>::{closure#0}, rustc_index[3b6d27c33e9a86b4]::vec::IndexVec<rustc_middle[3debd01596c306bb]::mir::query::CoroutineSavedLocal, rustc_abi[b9b81dfdd0cd95d4]::layout::ty::TyAndLayout<rustc_middle[3debd01596c306bb]::ty::Ty>>>
  35:        0x110e40088 - rustc_ty_utils[f20e79acf91c0c4d]::layout::layout_of
  36:        0x1103b1b74 - rustc_query_impl[1913c4dc82019177]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1913c4dc82019177]::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3debd01596c306bb]::query::erase::Erased<[u8; 16usize]>>
  37:        0x1106c3f8c - <rustc_query_impl[1913c4dc82019177]::query_impl::layout_of::dynamic_query::{closure#2} as core[efaf33ed1a5ac28d]::ops::function::FnOnce<(rustc_middle[3debd01596c306bb]::ty::context::TyCtxt, rustc_middle[3debd01596c306bb]::ty::PseudoCanonicalInput<rustc_middle[3debd01596c306bb]::ty::Ty>)>>::call_once
  38:        0x11040763c - rustc_query_system[55b68c9b31defbbe]::query::plumbing::try_execute_query::<rustc_query_impl[1913c4dc82019177]::DynamicConfig<rustc_query_system[55b68c9b31defbbe]::query::caches::DefaultCache<rustc_middle[3debd01596c306bb]::ty::PseudoCanonicalInput<rustc_middle[3debd01596c306bb]::ty::Ty>, rustc_middle[3debd01596c306bb]::query::erase::Erased<[u8; 16usize]>>, false, true, false>, rustc_query_impl[1913c4dc82019177]::plumbing::QueryCtxt, true>
  39:        0x11056ada8 - rustc_query_impl[1913c4dc82019177]::query_impl::layout_of::get_query_incr::__rust_end_short_backtrace
  40:        0x10f7c74bc - <rustc_middle[3debd01596c306bb]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[4523f22467e79f56]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  41:        0x10f80ffec - rustc_interface[4523f22467e79f56]::passes::analysis
  42:        0x1103b1820 - rustc_query_impl[1913c4dc82019177]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1913c4dc82019177]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[3debd01596c306bb]::query::erase::Erased<[u8; 0usize]>>
  43:        0x1103f8708 - rustc_query_system[55b68c9b31defbbe]::query::plumbing::try_execute_query::<rustc_query_impl[1913c4dc82019177]::DynamicConfig<rustc_query_system[55b68c9b31defbbe]::query::caches::SingleCache<rustc_middle[3debd01596c306bb]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[1913c4dc82019177]::plumbing::QueryCtxt, true>
  44:        0x110569204 - rustc_query_impl[1913c4dc82019177]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  45:        0x10eecd560 - rustc_interface[4523f22467e79f56]::passes::create_and_enter_global_ctxt::<core[efaf33ed1a5ac28d]::option::Option<rustc_interface[4523f22467e79f56]::queries::Linker>, rustc_driver_impl[50cf2a748b5c59a1]::run_compiler::{closure#0}::{closure#2}>
  46:        0x10ef18174 - rustc_interface[4523f22467e79f56]::interface::run_compiler::<(), rustc_driver_impl[50cf2a748b5c59a1]::run_compiler::{closure#0}>::{closure#1}
  47:        0x10ef0c734 - std[dc0ae436bb89db06]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4523f22467e79f56]::util::run_in_thread_with_globals<rustc_interface[4523f22467e79f56]::util::run_in_thread_pool_with_globals<rustc_interface[4523f22467e79f56]::interface::run_compiler<(), rustc_driver_impl[50cf2a748b5c59a1]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  48:        0x10ef1e970 - <<std[dc0ae436bb89db06]::thread::Builder>::spawn_unchecked_<rustc_interface[4523f22467e79f56]::util::run_in_thread_with_globals<rustc_interface[4523f22467e79f56]::util::run_in_thread_pool_with_globals<rustc_interface[4523f22467e79f56]::interface::run_compiler<(), rustc_driver_impl[50cf2a748b5c59a1]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[efaf33ed1a5ac28d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  49:        0x110ef1190 - std::sys::thread::unix::Thread::new::thread_start::h98270432b6aefc44
  50:        0x18a0efbc8 - __pthread_cond_wait

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.92.0 (ded5c06cf 2025-12-08) 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]

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

query stack during panic:
#0 [optimized_mir] optimizing MIR for `modules::stack::protocol::application::http::httpx::serve_request::{closure#0}`
#1 [layout_of] computing layout of `core::mem::maybe_uninit::MaybeUninit<{async fn body of modules::stack::protocol::application::http::httpx::serve_request()}>`
#2 [layout_of] computing layout of `{async block@src/modules/stack/protocol/application/http/httpx.rs:40:3: 40:13}`
#3 [analysis] running analysis passes on this crate
end of query stack
there was a panic while trying to force a dep node
try_mark_green dep node stack:
#0 layout_of(9d50d7303d967ddd-de30433fcf58b9f4)
#1 layout_of(dde471a2b8d826d3-3506269fa919b8c0)
#2 layout_of(7a4411078140b98a-63f10cb589b7d29b)
end of try_mark_green dep node stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-coercionsArea: implicit and explicit `expr as Type` coercionsC-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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions