rust-lang / rust-lang/rust

Opaque Future Type crashed compiler :) Called `Option::unwrap()` on a `None` value

Open
#141,268 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-ICE S-needs-info S-needs-repro T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

This is curiosity of our friends that will overthrow us AI :)

" The ICE is happening when the compiler tries to type-check async fn foo(...) -> ! (and its call into the generic bar) and ends up in a busted report_similar_impl_candidates path.

Code

Concretely, this signature:

#[embassy_executor::task]
async fn foo(A: SomeTypeIMatching) -> ! {
    bar(A).await
}

—combined with your generic async method

pub async fn Bar<A: OtherGenericType + 'static>(a: A) -> ! { … }

—produces an opaque future type that the compiler can’t correctly resolve, and that eventually hits an internal None.unwrap().

Solution (work around -.-)

I explicitly defined the types (though i didn't want to) within the module that is being called. This no longer has the error because of that.

Meta

I'm using container...

FROM espressif/idf-rust:esp32_latest
USER root
WORKDIR /owb
COPY . /owb
RUN chown -R esp:esp /owb
USER esp

ENV PATH="/home/esp/.rustup/toolchains/esp/xtensa-esp-elf/esp-14.2.0_20240906/xtensa-esp-elf/bin:/home/esp/.cargo/bin:$PATH"

CMD ["/bin/bash"]
Error output
thread 'rustc' panicked at compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs:1824:44:
called `Option::unwrap()` on a `None` value
Backtrace

thread 'rustc' panicked at compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs:1824:44:
called `Option::unwrap()` on a `None` value
stack backtrace:
   0:     0x7c13b4b5d604 - std::backtrace::Backtrace::create::hc917666e49edcc67
   1:     0x7c13b4b5d555 - std::backtrace::Backtrace::force_capture::h0456361e9223ac44
   2:     0x7c13ada3864f - <alloc[326f412a89e5869a]::boxed::Box<rustc_driver_impl[11120e4604616cb8]::install_ice_hook::{closure#0}> as core[19c24f2bf64da68c]::ops::function::Fn<(&dyn for<'a, 'b> core[19c24f2bf64da68c]::ops::function::Fn<(&'a std[3c1f75e497f5fe1]::panic::PanicHookInfo<'b>,), Output = ()> + core[19c24f2bf64da68c]::marker::Send + core[19c24f2bf64da68c]::marker::Sync, &std[3c1f75e497f5fe1]::panic::PanicHookInfo)>>::call
   3:     0x7c13b4b5f40d - std::panicking::rust_panic_with_hook::h81634076ecf27e23
   4:     0x7c13b4b47216 - std::panicking::begin_panic_handler::{{closure}}::hc739c40ce3082128
   5:     0x7c13b4b46ee9 - std::sys::backtrace::__rust_end_short_backtrace::h1aa68d986880e1b9
   6:     0x7c13b4b5eecc - rust_begin_unwind
   7:     0x7c13b4bea690 - core::panicking::panic_fmt::ha0d34e63f154cecc
   8:     0x7c13b4bea71c - core::panicking::panic::h80c9defdaf74510a
   9:     0x7c13b4be5e69 - core::option::unwrap_failed::h6a0ccd5c3d009ffb
  10:     0x7c13b37e6f08 - <rustc_trait_selection[a8595092de99c364]::error_reporting::TypeErrCtxt>::report_similar_impl_candidates
  11:     0x7c13b3811e8a - <rustc_trait_selection[a8595092de99c364]::error_reporting::TypeErrCtxt>::report_fulfillment_errors
  12:     0x7c13b188c491 - <rustc_hir_typeck[c37f261e904b2689]::fn_ctxt::FnCtxt>::report_ambiguity_errors
  13:     0x7c13b1b1da72 - rustc_hir_typeck[c37f261e904b2689]::typeck
  14:     0x7c13b3008ca0 - rustc_query_impl[139339c607ef3f83]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[139339c607ef3f83]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 8usize]>>
  15:     0x7c13b332260c - <rustc_query_impl[139339c607ef3f83]::query_impl::typeck::dynamic_query::{closure#2} as core[19c24f2bf64da68c]::ops::function::FnOnce<(rustc_middle[8ac56485c6056ae4]::ty::context::TyCtxt, rustc_span[6216dc77597e7c6d]::def_id::LocalDefId)>>::call_once
  16:     0x7c13b310423c - rustc_query_system[58145ffb095b1890]::query::plumbing::try_execute_query::<rustc_query_impl[139339c607ef3f83]::DynamicConfig<rustc_data_structures[7490c3560e13ac19]::vec_cache::VecCache<rustc_span[6216dc77597e7c6d]::def_id::LocalDefId, rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[58145ffb095b1890]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[139339c607ef3f83]::plumbing::QueryCtxt, false>
  17:     0x7c13b3205a16 - rustc_query_impl[139339c607ef3f83]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  18:     0x7c13b1de4e85 - rustc_middle[8ac56485c6056ae4]::query::plumbing::query_get_at::<rustc_data_structures[7490c3560e13ac19]::vec_cache::VecCache<rustc_span[6216dc77597e7c6d]::def_id::LocalDefId, rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[58145ffb095b1890]::dep_graph::graph::DepNodeIndex>>
  19:     0x7c13b1e0d864 - rustc_hir_analysis[f2f24cae42e238bb]::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit
  20:     0x7c13b1e57f7a - rustc_hir_analysis[f2f24cae42e238bb]::collect::type_of::type_of_opaque
  21:     0x7c13b30029c5 - rustc_query_impl[139339c607ef3f83]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[139339c607ef3f83]::query_impl::type_of_opaque::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 8usize]>>
  22:     0x7c13b33d62c0 - <rustc_query_impl[139339c607ef3f83]::query_impl::type_of_opaque::dynamic_query::{closure#2} as core[19c24f2bf64da68c]::ops::function::FnOnce<(rustc_middle[8ac56485c6056ae4]::ty::context::TyCtxt, rustc_span[6216dc77597e7c6d]::def_id::DefId)>>::call_once
  23:     0x7c13b30575d8 - rustc_query_system[58145ffb095b1890]::query::plumbing::try_execute_query::<rustc_query_impl[139339c607ef3f83]::DynamicConfig<rustc_query_system[58145ffb095b1890]::query::caches::DefIdCache<rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[139339c607ef3f83]::plumbing::QueryCtxt, false>
  24:     0x7c13b31f12f9 - rustc_query_impl[139339c607ef3f83]::query_impl::type_of_opaque::get_query_non_incr::__rust_end_short_backtrace
  25:     0x7c13b1e351cc - rustc_middle[8ac56485c6056ae4]::query::plumbing::query_get_at::<rustc_query_system[58145ffb095b1890]::query::caches::DefIdCache<rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 8usize]>>>
  26:     0x7c13b1e565d9 - rustc_hir_analysis[f2f24cae42e238bb]::collect::type_of::type_of
  27:     0x7c13b3008d42 - rustc_query_impl[139339c607ef3f83]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[139339c607ef3f83]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 8usize]>>
  28:     0x7c13b31ed340 - <rustc_query_impl[139339c607ef3f83]::query_impl::type_of::dynamic_query::{closure#2} as core[19c24f2bf64da68c]::ops::function::FnOnce<(rustc_middle[8ac56485c6056ae4]::ty::context::TyCtxt, rustc_span[6216dc77597e7c6d]::def_id::DefId)>>::call_once
  29:     0x7c13b30575d8 - rustc_query_system[58145ffb095b1890]::query::plumbing::try_execute_query::<rustc_query_impl[139339c607ef3f83]::DynamicConfig<rustc_query_system[58145ffb095b1890]::query::caches::DefIdCache<rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[139339c607ef3f83]::plumbing::QueryCtxt, false>
  30:     0x7c13b31f0d39 - rustc_query_impl[139339c607ef3f83]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7c13b1de61dc - rustc_middle[8ac56485c6056ae4]::query::plumbing::query_get_at::<rustc_query_system[58145ffb095b1890]::query::caches::DefIdCache<rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 8usize]>>>
  32:     0x7c13b1df664d - rustc_hir_analysis[f2f24cae42e238bb]::check::check::check_item_type
  33:     0x7c13b1e473ad - rustc_hir_analysis[f2f24cae42e238bb]::check::wfcheck::check_well_formed
  34:     0x7c13b3003ff0 - rustc_query_impl[139339c607ef3f83]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[139339c607ef3f83]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 1usize]>>
  35:     0x7c13b32e504c - <rustc_query_impl[139339c607ef3f83]::query_impl::check_well_formed::dynamic_query::{closure#2} as core[19c24f2bf64da68c]::ops::function::FnOnce<(rustc_middle[8ac56485c6056ae4]::ty::context::TyCtxt, rustc_span[6216dc77597e7c6d]::def_id::LocalDefId)>>::call_once
  36:     0x7c13b30fc6cd - rustc_query_system[58145ffb095b1890]::query::plumbing::try_execute_query::<rustc_query_impl[139339c607ef3f83]::DynamicConfig<rustc_data_structures[7490c3560e13ac19]::vec_cache::VecCache<rustc_span[6216dc77597e7c6d]::def_id::LocalDefId, rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[58145ffb095b1890]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[139339c607ef3f83]::plumbing::QueryCtxt, false>
  37:     0x7c13b321882d - rustc_query_impl[139339c607ef3f83]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7c13b1d631b3 - rustc_middle[8ac56485c6056ae4]::query::plumbing::query_ensure_error_guaranteed::<rustc_data_structures[7490c3560e13ac19]::vec_cache::VecCache<rustc_span[6216dc77597e7c6d]::def_id::LocalDefId, rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[58145ffb095b1890]::dep_graph::graph::DepNodeIndex>, ()>
  39:     0x7c13b1d571bf - <rustc_middle[8ac56485c6056ae4]::hir::ModuleItems>::par_opaques::<rustc_hir_analysis[f2f24cae42e238bb]::check::wfcheck::check_mod_type_wf::{closure#4}>
  40:     0x7c13b1e50a5b - rustc_hir_analysis[f2f24cae42e238bb]::check::wfcheck::check_mod_type_wf
  41:     0x7c13b3003fc0 - rustc_query_impl[139339c607ef3f83]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[139339c607ef3f83]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 1usize]>>
  42:     0x7c13b32c5ffc - <rustc_query_impl[139339c607ef3f83]::query_impl::check_mod_type_wf::dynamic_query::{closure#2} as core[19c24f2bf64da68c]::ops::function::FnOnce<(rustc_middle[8ac56485c6056ae4]::ty::context::TyCtxt, rustc_span[6216dc77597e7c6d]::def_id::LocalModDefId)>>::call_once
  43:     0x7c13b30a780c - rustc_query_system[58145ffb095b1890]::query::plumbing::try_execute_query::<rustc_query_impl[139339c607ef3f83]::DynamicConfig<rustc_query_system[58145ffb095b1890]::query::caches::DefaultCache<rustc_span[6216dc77597e7c6d]::def_id::LocalModDefId, rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[139339c607ef3f83]::plumbing::QueryCtxt, false>
  44:     0x7c13b320544d - rustc_query_impl[139339c607ef3f83]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7c13b1d5891d - <rustc_data_structures[7490c3560e13ac19]::sync::parallel::ParallelGuard>::run::<(), rustc_data_structures[7490c3560e13ac19]::sync::parallel::par_for_each_in<&rustc_hir[5d3ee39a220d4a50]::hir_id::OwnerId, &[rustc_hir[5d3ee39a220d4a50]::hir_id::OwnerId], <rustc_middle[8ac56485c6056ae4]::hir::map::Map>::par_for_each_module<rustc_hir_analysis[f2f24cae42e238bb]::check_crate::{closure#0}::{closure#0}>::{closure#0}>::{closure#0}::{closure#1}::{closure#0}>
  46:     0x7c13b1c43cde - <rustc_session[ae442a1a39ad9b5f]::session::Session>::time::<(), rustc_hir_analysis[f2f24cae42e238bb]::check_crate::{closure#0}>
  47:     0x7c13b1b58f8f - rustc_hir_analysis[f2f24cae42e238bb]::check_crate
  48:     0x7c13adccce29 - rustc_interface[fa0ba49808ba01a1]::passes::analysis
  49:     0x7c13b3008d7e - rustc_query_impl[139339c607ef3f83]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[139339c607ef3f83]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 1usize]>>
  50:     0x7c13b33885e8 - <rustc_query_impl[139339c607ef3f83]::query_impl::analysis::dynamic_query::{closure#2} as core[19c24f2bf64da68c]::ops::function::FnOnce<(rustc_middle[8ac56485c6056ae4]::ty::context::TyCtxt, ())>>::call_once
  51:     0x7c13b3061a6c - rustc_query_system[58145ffb095b1890]::query::plumbing::try_execute_query::<rustc_query_impl[139339c607ef3f83]::DynamicConfig<rustc_query_system[58145ffb095b1890]::query::caches::SingleCache<rustc_middle[8ac56485c6056ae4]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[139339c607ef3f83]::plumbing::QueryCtxt, false>
  52:     0x7c13b31f2243 - rustc_query_impl[139339c607ef3f83]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  53:     0x7c13ad9a5bfe - <rustc_middle[8ac56485c6056ae4]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[11120e4604616cb8]::run_compiler::{closure#0}::{closure#1}::{closure#6}, core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>
  54:     0x7c13ad9eed65 - <rustc_interface[fa0ba49808ba01a1]::interface::Compiler>::enter::<rustc_driver_impl[11120e4604616cb8]::run_compiler::{closure#0}::{closure#1}, core[19c24f2bf64da68c]::result::Result<core[19c24f2bf64da68c]::option::Option<rustc_interface[fa0ba49808ba01a1]::queries::Linker>, rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>
  55:     0x7c13ada70ff2 - <scoped_tls[4cdd8087fbbd96d6]::ScopedKey<rustc_span[6216dc77597e7c6d]::SessionGlobals>>::set::<rustc_interface[fa0ba49808ba01a1]::util::run_in_thread_with_globals<rustc_interface[fa0ba49808ba01a1]::util::run_in_thread_pool_with_globals<rustc_interface[fa0ba49808ba01a1]::interface::run_compiler<core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>, rustc_driver_impl[11120e4604616cb8]::run_compiler::{closure#0}>::{closure#1}, core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>::{closure#0}, core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>
  56:     0x7c13ada25a9c - rustc_span[6216dc77597e7c6d]::create_session_globals_then::<core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>, rustc_interface[fa0ba49808ba01a1]::util::run_in_thread_with_globals<rustc_interface[fa0ba49808ba01a1]::util::run_in_thread_pool_with_globals<rustc_interface[fa0ba49808ba01a1]::interface::run_compiler<core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>, rustc_driver_impl[11120e4604616cb8]::run_compiler::{closure#0}>::{closure#1}, core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>::{closure#0}, core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}>
  57:     0x7c13ada798e2 - std[3c1f75e497f5fe1]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[fa0ba49808ba01a1]::util::run_in_thread_with_globals<rustc_interface[fa0ba49808ba01a1]::util::run_in_thread_pool_with_globals<rustc_interface[fa0ba49808ba01a1]::interface::run_compiler<core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>, rustc_driver_impl[11120e4604616cb8]::run_compiler::{closure#0}>::{closure#1}, core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>::{closure#0}, core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>
  58:     0x7c13ada563c1 - <<std[3c1f75e497f5fe1]::thread::Builder>::spawn_unchecked_<rustc_interface[fa0ba49808ba01a1]::util::run_in_thread_with_globals<rustc_interface[fa0ba49808ba01a1]::util::run_in_thread_pool_with_globals<rustc_interface[fa0ba49808ba01a1]::interface::run_compiler<core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>, rustc_driver_impl[11120e4604616cb8]::run_compiler::{closure#0}>::{closure#1}, core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>::{closure#0}, core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[19c24f2bf64da68c]::result::Result<(), rustc_span[6216dc77597e7c6d]::ErrorGuaranteed>>::{closure#1} as core[19c24f2bf64da68c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  59:     0x7c13b4b9c5bb - std::sys::pal::unix::thread::Thread::new::thread_start::hba5155a029b79976
  60:     0x7c13aa3df1c4 - <unknown>
  61:     0x7c13aa45eac0 - __clone
  62:                0x0 - <unknown>


rustc version: 1.84.0-nightly (b0bd11bcc 2025-01-10) (1.84.0.0)
platform: x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `__led_task_task`
#1 [type_of_opaque] computing type of opaque `__led_task_task::{opaque#0}`
#2 [type_of] computing type of `__led_task_task::{opaque#0}`
#3 [check_well_formed] checking that `__led_task_task::{opaque#0}` is well-formed
#4 [check_mod_type_wf] checking that types are well-formed in top-level module
#5 [analysis] running analysis passes on this crate
end of query stack

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 at compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs near report_similar_impl_candidates, then trace the opaque-future and type-checking paths named in the backtrace. Reproduce the async foo/bar example with the reported toolchain context. Done means this case no longer causes rustc to panic at Option::unwrap() and instead completes compilation or emits a normal diagnostic.

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.