rust-lang / rust-lang/rust

ICE: `cannot convert '{erased} to a region vid`

Open
#146,985 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

-Zvalidate-mir C-bug I-ICE S-has-mcve T-compiler WG-trait-system-refactor
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

auto-reduced (treereduce-rust):

//@compile-flags: --edition=2024 
fn invalid_future() -> impl Future {
    create_complex_future()
}

fn create_complex_future() -> impl Future<Output = impl ReturnsSend> {
    async { &|| async { invalid_future().await } }
}

fn coerce_impl_trait() -> impl Future<Output = impl Send> {
    create_complex_future()
}

trait ReturnsSend {}

impl<F, R> ReturnsSend for F
where
    F: Fn() -> R,
    R: Send,
{
}

fn main() {}

original:

//@ edition: 2021

use std::future::Future;

fn invalid_future() -> impl Future {
    create_complex_future()
}
//~^ ERROR `()` is not a future

fn create_complex_future() -> impl Future<Output = impl ReturnsSend> {
    async { &|| async { invalid_future().await } }
}

fn coerce_impl_trait() -> impl Future<Output = impl Send> {
    create_complex_future()
}

trait ReturnsSend {}

impl<F, R> ReturnsSend for F
where
    F: Fn() -> R,
    R: Send,
{
}

fn main() {}

Version information

rustc 1.92.0-nightly (e9385f9ee 2025-09-24)
binary: rustc
commit-hash: e9385f9eea0221ef295a188d49d16f8f5189abf1
commit-date: 2025-09-24
host: x86_64-unknown-linux-gnu
release: 1.92.0-nightly
LLVM version: 21.1.2

Possibly related line of code:
https://github.com/rust-lang/rust/blob/e9385f9eea0221ef295a188d49d16f8f5189abf1/compiler/rustc_borrowck/src/universal_regions.rs#L924-L936

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

Program output

error[E0720]: cannot resolve opaque type
 --> /tmp/icemaker_global_tempdir.aUMoW0s2aYlu/rustc_testrunner_tmpdir_reporting.gv3XOaBfqwDY/mvce.rs:1:24
  |
1 | fn invalid_future() -> impl Future {
  |                        ^^^^^^^^^^^ recursive opaque type
2 |     create_complex_future()
  |     ----------------------- returning here with type `impl Future<Output = impl ReturnsSend>`
...
5 | fn create_complex_future() -> impl Future<Output = impl ReturnsSend> {
  |                               -------------------------------------- returning this opaque type `impl Future<Output = impl ReturnsSend>`

error[E0720]: cannot resolve opaque type
 --> /tmp/icemaker_global_tempdir.aUMoW0s2aYlu/rustc_testrunner_tmpdir_reporting.gv3XOaBfqwDY/mvce.rs:5:31
  |
1 | fn invalid_future() -> impl Future {
  |                        ----------- returning this type `{async block@/tmp/icemaker_global_tempdir.aUMoW0s2aYlu/rustc_testrunner_tmpdir_reporting.gv3XOaBfqwDY/mvce.rs:6:5: 6:10}`
...
5 | fn create_complex_future() -> impl Future<Output = impl ReturnsSend> {
  |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive opaque type
6 |     async { &|| async { invalid_future().await } }
  |     ---------------------------------------------- returning here with type `{async block@/tmp/icemaker_global_tempdir.aUMoW0s2aYlu/rustc_testrunner_tmpdir_reporting.gv3XOaBfqwDY/mvce.rs:6:5: 6:10}`

error: future cannot be sent between threads safely
 --> /tmp/icemaker_global_tempdir.aUMoW0s2aYlu/rustc_testrunner_tmpdir_reporting.gv3XOaBfqwDY/mvce.rs:5:52
  |
5 | fn create_complex_future() -> impl Future<Output = impl ReturnsSend> {
  |                                                    ^^^^^^^^^^^^^^^^ future created by async block is not `Send`
  |
  = note: cannot satisfy `impl Future<Output = impl ReturnsSend>: Send`
note: future is not `Send` as it awaits another future which is not `Send`
 --> /tmp/icemaker_global_tempdir.aUMoW0s2aYlu/rustc_testrunner_tmpdir_reporting.gv3XOaBfqwDY/mvce.rs:6:25
  |
6 |     async { &|| async { invalid_future().await } }
  |                         ^^^^^^^^^^^^^^^^ await occurs here on type `impl Future`, which is not `Send`
note: required by a bound in an opaque type
 --> /tmp/icemaker_global_tempdir.aUMoW0s2aYlu/rustc_testrunner_tmpdir_reporting.gv3XOaBfqwDY/mvce.rs:5:57
  |
5 | fn create_complex_future() -> impl Future<Output = impl ReturnsSend> {
  |                                                         ^^^^^^^^^^^

error: internal compiler error: compiler/rustc_borrowck/src/universal_regions.rs:930:36: cannot convert `'{erased}` to a region vid


thread 'rustc' (814462) panicked at compiler/rustc_borrowck/src/universal_regions.rs:930:36:
Box<dyn Any>
stack backtrace:
   0:     0x7ff7b07ca183 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h4a7ebf3c97b63e54
   1:     0x7ff7b0e02004 - core::fmt::write::h5e5759cada453e98
   2:     0x7ff7b077ea01 - std::io::Write::write_fmt::h503716d2664a2999
   3:     0x7ff7b078fef2 - std::sys::backtrace::BacktraceLock::print::haede8464af6f6593
   4:     0x7ff7b0795e59 - std::panicking::default_hook::{{closure}}::hd1d459f3747276de
   5:     0x7ff7b0795983 - std::panicking::default_hook::h4615f5c23d4bd826
   6:     0x7ff7af7ba5d7 - std[4d5cf81698346de3]::panicking::update_hook::<alloc[62720e50f6bf8d96]::boxed::Box<rustc_driver_impl[743c5953b67fc26f]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7ff7b079627f - std::panicking::panic_with_hook::h290022751dfbc99c
   8:     0x7ff7af7f6861 - std[4d5cf81698346de3]::panicking::begin_panic::<rustc_errors[1d45ad03724e6281]::ExplicitBug>::{closure#0}
   9:     0x7ff7af7eac36 - std[4d5cf81698346de3]::sys::backtrace::__rust_end_short_backtrace::<std[4d5cf81698346de3]::panicking::begin_panic<rustc_errors[1d45ad03724e6281]::ExplicitBug>::{closure#0}, !>
  10:     0x7ff7af7e7b19 - std[4d5cf81698346de3]::panicking::begin_panic::<rustc_errors[1d45ad03724e6281]::ExplicitBug>
  11:     0x7ff7af801f51 - <rustc_errors[1d45ad03724e6281]::diagnostic::BugAbort as rustc_errors[1d45ad03724e6281]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7ff7afd946ca - rustc_middle[e8cb4ff3ac94f2d4]::util::bug::opt_span_bug_fmt::<rustc_span[80b09b3132128d8d]::span_encoding::Span>::{closure#0}
  13:     0x7ff7afd9488a - rustc_middle[e8cb4ff3ac94f2d4]::ty::context::tls::with_opt::<rustc_middle[e8cb4ff3ac94f2d4]::util::bug::opt_span_bug_fmt<rustc_span[80b09b3132128d8d]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7ff7afd8345b - rustc_middle[e8cb4ff3ac94f2d4]::ty::context::tls::with_context_opt::<rustc_middle[e8cb4ff3ac94f2d4]::ty::context::tls::with_opt<rustc_middle[e8cb4ff3ac94f2d4]::util::bug::opt_span_bug_fmt<rustc_span[80b09b3132128d8d]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7ff7ade7bbd0 - rustc_middle[e8cb4ff3ac94f2d4]::util::bug::bug_fmt
  16:     0x7ff7b175fa36 - <rustc_borrowck[6eb8f1ad86d728a7]::type_check::constraint_conversion::ConstraintConversion>::convert_all
  17:     0x7ff7b148b26d - <rustc_borrowck[6eb8f1ad86d728a7]::type_check::TypeChecker>::fully_perform_op::<(), rustc_borrowck[6eb8f1ad86d728a7]::type_check::InstantiateOpaqueType>
  18:     0x7ff7b1d7ea35 - <rustc_borrowck[6eb8f1ad86d728a7]::type_check::relate_tys::NllTypeRelating>::relate_opaques
  19:     0x7ff7b1e41b37 - <rustc_borrowck[6eb8f1ad86d728a7]::type_check::TypeChecker as rustc_middle[e8cb4ff3ac94f2d4]::mir::visit::Visitor>::visit_body
  20:     0x7ff7b1df6503 - rustc_borrowck[6eb8f1ad86d728a7]::type_check::type_check
  21:     0x7ff7b1ffaa81 - <rustc_borrowck[6eb8f1ad86d728a7]::root_cx::BorrowCheckRootCtxt>::do_mir_borrowck
  22:     0x7ff7b1ff3057 - rustc_borrowck[6eb8f1ad86d728a7]::mir_borrowck
  23:     0x7ff7b1ff2e1d - rustc_query_impl[c5c9f822c73cefb7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c5c9f822c73cefb7]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e8cb4ff3ac94f2d4]::query::erase::Erased<[u8; 8usize]>>
  24:     0x7ff7b0fd1644 - rustc_query_system[b5e6460b078a577c]::query::plumbing::try_execute_query::<rustc_query_impl[c5c9f822c73cefb7]::DynamicConfig<rustc_data_structures[a8767abe109b0a96]::vec_cache::VecCache<rustc_span[80b09b3132128d8d]::def_id::LocalDefId, rustc_middle[e8cb4ff3ac94f2d4]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[b5e6460b078a577c]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[c5c9f822c73cefb7]::plumbing::QueryCtxt, false>
  25:     0x7ff7b0fd5f89 - rustc_query_impl[c5c9f822c73cefb7]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7ff7b1e7a011 - rustc_hir_analysis[7f4f1816d2196b28]::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit
  27:     0x7ff7b1e79d8c - rustc_hir_analysis[7f4f1816d2196b28]::collect::type_of::type_of_opaque
  28:     0x7ff7b1e79c91 - rustc_query_impl[c5c9f822c73cefb7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c5c9f822c73cefb7]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e8cb4ff3ac94f2d4]::query::erase::Erased<[u8; 8usize]>>
  29:     0x7ff7b0e1af3a - rustc_query_system[b5e6460b078a577c]::query::plumbing::try_execute_query::<rustc_query_impl[c5c9f822c73cefb7]::DynamicConfig<rustc_query_system[b5e6460b078a577c]::query::caches::DefIdCache<rustc_middle[e8cb4ff3ac94f2d4]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[c5c9f822c73cefb7]::plumbing::QueryCtxt, false>
  30:     0x7ff7b2054d9b - rustc_query_impl[c5c9f822c73cefb7]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7ff7b173f8d8 - rustc_hir_analysis[7f4f1816d2196b28]::collect::type_of::type_of
  32:     0x7ff7b0e1c2a6 - rustc_query_impl[c5c9f822c73cefb7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c5c9f822c73cefb7]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e8cb4ff3ac94f2d4]::query::erase::Erased<[u8; 8usize]>>
  33:     0x7ff7b0e1af3a - rustc_query_system[b5e6460b078a577c]::query::plumbing::try_execute_query::<rustc_query_impl[c5c9f822c73cefb7]::DynamicConfig<rustc_query_system[b5e6460b078a577c]::query::caches::DefIdCache<rustc_middle[e8cb4ff3ac94f2d4]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[c5c9f822c73cefb7]::plumbing::QueryCtxt, false>
  34:     0x7ff7b0e1aadd - rustc_query_impl[c5c9f822c73cefb7]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7ff7b1e7a6ec - rustc_hir_analysis[7f4f1816d2196b28]::check::check::check_opaque
  36:     0x7ff7b1701984 - rustc_hir_analysis[7f4f1816d2196b28]::check::check::check_item_type
  37:     0x7ff7b16f9c39 - rustc_hir_analysis[7f4f1816d2196b28]::check::wfcheck::check_well_formed
  38:     0x7ff7b16f9c1b - rustc_query_impl[c5c9f822c73cefb7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c5c9f822c73cefb7]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e8cb4ff3ac94f2d4]::query::erase::Erased<[u8; 1usize]>>
  39:     0x7ff7b16f9492 - rustc_query_system[b5e6460b078a577c]::query::plumbing::try_execute_query::<rustc_query_impl[c5c9f822c73cefb7]::DynamicConfig<rustc_data_structures[a8767abe109b0a96]::vec_cache::VecCache<rustc_span[80b09b3132128d8d]::def_id::LocalDefId, rustc_middle[e8cb4ff3ac94f2d4]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[b5e6460b078a577c]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[c5c9f822c73cefb7]::plumbing::QueryCtxt, false>
  40:     0x7ff7b16f8f96 - rustc_query_impl[c5c9f822c73cefb7]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7ff7b16f6615 - rustc_hir_analysis[7f4f1816d2196b28]::check::wfcheck::check_type_wf
  42:     0x7ff7b16f64b5 - rustc_query_impl[c5c9f822c73cefb7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c5c9f822c73cefb7]::query_impl::check_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e8cb4ff3ac94f2d4]::query::erase::Erased<[u8; 1usize]>>
  43:     0x7ff7b1dc6288 - rustc_query_system[b5e6460b078a577c]::query::plumbing::try_execute_query::<rustc_query_impl[c5c9f822c73cefb7]::DynamicConfig<rustc_query_system[b5e6460b078a577c]::query::caches::SingleCache<rustc_middle[e8cb4ff3ac94f2d4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c5c9f822c73cefb7]::plumbing::QueryCtxt, false>
  44:     0x7ff7b1dc604e - rustc_query_impl[c5c9f822c73cefb7]::query_impl::check_type_wf::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7ff7b18e32dc - rustc_hir_analysis[7f4f1816d2196b28]::check_crate
  46:     0x7ff7b0fd2d30 - rustc_interface[e80a289d81ff7a8]::passes::analysis
  47:     0x7ff7b0fd29ed - rustc_query_impl[c5c9f822c73cefb7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c5c9f822c73cefb7]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e8cb4ff3ac94f2d4]::query::erase::Erased<[u8; 0usize]>>
  48:     0x7ff7b1dcc666 - rustc_query_system[b5e6460b078a577c]::query::plumbing::try_execute_query::<rustc_query_impl[c5c9f822c73cefb7]::DynamicConfig<rustc_query_system[b5e6460b078a577c]::query::caches::SingleCache<rustc_middle[e8cb4ff3ac94f2d4]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[c5c9f822c73cefb7]::plumbing::QueryCtxt, false>
  49:     0x7ff7b1dcc2bc - rustc_query_impl[c5c9f822c73cefb7]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  50:     0x7ff7b2093e0f - rustc_interface[e80a289d81ff7a8]::passes::create_and_enter_global_ctxt::<core[aa10cf8c11ee53a9]::option::Option<rustc_interface[e80a289d81ff7a8]::queries::Linker>, rustc_driver_impl[743c5953b67fc26f]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  51:     0x7ff7b20303fe - rustc_interface[e80a289d81ff7a8]::interface::run_compiler::<(), rustc_driver_impl[743c5953b67fc26f]::run_compiler::{closure#0}>::{closure#1}
  52:     0x7ff7b1f67e78 - std[4d5cf81698346de3]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[e80a289d81ff7a8]::util::run_in_thread_with_globals<rustc_interface[e80a289d81ff7a8]::util::run_in_thread_pool_with_globals<rustc_interface[e80a289d81ff7a8]::interface::run_compiler<(), rustc_driver_impl[743c5953b67fc26f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  53:     0x7ff7b1f67b48 - <<std[4d5cf81698346de3]::thread::Builder>::spawn_unchecked_<rustc_interface[e80a289d81ff7a8]::util::run_in_thread_with_globals<rustc_interface[e80a289d81ff7a8]::util::run_in_thread_pool_with_globals<rustc_interface[e80a289d81ff7a8]::interface::run_compiler<(), rustc_driver_impl[743c5953b67fc26f]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[aa10cf8c11ee53a9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  54:     0x7ff7b1f6dc4d - std::sys::thread::unix::Thread::new::thread_start::hbfb8ed69a8a2081e
  55:     0x7ff7ab8969cb - <unknown>
  56:     0x7ff7ab91aa0c - <unknown>
  57:                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.92.0-nightly (e9385f9ee 2025-09-24) running on x86_64-unknown-linux-gnu

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

query stack during panic:
#0 [mir_borrowck] borrow-checking `coerce_impl_trait`
#1 [type_of_opaque] computing type of opaque `coerce_impl_trait::{opaque#0}`
#2 [type_of] computing type of `coerce_impl_trait::{opaque#0}`
#3 [check_well_formed] checking that `coerce_impl_trait::{opaque#0}` is well-formed
#4 [check_type_wf] checking that types are well-formed
#5 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0601, E0720.
For more information about an error, try `rustc --explain E0601`.

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 reduced Rust program and reproduce it using the provided --edition=2024 command. Inspect compiler/rustc_borrowck/src/universal_regions.rs around line 930 and the borrow-checking stack frames; done means the program emits its ordinary diagnostics without triggering the internal compiler error.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.