Skip to content

ICE: Unsize coercion, but std::pin::Pin<std::boxed::Box<{async block .. isn't coercible #146210

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: --edition=2024 -Zvalidate-mir use ::core::pin::Pin; trait Foo { fn bar<'me, 'async_trait, T: Send>(x: &'me T) -> Pin<Box<dyn Future<Output = ()> + Send>> where 'me: 'async_trait; } impl Foo for () { fn bar<'me, 'async_trait, T: Send>(x: &'me T) -> Pin<Box<dyn Future<Output = ()> + Send>> where 'me: 'async_trait, { Box::pin(async move { let x = x; }) } } fn main() {}

original:

//@ edition:2018 use ::core::pin::Pin; use ::core::future::Future; use ::core::marker::Send; trait Foo { fn bar<'me, 'async_trait, T: Send>(x: &'me T) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'me: 'async_trait; } impl Foo for () { fn bar<'me, 'async_trait, T: Send>(x: &'me T) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>> where 'me:'async_trait { Box::pin( //@ edition:2018 async move { let x = x; } ) } } fn main() { }

Version information

rustc 1.91.0-nightly (71289c378 2025-09-04) binary: rustc commit-hash: 71289c378d0a406a4f537fe4001282d19362931f commit-date: 2025-09-04 host: x86_64-unknown-linux-gnu release: 1.91.0-nightly LLVM version: 21.1.0 

Possibly related line of code:

};
cfg_checker.visit_body(body);
cfg_checker.check_cleanup_control_flow();
// Also run the TypeChecker.
for (location, msg) in validate_types(tcx, typing_env, body, body) {
cfg_checker.fail(location, msg);
}
if let MirPhase::Runtime(_) = body.phase
&& let ty::InstanceKind::Item(_) = body.source.instance
&& body.has_free_regions()
{

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc --edition=2024 -Zvalidate-mir

Program output

warning: unused variable: `x` --> /tmp/icemaker_global_tempdir.WalRtMxhm63X/rustc_testrunner_tmpdir_reporting.WqFA43bpg2gM/mvce.rs:15:17 | 15 | let x = x; | ^ help: if this is intentional, prefix it with an underscore: `_x` | = note: `#[warn(unused_variables)]` (part of `#[warn(unused)]`) on by default error: internal compiler error: compiler/rustc_mir_transform/src/validate.rs:80:25: broken MIR in Item(DefId(0:10 ~ mvce[5d7d]::{impl#0}::bar)) (after pass CheckForceInline) at bb1[0]: Unsize coercion, but `std::pin::Pin<std::boxed::Box<{async block@/tmp/icemaker_global_tempdir.WalRtMxhm63X/rustc_testrunner_tmpdir_reporting.WqFA43bpg2gM/mvce.rs:14:18: 14:28}>>` isn't coercible to `std::pin::Pin<std::boxed::Box<dyn std::future::Future<Output = ()> + std::marker::Send>>` --> /tmp/icemaker_global_tempdir.WalRtMxhm63X/rustc_testrunner_tmpdir_reporting.WqFA43bpg2gM/mvce.rs:14:9 | 14 | / Box::pin(async move { 15 | | let x = x; 16 | | }) | |__________^ thread 'rustc' (1981516) panicked at compiler/rustc_mir_transform/src/validate.rs:80:25: Box<dyn Any> stack backtrace: 0: 0x7f15a0c75fd2 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h74535c69a9a8851c 1: 0x7f15a140c57c - core::fmt::write::h617ef057c538ffbe 2: 0x7f15a0c2a251 - std::io::Write::write_fmt::haeef701e34a0f1ce 3: 0x7f15a0c3b8d2 - std::sys::backtrace::BacktraceLock::print::hc779bb6277bee776 4: 0x7f15a0c41ba7 - std::panicking::default_hook::{{closure}}::h375a85ea81672879 5: 0x7f15a0c416b3 - std::panicking::default_hook::h6cf8c92021730d42 6: 0x7f159fc63691 - std[a85058167e77f399]::panicking::update_hook::<alloc[f3ac3bcb91ff4184]::boxed::Box<rustc_driver_impl[8ae33f5ddd6f22c2]::install_ice_hook::{closure#1}>>::{closure#0} 7: 0x7f15a0c420af - std::panicking::panic_with_hook::hb1f4786dce1429bc 8: 0x7f159fca0fe1 - std[a85058167e77f399]::panicking::begin_panic::<rustc_errors[55184e806260cfe4]::ExplicitBug>::{closure#0} 9: 0x7f159fc95326 - std[a85058167e77f399]::sys::backtrace::__rust_end_short_backtrace::<std[a85058167e77f399]::panicking::begin_panic<rustc_errors[55184e806260cfe4]::ExplicitBug>::{closure#0}, !> 10: 0x7f159fc9469e - std[a85058167e77f399]::panicking::begin_panic::<rustc_errors[55184e806260cfe4]::ExplicitBug> 11: 0x7f159fcacc01 - <rustc_errors[55184e806260cfe4]::diagnostic::BugAbort as rustc_errors[55184e806260cfe4]::diagnostic::EmissionGuarantee>::emit_producing_guarantee 12: 0x7f15a022e5dc - <rustc_errors[55184e806260cfe4]::DiagCtxtHandle>::span_bug::<rustc_span[e82c85b666ab7901]::span_encoding::Span, alloc[f3ac3bcb91ff4184]::string::String> 13: 0x7f15a0255757 - rustc_middle[5ded7ef5e9c99589]::util::bug::opt_span_bug_fmt::<rustc_span[e82c85b666ab7901]::span_encoding::Span>::{closure#0} 14: 0x7f15a025594a - rustc_middle[5ded7ef5e9c99589]::ty::context::tls::with_opt::<rustc_middle[5ded7ef5e9c99589]::util::bug::opt_span_bug_fmt<rustc_span[e82c85b666ab7901]::span_encoding::Span>::{closure#0}, !>::{closure#0} 15: 0x7f15a024407b - rustc_middle[5ded7ef5e9c99589]::ty::context::tls::with_context_opt::<rustc_middle[5ded7ef5e9c99589]::ty::context::tls::with_opt<rustc_middle[5ded7ef5e9c99589]::util::bug::opt_span_bug_fmt<rustc_span[e82c85b666ab7901]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !> 16: 0x7f159e102f67 - rustc_middle[5ded7ef5e9c99589]::util::bug::span_bug_fmt::<rustc_span[e82c85b666ab7901]::span_encoding::Span> 17: 0x7f159ebfe16f - <rustc_mir_transform[f939db7989ace53a]::validate::CfgChecker>::fail::<alloc[f3ac3bcb91ff4184]::string::String> 18: 0x7f15a20fb526 - <rustc_mir_transform[f939db7989ace53a]::validate::Validator as rustc_mir_transform[f939db7989ace53a]::pass_manager::MirPass>::run_pass 19: 0x7f159ec2f095 - rustc_mir_transform[f939db7989ace53a]::pass_manager::validate_body 20: 0x7f15a1407136 - rustc_query_impl[9354df03bc15753a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9354df03bc15753a]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5ded7ef5e9c99589]::query::erase::Erased<[u8; 8usize]>> 21: 0x7f15a15f8f05 - rustc_query_system[58e4f3e481076de2]::query::plumbing::try_execute_query::<rustc_query_impl[9354df03bc15753a]::DynamicConfig<rustc_data_structures[59c3a3e48a0cb88]::vec_cache::VecCache<rustc_span[e82c85b666ab7901]::def_id::LocalDefId, rustc_middle[5ded7ef5e9c99589]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[58e4f3e481076de2]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[9354df03bc15753a]::plumbing::QueryCtxt, false> 22: 0x7f15a15f8a09 - rustc_query_impl[9354df03bc15753a]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace 23: 0x7f15a2030eda - rustc_mir_build[f65013b02413be2b]::check_unsafety::check_unsafety 24: 0x7f15a2030ae7 - rustc_query_impl[9354df03bc15753a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9354df03bc15753a]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5ded7ef5e9c99589]::query::erase::Erased<[u8; 0usize]>> 25: 0x7f15a15f125b - rustc_query_system[58e4f3e481076de2]::query::plumbing::try_execute_query::<rustc_query_impl[9354df03bc15753a]::DynamicConfig<rustc_data_structures[59c3a3e48a0cb88]::vec_cache::VecCache<rustc_span[e82c85b666ab7901]::def_id::LocalDefId, rustc_middle[5ded7ef5e9c99589]::query::erase::Erased<[u8; 0usize]>, rustc_query_system[58e4f3e481076de2]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[9354df03bc15753a]::plumbing::QueryCtxt, false> 26: 0x7f15a15f0e8b - rustc_query_impl[9354df03bc15753a]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace 27: 0x7f15a15f0373 - <rustc_middle[5ded7ef5e9c99589]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[b9c81810830046cc]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0} 28: 0x7f15a15edcdb - rustc_interface[b9c81810830046cc]::passes::analysis 29: 0x7f15a15ed18d - rustc_query_impl[9354df03bc15753a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[9354df03bc15753a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[5ded7ef5e9c99589]::query::erase::Erased<[u8; 0usize]>> 30: 0x7f15a24b9920 - rustc_query_system[58e4f3e481076de2]::query::plumbing::try_execute_query::<rustc_query_impl[9354df03bc15753a]::DynamicConfig<rustc_query_system[58e4f3e481076de2]::query::caches::SingleCache<rustc_middle[5ded7ef5e9c99589]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[9354df03bc15753a]::plumbing::QueryCtxt, false> 31: 0x7f15a24b9576 - rustc_query_impl[9354df03bc15753a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 32: 0x7f15a27c1576 - rustc_interface[b9c81810830046cc]::passes::create_and_enter_global_ctxt::<core[388173e3ebade246]::option::Option<rustc_interface[b9c81810830046cc]::queries::Linker>, rustc_driver_impl[8ae33f5ddd6f22c2]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0} 33: 0x7f15a26a3f85 - rustc_interface[b9c81810830046cc]::interface::run_compiler::<(), rustc_driver_impl[8ae33f5ddd6f22c2]::run_compiler::{closure#0}>::{closure#1} 34: 0x7f15a259f403 - std[a85058167e77f399]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[b9c81810830046cc]::util::run_in_thread_with_globals<rustc_interface[b9c81810830046cc]::util::run_in_thread_pool_with_globals<rustc_interface[b9c81810830046cc]::interface::run_compiler<(), rustc_driver_impl[8ae33f5ddd6f22c2]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()> 35: 0x7f15a259f0c8 - <<std[a85058167e77f399]::thread::Builder>::spawn_unchecked_<rustc_interface[b9c81810830046cc]::util::run_in_thread_with_globals<rustc_interface[b9c81810830046cc]::util::run_in_thread_pool_with_globals<rustc_interface[b9c81810830046cc]::interface::run_compiler<(), rustc_driver_impl[8ae33f5ddd6f22c2]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[388173e3ebade246]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 36: 0x7f15a25a55ef - std::sys::pal::unix::thread::Thread::new::thread_start::hf0c6c3cf2c1ee824 37: 0x7f159bc969cb - <unknown> 38: 0x7f159bd1aa0c - <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.91.0-nightly (71289c378 2025-09-04) running on x86_64-unknown-linux-gnu note: compiler flags: -Z validate-mir -Z dump-mir-dir=dir query stack during panic: #0 [mir_built] building MIR for `<impl at /tmp/icemaker_global_tempdir.WalRtMxhm63X/rustc_testrunner_tmpdir_reporting.WqFA43bpg2gM/mvce.rs:9:1: 9:16>::bar` #1 [check_unsafety] unsafety-checking `<impl at /tmp/icemaker_global_tempdir.WalRtMxhm63X/rustc_testrunner_tmpdir_reporting.WqFA43bpg2gM/mvce.rs:9:1: 9:16>::bar` #2 [analysis] running analysis passes on this crate end of query stack error: aborting due to 1 previous error; 1 warning emitted 

Metadata

Metadata

Assignees

No one assigned

    Labels

    -Zvalidate-mirUnstable option: MIR validationC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions