Skip to content

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

Closed

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

Activity

  1. added
    I-ICE
    T-compiler
    C-bug
    on Dec 25, 2025
  2. added
    needs-triage
    on Dec 25, 2025
  3. moxian commented on Dec 25, 2025

    @moxian
    Contributor

    Smaller, but still reliant on futures_util::join (playground):

    use futures_util::join;
    // use tokio::join; // same thing
    
    use std::pin::Pin;
    use std::task::Context;
    use std::task::Poll;
    use std::future::Future;
    
    pub(crate) struct VaneBody {
        tunnel_task: Pin<Box<dyn Future<Output = ()> + Send + Sync>>,
    }
    
    pub(crate) async fn handle_connection() {
        async move { serve_request().await };
    }
    
    struct OnUpgrade {}
    
    impl Future for OnUpgrade {
        type Output = NotSend;
    
        fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
            todo!()
        }
    }
    
    struct NotSend {
        thing: *mut usize,
    }
    
    async fn serve_request() {
        let client_upgrade = OnUpgrade {};
        let tunnel_future = Box::pin(async move {
            join!(client_upgrade);
        });
        let payload = VaneBody {
            tunnel_task: tunnel_future,
        };
    }
    Regression bisects to nightly-2024-09-26. PRs in range:
     - #129587 (Add `optimize_for_size` variants for stable and unstable sort as well as select_nth_unstable) by Voultapher
     - #130739 (Fix cargo staging for run-make tests) by jieyouxu
     - #130807 (Rollup of 7 pull requests) by tgross35
       - #130234 (improve compile errors for invalid ptr-to-ptr casts with trait objects)
       - #130752 (Improve assembly test for CMSE ABIs)
       - #130764 (Separate collection of crate-local inherent impls from error tracking)
       - #130788 (Pin memchr to 2.5.0 in the library rather than rustc_ast)
       - #130789 (add InProgress ErrorKind gated behind io_error_inprogress feature)
       - #130793 (Mention `COMPILETEST_VERBOSE_CRASHES` on crash test failure)
       - #130798 (rustdoc: inherit parent's stability where applicable)
     - #130803 (Add `File` constructors that return files wrapped with a buffer) by cuviper
     - #18184 (fix: Pass all-targets for build scripts in more cli commands) by Veykril
     - #18183 (internal: Sync from downstream) by lnicola
     - #130816 (Rollup of 6 pull requests) by matthiaskrgr
       - #130549 (Add RISC-V vxworks targets)
       - #130595 (Initial std library support for NuttX)
       - #130734 (Fix: ices on virtual-function-elimination about principal trait)
       - #130787 (Ban combination of GCE and new solver)
       - #130809 (Update llvm triple for OpenHarmony targets)
       - #130810 (Don't trap into the debugger on panics under Linux)
     - #130778 (Clippy subtree update) by flip1995
     - #130812 (Subtree update of `rust-analyzer`) by lnicola
     - #130847 (Rollup of 6 pull requests) by matthiaskrgr
       - #130735 (Simple validation for unsize coercion in MIR validation)
       - #130781 (Fix up setting strip = true in Cargo.toml makes build scripts fail in…)
       - #130811 (add link from random() helper fn to extensive DefaultRandomSource docs)
       - #130819 (Add `must_use` attribute to `len_utf8` and `len_utf16`.)
       - #130832 (fix some cfg logic around optimize_for_size and 16-bit targets)
       - #130842 (Add tracking issue for io_error_inprogress)
     - #120752 (Collect relevant item bounds from trait clauses for nested rigid projections) by compiler-errors
    ..although nothing stands out to me as an obvious culprit. Maybe #130735 ?..

    @rustbot label: +S-has-bisection +A-coercions +A-async-await

  4. added
    A-async-await
    A-coercions
    S-has-bisection
    on Dec 25, 2025
  5. canmi21 commented on Dec 26, 2025

    @canmi21
    Author

    One observation from my side: on macOS (rustc 1.92.0 (ded5c06 2025-12-08)), the provided reproducer does NOT ICE locally. Instead, it is rejected earlier with proper Send/Sync errors during type checking.

    However, rust-analyzer reports a "broken MIR" diagnostic pointing to an unsize coercion from Pin<Box<async block>> to Pin<Box<dyn Future + Send + Sync>>, which suggests the compiler is still able to generate invalid MIR in some code paths.

    So it seems the behavior depends on the compilation pipeline / flags: some paths correctly reject the code, while others allow it to reach MIR validation and ICE.

    Happy to provide logs if useful.

    macOS rejected earlier

    canmi@xyy ~/C/P/future_sync_ice (main)> RUST_BACKTRACE=full cargo check
        Checking future_sync_ice v0.1.0 (/Users/canmi/Canmi/Project/future_sync_ice)
    error[E0601]: `main` function not found in crate `future_sync_ice`
      --> src/main.rs:39:2
       |
    39 | }
       |  ^ consider adding a `main` function to `src/main.rs`
    
    warning: unused variable: `payload`
      --> src/main.rs:36:9
       |
    36 |     let payload = VaneBody {
       |         ^^^^^^^ help: if this is intentional, prefix it with an underscore: `_payload`
       |
       = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default
    
    warning: unused variable: `cx`
      --> src/main.rs:22:35
       |
    22 |     fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
       |                                   ^^ help: if this is intentional, prefix it with an underscore: `_cx`
    
    error: future cannot be shared between threads safely
      --> src/main.rs:37:22
       |
    37 |         tunnel_task: tunnel_future,
       |                      ^^^^^^^^^^^^^ future created by async block is not `Sync`
       |
       = help: within `{async block@src/main.rs:33:34: 33:44}`, the trait `Sync` is not implemented for `*mut usize`
    note: future is not `Sync` as this value is used across an await
      --> src/main.rs:34:9
       |
    34 |         join!(client_upgrade);
       |         ^^^^^^^^^^^^^^^^^^^^^
       |         |
       |         await occurs here, with the value maybe used later
       |         has type `MaybeDone<OnUpgrade>` which is not `Sync`
       = note: required for the cast from `Pin<Box<{async block@src/main.rs:33:34: 33:44}>>` to `Pin<Box<dyn futures_util::Future<Output = ()> + Send + Sync>>`
       = note: this error originates in the macro `join` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    error: future cannot be sent between threads safely
      --> src/main.rs:37:22
       |
    37 |         tunnel_task: tunnel_future,
       |                      ^^^^^^^^^^^^^ future created by async block is not `Send`
       |
       = help: within `{async block@src/main.rs:33:34: 33:44}`, the trait `Send` is not implemented for `*mut usize`
    note: future is not `Send` as this value is used across an await
      --> src/main.rs:34:9
       |
    34 |         join!(client_upgrade);
       |         ^^^^^^^^^^^^^^^^^^^^^
       |         |
       |         await occurs here, with the value maybe used later
       |         has type `MaybeDone<OnUpgrade>` which is not `Send`
       = note: required for the cast from `Pin<Box<{async block@src/main.rs:33:34: 33:44}>>` to `Pin<Box<dyn futures_util::Future<Output = ()> + Send + Sync>>`
       = note: this error originates in the macro `join` (in Nightly builds, run with -Z macro-backtrace for more info)
    
    For more information about this error, try `rustc --explain E0601`.
    warning: `future_sync_ice` (bin "future_sync_ice") generated 2 warnings
    error: could not compile `future_sync_ice` (bin "future_sync_ice") due to 3 previous errors; 2 warnings emitted
    canmi@xyy ~/C/P/future_sync_ice (main) [101]> 
    
    

  6. canmi21 commented on Dec 26, 2025

    @canmi21
    Author

    @moxian It seems that this minimum reproduction code still has some conditional triggers. This cannot be directly triggered on my macos, but my project can be 100% triggered. Further investigation might be needed

  7. moxian commented on Dec 26, 2025

    @moxian
    Contributor

    This is surprising! The example above ICEs for me both on WSL (ubuntu) and Windows (and on rust playground as linked). I can't think of a reason MacOS would behave differently here.

    To minimize the code I used cargo-minimize (or more specifically my fork of it) run as cargo minimize --cargo-subcmd 'check' --verify-fn='|output | output.out.contains("internal compiler error") && output.out.contains("compiler/rustc_mir_transform/src/validate.rs:81:25: broken MIR")' --bisect-delete-imports src/ which did the bulk of the work, followed by some light manual cleanup.
    You can try following similar steps to get a repro that ICEs for you locally and maybe see what's the difference between the two.

  8. canmi21 commented on Dec 26, 2025

    @canmi21
    Author

    I've tried opening a repository to investigate. Currently, it has been optimized to reproduce ICE with over 200 lines of code. Let's see if we can continue to reduce it. I think this ICE is related to a certain warpper level code

    https://github.com/canmi21/future-sync-ice/blob/main/src/main.rs

  9. canmi21 commented on Dec 26, 2025

    @canmi21
    Author

    And I also noticed that this situation triggered on macOS seems to be related to the mod layer. When I try to remove the mod hierarchy, it seems to disappear.

  10. canmi21 commented on Dec 26, 2025

    @canmi21
    Author

    @moxian I successfully extracted an ICE minimum problem reproduction code of approximately 70 lines (x
    Some of the conditions and backtraces that I discovered can be found in the README.md file.

    pub(crate) mod repro {
        use std::pin::Pin;
        use std::task::Context;
        use std::task::Poll;
        use tokio::io::AsyncRead;
        use tokio::io::AsyncWrite;
        use tokio::io::ReadBuf;
    
        pub(crate) struct Upgraded {
            pub(crate) io: Box<dyn AsyncReadWrite + Send>,
        }
    
        pub(crate) trait AsyncReadWrite: AsyncRead + AsyncWrite + Unpin { }
    
        impl<T: AsyncRead + AsyncWrite + Unpin> AsyncReadWrite for T { }
    
        impl AsyncRead for Upgraded {
            fn poll_read(
                self: Pin<&mut Self>,
                _: &mut Context<'_>,
                _: &mut ReadBuf<'_>,
            ) -> Poll<std::io::Result<()>> {
                loop { }
            }
        }
    
        impl AsyncWrite for Upgraded {
            fn poll_write(self: Pin<&mut Self>, _: &mut Context<'_>, _: &[u8]) -> Poll<std::io::Result<usize>> {
                loop { }
            }
    
            fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<std::io::Result<()>> {
                loop { }
            }
    
            fn poll_shutdown(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<std::io::Result<()>> {
                loop { }
            }
        }
    
        type OnUpgrade = Pin<Box<dyn Future<Output = Result<Upgraded, ()>> + Send>>;
    
        pub(crate) async fn handle_connection() {
            let service = || async move {
                serve_request().await
            };
            let _ = service().await;
        }
    
        async fn serve_request() {
            let client: OnUpgrade = Box::pin(async {
                Ok(Upgraded { io: Box::new(tokio::io::empty()) })
            });
            let upstream: OnUpgrade = Box::pin(async {
                Ok(Upgraded { io: Box::new(tokio::io::empty()) })
            });
            tokio::task::yield_now().await;
            let tunnel_future = Box::pin(async move {
                tokio::task::yield_now().await;
                match tokio::try_join!(client, upstream) {
                    Ok((mut c_io, mut u_io)) => {
                        let _ = tokio::io::copy_bidirectional(&mut c_io, &mut u_io).await;
                    },
                    Err(_) => { },
                }
            });
            let _target: Pin<Box<dyn Future<Output = ()> + Send + Sync>> = tunnel_future;
            loop { }
        }
    }
    
    #[tokio::main]
    async fn main() {
        loop { }
    }
  11. canmi21 commented on Dec 26, 2025

    @canmi21
    Author

    You can check at Playground, this version will 100% casue ICE on macOS, We can compare these two versions. Maybe we still need to add a platform tag to this issue, or it might be two ICE issues?

    Regarding the reproduction code you provide above, I guess it might be related to the recent Nightly version. It seems that the plugins in vscode are updated Nightly, while the Stable version on my mac only crashes with my ~70 line version and there are some very strange conditions that can trigger it, u can check it in my repo README

  12. feishiheng commented on Dec 28, 2025

    @feishiheng

    I’ve put together an MRE that reliably reproduces the ICE on my machine.

    use std::future::Future;
    use std::pin::Pin;
    
    pub struct Upgraded {
        pub io: Box<dyn Send>,
    }
    
    type OnUpgrade = Pin<Box<dyn Future<Output = Result<Upgraded, ()>> + Send>>;
    
    pub async fn serve_request() {
        let client: OnUpgrade = Box::pin(async {
            Ok(Upgraded { io: Box::new(0) })
        });
    
        let upstream: OnUpgrade = Box::pin(async {
            Ok(Upgraded { io: Box::new(0) })
        });
    
        let tunnel_future = Box::pin(async move {
            let _ = client.await;
            let _ = upstream.await;
        });
    
        let _target: Pin<Box<dyn Future<Output = ()> + Send + Sync>> = tunnel_future;
    }
    
    fn main() {}

    However, my bisection led to a different result than previously reported; specifically, the crash started occurring with this commit. It’s possible we are looking at multiple related ICEs here.

    Before the commit
    fish@ubuntu ~/p/i/future-sync-ice (main)> ~/src/rust/build/host/stage1/bin/rustc --edition 2024 src/main.rs
    error: future cannot be shared between threads safely
      --> src/main.rs:33:68
       |
    33 |     let _target: Pin<Box<dyn Future<Output = ()> + Send + Sync>> = tunnel_future;
       |                                                                    ^^^^^^^^^^^^^ future created by async block is not `Sync`
       |
       = help: the trait `Sync` is not implemented for `dyn Future<Output = Result<Upgraded, ()>> + Send`
    note: captured value is not `Sync`
      --> src/main.rs:26:17
       |
    26 |         let _ = client.await;
       |                 ^^^^^^ has type `Pin<Box<dyn Future<Output = Result<Upgraded, ()>> + Send>>` which is not `Sync`
       = note: required for the cast from `Pin<Box<{async block@src/main.rs:25:34: 25:44}>>` to `Pin<Box<dyn Future<Output = ()> + Send + Sync>>`
    
    error: aborting due to 1 previous error
    
    fish@ubuntu ~/p/i/future-sync-ice (main) [1]> ~/src/rust/build/host/stage1/bin/rustc -vV
    rustc 1.90.0-nightly (4b55fe199 2025-08-01)
    binary: rustc
    commit-hash: 4b55fe199cfe9c710555a5af7f2a49491ad38254
    commit-date: 2025-08-01
    host: x86_64-unknown-linux-gnu
    release: 1.90.0-nightly
    LLVM version: 21.1.8
    
    With the commit
    fish@ubuntu ~/p/i/future-sync-ice (main)> ~/src/rust/build/host/stage1/bin/rustc --edition 2024 src/main.rs
    error: internal compiler error: compiler/rustc_mir_transform/src/validate.rs:80:25: broken MIR in Item(DefId(0:10 ~ main[543c]::serve_request::{closure#0})) (after phase change to runtime-optimized) at bb4[0]:
                                    Unsize coercion, but `std::pin::Pin<std::boxed::Box<{async block@src/main.rs:25:34: 25:44}>>` isn't coercible to `std::pin::Pin<std::boxed::Box<dyn std::future::Future<Output = ()> + std::marker::Send + std::marker::Sync>>`
      --> src/main.rs:33:68
       |
    33 |     let _target: Pin<Box<dyn Future<Output = ()> + Send + Sync>> = tunnel_future;
       |                                                                    ^^^^^^^^^^^^^
    
    
    thread 'rustc' panicked at compiler/rustc_mir_transform/src/validate.rs:80:25:
    Box<dyn Any>
    stack backtrace:
       0:     0x7318ea35c8e2 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h3f25e7a042e0f78f
       1:     0x7318ea3ab253 - core::fmt::write::h9228492c07172c71
       2:     0x7318ea350fe3 - std::io::Write::write_fmt::hbc89b049541b1f3f
       3:     0x7318ea35c732 - std::sys::backtrace::BacktraceLock::print::h84d9c59f112a45df
       4:     0x7318ea36030c - std::panicking::default_hook::{{closure}}::h5230ec8d3834b5dc
       5:     0x7318ea36010f - std::panicking::default_hook::h82fc2bc32e1ed222
       6:     0x7318e25b9b94 - std[c965b0aa6c3056df]::panicking::update_hook::<alloc[d932a86623700fa6]::boxed::Box<rustc_driver_impl[6eadf89b26fc365d]::install_ice_hook::{closure#1}>>::{closure#0}
       7:     0x7318ea360ddb - std::panicking::rust_panic_with_hook::h7841a0c9dd31384d
       8:     0x7318e9f7edd3 - std[c965b0aa6c3056df]::panicking::begin_panic::<rustc_errors[eb2cea292e117b6f]::ExplicitBug>::{closure#0}
       9:     0x7318e9f7c506 - std[c965b0aa6c3056df]::sys::backtrace::__rust_end_short_backtrace::<std[c965b0aa6c3056df]::panicking::begin_panic<rustc_errors[eb2cea292e117b6f]::ExplicitBug>::{closure#0}, !>
      10:     0x7318e23db644 - std[c965b0aa6c3056df]::panicking::begin_panic::<rustc_errors[eb2cea292e117b6f]::ExplicitBug>
      11:     0x7318e23dbb82 - <rustc_errors[eb2cea292e117b6f]::diagnostic::BugAbort as rustc_errors[eb2cea292e117b6f]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
      12:     0x7318e9d6f550 - <rustc_errors[eb2cea292e117b6f]::DiagCtxtHandle>::span_bug::<rustc_span[3e13a556bd61225d]::span_encoding::Span, alloc[d932a86623700fa6]::string::String>
      13:     0x7318e9da8914 - rustc_middle[7679686ddf2b4d96]::util::bug::opt_span_bug_fmt::<rustc_span[3e13a556bd61225d]::span_encoding::Span>::{closure#0}
      14:     0x7318e9da777a - rustc_middle[7679686ddf2b4d96]::ty::context::tls::with_opt::<rustc_middle[7679686ddf2b4d96]::util::bug::opt_span_bug_fmt<rustc_span[3e13a556bd61225d]::span_encoding::Span>::{closure#0}, !>::{closure#0}
      15:     0x7318e9da772b - rustc_middle[7679686ddf2b4d96]::ty::context::tls::with_context_opt::<rustc_middle[7679686ddf2b4d96]::ty::context::tls::with_opt<rustc_middle[7679686ddf2b4d96]::util::bug::opt_span_bug_fmt<rustc_span[3e13a556bd61225d]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
      16:     0x7318e23b444a - rustc_middle[7679686ddf2b4d96]::util::bug::span_bug_fmt::<rustc_span[3e13a556bd61225d]::span_encoding::Span>
      17:     0x7318e77c91b3 - <rustc_mir_transform[654b2a96333f86ac]::validate::CfgChecker>::fail::<alloc[d932a86623700fa6]::string::String>
      18:     0x7318e77c8884 - <rustc_mir_transform[654b2a96333f86ac]::validate::Validator as rustc_mir_transform[654b2a96333f86ac]::pass_manager::MirPass>::run_pass
      19:     0x7318e79784d7 - rustc_mir_transform[654b2a96333f86ac]::pass_manager::run_passes_inner
      20:     0x7318e77393d0 - rustc_mir_transform[654b2a96333f86ac]::run_optimization_passes
      21:     0x7318e773989d - rustc_mir_transform[654b2a96333f86ac]::optimized_mir
      22:     0x7318e8b5ea52 - rustc_query_impl[b179d58b5687cd24]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b179d58b5687cd24]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7679686ddf2b4d96]::query::erase::Erased<[u8; 8usize]>>
      23:     0x7318e8bd4740 - <rustc_query_impl[b179d58b5687cd24]::query_impl::optimized_mir::dynamic_query::{closure#2} as core[53647cb28d9a8e2]::ops::function::FnOnce<(rustc_middle[7679686ddf2b4d96]::ty::context::TyCtxt, rustc_span[3e13a556bd61225d]::def_id::DefId)>>::call_once
      24:     0x7318e8a9297d - rustc_query_system[582d53aef529b241]::query::plumbing::try_execute_query::<rustc_query_impl[b179d58b5687cd24]::DynamicConfig<rustc_query_system[582d53aef529b241]::query::caches::DefIdCache<rustc_middle[7679686ddf2b4d96]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[b179d58b5687cd24]::plumbing::QueryCtxt, false>
      25:     0x7318e8da3f9a - rustc_query_impl[b179d58b5687cd24]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
      26:     0x7318e9c53759 - <rustc_middle[7679686ddf2b4d96]::ty::context::TyCtxt>::coroutine_layout
      27:     0x7318e880d8ef - rustc_ty_utils[7eb09d67aeb185c1]::layout::layout_of
      28:     0x7318e8b64ffc - rustc_query_impl[b179d58b5687cd24]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b179d58b5687cd24]::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7679686ddf2b4d96]::query::erase::Erased<[u8; 16usize]>>
      29:     0x7318e8bfd502 - <rustc_query_impl[b179d58b5687cd24]::query_impl::layout_of::dynamic_query::{closure#2} as core[53647cb28d9a8e2]::ops::function::FnOnce<(rustc_middle[7679686ddf2b4d96]::ty::context::TyCtxt, rustc_middle[7679686ddf2b4d96]::ty::PseudoCanonicalInput<rustc_middle[7679686ddf2b4d96]::ty::Ty>)>>::call_once
      30:     0x7318e8aa24d0 - rustc_query_system[582d53aef529b241]::query::plumbing::try_execute_query::<rustc_query_impl[b179d58b5687cd24]::DynamicConfig<rustc_query_system[582d53aef529b241]::query::caches::DefaultCache<rustc_middle[7679686ddf2b4d96]::ty::PseudoCanonicalInput<rustc_middle[7679686ddf2b4d96]::ty::Ty>, rustc_middle[7679686ddf2b4d96]::query::erase::Erased<[u8; 16usize]>>, false, true, false>, rustc_query_impl[b179d58b5687cd24]::plumbing::QueryCtxt, false>
      31:     0x7318e8d5ffa0 - rustc_query_impl[b179d58b5687cd24]::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace
      32:     0x7318e79037d2 - <rustc_mir_transform[654b2a96333f86ac]::known_panics_lint::KnownPanicsLint as rustc_mir_transform[654b2a96333f86ac]::pass_manager::MirLint>::run_lint
      33:     0x7318e7977f26 - rustc_mir_transform[654b2a96333f86ac]::pass_manager::run_passes_inner
      34:     0x7318e7738c97 - rustc_mir_transform[654b2a96333f86ac]::run_analysis_to_runtime_passes
      35:     0x7318e7738855 - rustc_mir_transform[654b2a96333f86ac]::mir_drops_elaborated_and_const_checked
      36:     0x7318e8b644f0 - rustc_query_impl[b179d58b5687cd24]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b179d58b5687cd24]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7679686ddf2b4d96]::query::erase::Erased<[u8; 8usize]>>
      37:     0x7318e8bf8e1c - <rustc_query_impl[b179d58b5687cd24]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2} as core[53647cb28d9a8e2]::ops::function::FnOnce<(rustc_middle[7679686ddf2b4d96]::ty::context::TyCtxt, rustc_span[3e13a556bd61225d]::def_id::LocalDefId)>>::call_once
      38:     0x7318e8b05df7 - rustc_query_system[582d53aef529b241]::query::plumbing::try_execute_query::<rustc_query_impl[b179d58b5687cd24]::DynamicConfig<rustc_data_structures[f42d743336959af9]::vec_cache::VecCache<rustc_span[3e13a556bd61225d]::def_id::LocalDefId, rustc_middle[7679686ddf2b4d96]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[582d53aef529b241]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[b179d58b5687cd24]::plumbing::QueryCtxt, false>
      39:     0x7318e8d340b8 - rustc_query_impl[b179d58b5687cd24]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
      40:     0x7318e281e802 - <rustc_middle[7679686ddf2b4d96]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[ecbe43cc18b7ed0d]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
      41:     0x7318e281666c - rustc_data_structures[f42d743336959af9]::sync::parallel::par_for_each_in::<&rustc_span[3e13a556bd61225d]::def_id::LocalDefId, &[rustc_span[3e13a556bd61225d]::def_id::LocalDefId], <rustc_middle[7679686ddf2b4d96]::ty::context::TyCtxt>::par_hir_body_owners<rustc_interface[ecbe43cc18b7ed0d]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}>
      42:     0x7318e27f9d6d - <rustc_session[5e4f5d64db36eed5]::session::Session>::time::<(), rustc_interface[ecbe43cc18b7ed0d]::passes::run_required_analyses::{closure#1}>
      43:     0x7318e27e1a6c - rustc_interface[ecbe43cc18b7ed0d]::passes::analysis
      44:     0x7318e8b64bfa - rustc_query_impl[b179d58b5687cd24]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b179d58b5687cd24]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7679686ddf2b4d96]::query::erase::Erased<[u8; 0usize]>>
      45:     0x7318e8bfc188 - <rustc_query_impl[b179d58b5687cd24]::query_impl::analysis::dynamic_query::{closure#2} as core[53647cb28d9a8e2]::ops::function::FnOnce<(rustc_middle[7679686ddf2b4d96]::ty::context::TyCtxt, ())>>::call_once
      46:     0x7318e8a95d71 - rustc_query_system[582d53aef529b241]::query::plumbing::try_execute_query::<rustc_query_impl[b179d58b5687cd24]::DynamicConfig<rustc_query_system[582d53aef529b241]::query::caches::SingleCache<rustc_middle[7679686ddf2b4d96]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[b179d58b5687cd24]::plumbing::QueryCtxt, false>
      47:     0x7318e8d32d44 - rustc_query_impl[b179d58b5687cd24]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
      48:     0x7318e25a735d - <std[c965b0aa6c3056df]::thread::local::LocalKey<core[53647cb28d9a8e2]::cell::Cell<*const ()>>>::with::<rustc_middle[7679686ddf2b4d96]::ty::context::tls::enter_context<<rustc_middle[7679686ddf2b4d96]::ty::context::GlobalCtxt>::enter<rustc_interface[ecbe43cc18b7ed0d]::passes::create_and_enter_global_ctxt<core[53647cb28d9a8e2]::option::Option<rustc_interface[ecbe43cc18b7ed0d]::queries::Linker>, rustc_driver_impl[6eadf89b26fc365d]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core[53647cb28d9a8e2]::option::Option<rustc_interface[ecbe43cc18b7ed0d]::queries::Linker>>::{closure#1}, core[53647cb28d9a8e2]::option::Option<rustc_interface[ecbe43cc18b7ed0d]::queries::Linker>>::{closure#0}, core[53647cb28d9a8e2]::option::Option<rustc_interface[ecbe43cc18b7ed0d]::queries::Linker>>
      49:     0x7318e25ec117 - <rustc_middle[7679686ddf2b4d96]::ty::context::TyCtxt>::create_global_ctxt::<core[53647cb28d9a8e2]::option::Option<rustc_interface[ecbe43cc18b7ed0d]::queries::Linker>, rustc_interface[ecbe43cc18b7ed0d]::passes::create_and_enter_global_ctxt<core[53647cb28d9a8e2]::option::Option<rustc_interface[ecbe43cc18b7ed0d]::queries::Linker>, rustc_driver_impl[6eadf89b26fc365d]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}>
      50:     0x7318e25a5150 - <rustc_interface[ecbe43cc18b7ed0d]::passes::create_and_enter_global_ctxt<core[53647cb28d9a8e2]::option::Option<rustc_interface[ecbe43cc18b7ed0d]::queries::Linker>, rustc_driver_impl[6eadf89b26fc365d]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[53647cb28d9a8e2]::ops::function::FnOnce<(&rustc_session[5e4f5d64db36eed5]::session::Session, rustc_middle[7679686ddf2b4d96]::ty::context::CurrentGcx, alloc[d932a86623700fa6]::sync::Arc<rustc_data_structures[f42d743336959af9]::jobserver::Proxy>, &std[c965b0aa6c3056df]::sync::once_lock::OnceLock<rustc_middle[7679686ddf2b4d96]::ty::context::GlobalCtxt>, &rustc_data_structures[f42d743336959af9]::sync::worker_local::WorkerLocal<rustc_middle[7679686ddf2b4d96]::arena::Arena>, &rustc_data_structures[f42d743336959af9]::sync::worker_local::WorkerLocal<rustc_hir[918c15de8fa92aec]::Arena>, rustc_driver_impl[6eadf89b26fc365d]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
      51:     0x7318e25904de - rustc_interface[ecbe43cc18b7ed0d]::passes::create_and_enter_global_ctxt::<core[53647cb28d9a8e2]::option::Option<rustc_interface[ecbe43cc18b7ed0d]::queries::Linker>, rustc_driver_impl[6eadf89b26fc365d]::run_compiler::{closure#0}::{closure#2}>
      52:     0x7318e2583fb6 - rustc_interface[ecbe43cc18b7ed0d]::interface::run_compiler::<(), rustc_driver_impl[6eadf89b26fc365d]::run_compiler::{closure#0}>::{closure#1}
      53:     0x7318e257bb5c - <scoped_tls[e1331b77299fe260]::ScopedKey<rustc_span[3e13a556bd61225d]::SessionGlobals>>::set::<rustc_interface[ecbe43cc18b7ed0d]::util::run_in_thread_with_globals<rustc_interface[ecbe43cc18b7ed0d]::util::run_in_thread_pool_with_globals<rustc_interface[ecbe43cc18b7ed0d]::interface::run_compiler<(), rustc_driver_impl[6eadf89b26fc365d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
      54:     0x7318e25d27de - rustc_span[3e13a556bd61225d]::create_session_globals_then::<(), rustc_interface[ecbe43cc18b7ed0d]::util::run_in_thread_with_globals<rustc_interface[ecbe43cc18b7ed0d]::util::run_in_thread_pool_with_globals<rustc_interface[ecbe43cc18b7ed0d]::interface::run_compiler<(), rustc_driver_impl[6eadf89b26fc365d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
      55:     0x7318e25af149 - std[c965b0aa6c3056df]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[ecbe43cc18b7ed0d]::util::run_in_thread_with_globals<rustc_interface[ecbe43cc18b7ed0d]::util::run_in_thread_pool_with_globals<rustc_interface[ecbe43cc18b7ed0d]::interface::run_compiler<(), rustc_driver_impl[6eadf89b26fc365d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
      56:     0x7318e2584da6 - <<std[c965b0aa6c3056df]::thread::Builder>::spawn_unchecked_<rustc_interface[ecbe43cc18b7ed0d]::util::run_in_thread_with_globals<rustc_interface[ecbe43cc18b7ed0d]::util::run_in_thread_pool_with_globals<rustc_interface[ecbe43cc18b7ed0d]::interface::run_compiler<(), rustc_driver_impl[6eadf89b26fc365d]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[53647cb28d9a8e2]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
      57:     0x7318ea365467 - std::sys::pal::unix::thread::Thread::new::thread_start::h208e5045c7868bf5
      58:     0x7318e14a27f1 - start_thread
                                   at ./nptl/pthread_create.c:448:8
      59:     0x7318e1533b5c - __GI___clone3
                                   at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78:0
      60:                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: please attach the file at `/home/fish/playground/issues/future-sync-ice/rustc-ice-2025-12-28T10_26_27-317572.txt` to your bug report
    
    query stack during panic:
    #0 [optimized_mir] optimizing MIR for `serve_request::{closure#0}`
    #1 [layout_of] computing layout of `{async fn body of serve_request()}`
    ... and 2 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
    error: future cannot be shared between threads safely
      --> src/main.rs:33:68
       |
    33 |     let _target: Pin<Box<dyn Future<Output = ()> + Send + Sync>> = tunnel_future;
       |                                                                    ^^^^^^^^^^^^^ future created by async block is not `Sync`
       |
       = help: the trait `Sync` is not implemented for `dyn Future<Output = Result<Upgraded, ()>> + Send`
    note: future is not `Sync` as it awaits another future which is not `Sync`
      --> src/main.rs:26:17
       |
    26 |         let _ = client.await;
       |                 ^^^^^^ await occurs here on type `Pin<Box<dyn Future<Output = Result<Upgraded, ()>> + Send>>`, which is not `Sync`
       = note: required for the cast from `Pin<Box<{async block@src/main.rs:25:34: 25:44}>>` to `Pin<Box<dyn Future<Output = ()> + Send + Sync>>`
    
    error: aborting due to 2 previous errors
    
    fish@ubuntu ~/p/i/future-sync-ice (main) [101]> ~/src/rust/build/host/stage1/bin/rustc -vV
    rustc 1.90.0-nightly (63f6845e5 2025-08-01)
    binary: rustc
    commit-hash: 63f6845e570305a92eaf855897768617366164d6
    commit-date: 2025-08-01
    host: x86_64-unknown-linux-gnu
    release: 1.90.0-nightly
    LLVM version: 20.1.8
    

    fish@ubuntu ~/p/i/future-sync-ice (main)>

    As this is my first post on GitHub, I’d appreciate any feedback on the process or if I missed any conventions.

  13. canmi21 commented on Dec 28, 2025

    @canmi21
    Author

    It’s possible we are looking at multiple related ICEs here.

    Yes,This is what I said before

    or it might be two ICE issues?

    But there's still one problem. What you said on your machine refers to the linux platform, right? However, the one we discovered before does not trigger on macOS, and the other one I mentioned can be triggered on both macOS and the playground(linux),So before we have a clear understanding of that conditional trigger on macOS, we cannot merge these two minimum reproduction codes

  14. feishiheng commented on Dec 31, 2025

    @feishiheng

    What you said on your machine refers to the linux platform, right?

    Yes.

    So before we have a clear understanding of that conditional trigger on macOS, we cannot merge these two minimum reproduction codes

    Indeed, this area needs further looking into.

    Sorry for the wait, I've been narrowing down the issue over the past few days. I found that the compiler does recognize the async block as non-Sync while evaluating obligations:

    Log details
    ...
           rustc_trait_selection::traits::fulfill::process_trait_obligation trait_obligation=Obligation(predicate=Binder { value: TraitPredicate(<dyn std::future::Future<Output = std::result::Result<Upgraded, ()>> + std::marker::Send as std::marker::Sync>, polarity:Positive), bound_vars: [] }, depth=8)
             0ms DEBUG rustc_trait_selection::traits::fulfill process_trait_obligation, select_result=Err(Unimplemented)
             0ms DEBUG rustc_trait_selection::traits::fulfill selecting trait at depth 8 yielded Err
             0ms DEBUG rustc_trait_selection::traits::fulfill return=Error(Unimplemented)
           rustc_trait_selection::traits::fulfill::process_trait_obligation trait_obligation=Obligation(predicate=Binder { value: TraitPredicate(<dyn std::future::Future<Output = std::result::Result<Upgraded, ()>> + std::marker::Send as std::marker::Sync>, polarity:Positive), bound_vars: [] }, depth=8)
    ...
       rustc_trait_selection::traits::fulfill::select obligation_forest_size=1
        10ms DEBUG rustc_trait_selection::traits::fulfill select(0 predicates remaining, 4 errors) done
       rustc_trait_selection::traits::fulfill::select obligation_forest_size=1
     rustc_trait_selection::traits::fulfill::try_evaluate_obligations 
      10ms DEBUG rustc_trait_selection::traits::fulfill return=[TrueError, TrueError, TrueError, TrueError]
    ...
    

    ice-150378.log

    However, I’m still struggling to find where this error gets swallowed, leading to the late-stage panic in MIR opts. I'll ask for some help on zulip and keep at it. Best wishes for the New Year!

  15. added a commit that references this issue on Jan 8, 2026
    d99b54a
  16. added a commit that references this issue on Jan 28, 2026
    d69d7f7
  17. cyrgani commented on Jun 28, 2026

    @cyrgani
    Contributor

    Fixed by #152327.

  18. removed
    needs-triage
    on Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitA-coercionsC-bugI-ICES-has-bisectionT-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions