Skip to content

ICE: expected async fn in trait to return an RPITIT #136286

Description

@matthiaskrgr

snippet:

//@compile-flags: --edition=2024
#![feature(async_fn_in_dyn_trait)]
trait A {
    async fn b(self: A);
}

Version information

rustc 1.86.0-nightly (e6f12c8b7 2025-01-30)
binary: rustc
commit-hash: e6f12c8b7d8d5c821c32fb2739ea01d1d874c58a
commit-date: 2025-01-30
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Possibly related line of code:

if tcx.asyncness(fn_def_id).is_async() {
// FIXME(async_fn_in_dyn_trait): Think of a better way to unify these code paths
// to issue an appropriate feature suggestion when users try to use AFIDT.
// Obviously we must only do this once AFIDT is finished enough to actually be usable.
if tcx.features().async_fn_in_dyn_trait() {
let ty::Alias(ty::Projection, proj) = *ty.kind() else {
bug!("expected async fn in trait to return an RPITIT");
};
assert!(tcx.is_impl_trait_in_trait(proj.def_id));
// FIXME(async_fn_in_dyn_trait): We should check that this bound is legal too,
// and stop relying on `async fn` in the definition.
for bound in tcx.item_bounds(proj.def_id).instantiate(tcx, proj.args) {

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

Program output

warning: the feature `async_fn_in_dyn_trait` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.7pZXHQ7HZKbf/rustc_testrunner_tmpdir_reporting.rOKT2kZqYC9F/mvce.rs:1:12
  |
1 | #![feature(async_fn_in_dyn_trait)]
  |            ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #133119 <https://github.com/rust-lang/rust/issues/133119> for more information
  = note: `#[warn(incomplete_features)]` on by default

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.7pZXHQ7HZKbf/rustc_testrunner_tmpdir_reporting.rOKT2kZqYC9F/mvce.rs:4:2
  |
4 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.7pZXHQ7HZKbf/rustc_testrunner_tmpdir_reporting.rOKT2kZqYC9F/mvce.rs`

error: internal compiler error: compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs:913:17: expected async fn in trait to return an RPITIT


thread 'rustc' panicked at compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs:913:17:
Box<dyn Any>
stack backtrace:
   0:     0x7b4b4522d410 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h32b76eca82481332
   1:     0x7b4b45a138e6 - core::fmt::write::h6aab99975a3e1e0d
   2:     0x7b4b46904bd1 - std::io::Write::write_fmt::h07e3041152301b92
   3:     0x7b4b4522d272 - std::sys::backtrace::BacktraceLock::print::h11198f536c423f0e
   4:     0x7b4b4522f6f2 - std::panicking::default_hook::{{closure}}::hedf2549fe54c612d
   5:     0x7b4b4522f57a - std::panicking::default_hook::h5cafcda49fcb475d
   6:     0x7b4b44389e99 - std[65c60797a113df8d]::panicking::update_hook::<alloc[26d4a3e3ec5433a5]::boxed::Box<rustc_driver_impl[88e265ae9927f55c]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7b4b45230273 - std::panicking::rust_panic_with_hook::h9e0ce671ec08e8dc
   8:     0x7b4b443c4c21 - std[65c60797a113df8d]::panicking::begin_panic::<rustc_errors[23526cdfd16e48c4]::ExplicitBug>::{closure#0}
   9:     0x7b4b443b9b26 - std[65c60797a113df8d]::sys::backtrace::__rust_end_short_backtrace::<std[65c60797a113df8d]::panicking::begin_panic<rustc_errors[23526cdfd16e48c4]::ExplicitBug>::{closure#0}, !>
  10:     0x7b4b443b67ed - std[65c60797a113df8d]::panicking::begin_panic::<rustc_errors[23526cdfd16e48c4]::ExplicitBug>
  11:     0x7b4b443ceb71 - <rustc_errors[23526cdfd16e48c4]::diagnostic::BugAbort as rustc_errors[23526cdfd16e48c4]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7b4b449b1ba3 - rustc_middle[c95cf357e72e9a85]::util::bug::opt_span_bug_fmt::<rustc_span[cb34d841a75ac9bc]::span_encoding::Span>::{closure#0}
  13:     0x7b4b4499ab0a - rustc_middle[c95cf357e72e9a85]::ty::context::tls::with_opt::<rustc_middle[c95cf357e72e9a85]::util::bug::opt_span_bug_fmt<rustc_span[cb34d841a75ac9bc]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7b4b4499a99b - rustc_middle[c95cf357e72e9a85]::ty::context::tls::with_context_opt::<rustc_middle[c95cf357e72e9a85]::ty::context::tls::with_opt<rustc_middle[c95cf357e72e9a85]::util::bug::opt_span_bug_fmt<rustc_span[cb34d841a75ac9bc]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7b4b42c3df80 - rustc_middle[c95cf357e72e9a85]::util::bug::bug_fmt
  16:     0x7b4b46556623 - rustc_trait_selection[d3a832fb8e061b24]::traits::dyn_compatibility::virtual_call_violations_for_method
  17:     0x7b4b45fef6ed - rustc_trait_selection[d3a832fb8e061b24]::traits::dyn_compatibility::dyn_compatibility_violations_for_assoc_item
  18:     0x7b4b45fef590 - <core[b38de05c6bab522f]::iter::adapters::flatten::FlatMap<core[b38de05c6bab522f]::iter::adapters::map::Map<core[b38de05c6bab522f]::iter::adapters::map::Map<core[b38de05c6bab522f]::slice::iter::Iter<(rustc_span[cb34d841a75ac9bc]::symbol::Symbol, rustc_middle[c95cf357e72e9a85]::ty::assoc::AssocItem)>, <rustc_data_structures[9c6ee9e9e5334c83]::sorted_map::index_map::SortedIndexMultiMap<u32, rustc_span[cb34d841a75ac9bc]::symbol::Symbol, rustc_middle[c95cf357e72e9a85]::ty::assoc::AssocItem>>::iter::{closure#0}>, <rustc_middle[c95cf357e72e9a85]::ty::assoc::AssocItems>::in_definition_order::{closure#0}>, alloc[26d4a3e3ec5433a5]::vec::Vec<rustc_middle[c95cf357e72e9a85]::traits::DynCompatibilityViolation>, rustc_trait_selection[d3a832fb8e061b24]::traits::dyn_compatibility::dyn_compatibility_violations_for_trait::{closure#0}::{closure#0}> as core[b38de05c6bab522f]::iter::traits::iterator::Iterator>::next
  19:     0x7b4b46543d60 - <core[b38de05c6bab522f]::iter::adapters::flatten::FlatMap<core[b38de05c6bab522f]::iter::sources::from_fn::FromFn<rustc_type_ir[6a899794ba15143]::elaborate::supertrait_def_ids<rustc_middle[c95cf357e72e9a85]::ty::context::TyCtxt>::{closure#0}>, alloc[26d4a3e3ec5433a5]::vec::Vec<rustc_middle[c95cf357e72e9a85]::traits::DynCompatibilityViolation>, rustc_trait_selection[d3a832fb8e061b24]::traits::dyn_compatibility::dyn_compatibility_violations::{closure#0}> as core[b38de05c6bab522f]::iter::traits::iterator::Iterator>::next
  20:     0x7b4b46543984 - <core[b38de05c6bab522f]::iter::adapters::flatten::FlatMap<core[b38de05c6bab522f]::iter::sources::from_fn::FromFn<rustc_type_ir[6a899794ba15143]::elaborate::supertrait_def_ids<rustc_middle[c95cf357e72e9a85]::ty::context::TyCtxt>::{closure#0}>, alloc[26d4a3e3ec5433a5]::vec::Vec<rustc_middle[c95cf357e72e9a85]::traits::DynCompatibilityViolation>, rustc_trait_selection[d3a832fb8e061b24]::traits::dyn_compatibility::dyn_compatibility_violations::{closure#0}> as core[b38de05c6bab522f]::iter::traits::iterator::Iterator>::collect::<smallvec[ec8755ed03ba0f13]::SmallVec<[rustc_middle[c95cf357e72e9a85]::traits::DynCompatibilityViolation; 8usize]>>
  21:     0x7b4b465434dd - rustc_trait_selection[d3a832fb8e061b24]::traits::dyn_compatibility::dyn_compatibility_violations
  22:     0x7b4b465433e2 - rustc_query_impl[a79c5430108c0b60]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a79c5430108c0b60]::query_impl::dyn_compatibility_violations::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 16usize]>>
  23:     0x7b4b465433c9 - <rustc_query_impl[a79c5430108c0b60]::query_impl::dyn_compatibility_violations::dynamic_query::{closure#2} as core[b38de05c6bab522f]::ops::function::FnOnce<(rustc_middle[c95cf357e72e9a85]::ty::context::TyCtxt, rustc_span[cb34d841a75ac9bc]::def_id::DefId)>>::call_once
  24:     0x7b4b45e8840a - rustc_query_system[ff51b95ecba2cb21]::query::plumbing::try_execute_query::<rustc_query_impl[a79c5430108c0b60]::DynamicConfig<rustc_query_system[ff51b95ecba2cb21]::query::caches::DefIdCache<rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[a79c5430108c0b60]::plumbing::QueryCtxt, false>
  25:     0x7b4b45ff1338 - rustc_query_impl[a79c5430108c0b60]::query_impl::dyn_compatibility_violations::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7b4b45ff162f - rustc_middle[c95cf357e72e9a85]::query::plumbing::query_get_at::<rustc_query_system[ff51b95ecba2cb21]::query::caches::DefIdCache<rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 16usize]>>>
  27:     0x7b4b45ff1427 - rustc_trait_selection[d3a832fb8e061b24]::traits::dyn_compatibility::is_dyn_compatible
  28:     0x7b4b45ff13e9 - rustc_query_impl[a79c5430108c0b60]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a79c5430108c0b60]::query_impl::is_dyn_compatible::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 1usize]>>
  29:     0x7b4b45d6c3eb - rustc_query_system[ff51b95ecba2cb21]::query::plumbing::try_execute_query::<rustc_query_impl[a79c5430108c0b60]::DynamicConfig<rustc_query_system[ff51b95ecba2cb21]::query::caches::DefIdCache<rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a79c5430108c0b60]::plumbing::QueryCtxt, false>
  30:     0x7b4b4630eca6 - rustc_query_impl[a79c5430108c0b60]::query_impl::is_dyn_compatible::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7b4b463b7200 - rustc_middle[c95cf357e72e9a85]::query::plumbing::query_get_at::<rustc_query_system[ff51b95ecba2cb21]::query::caches::DefIdCache<rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 1usize]>>>
  32:     0x7b4b46b1cd85 - <dyn rustc_hir_analysis[52c5e5868dd20650]::hir_ty_lowering::HirTyLowerer>::prohibit_or_lint_bare_trait_object_ty
  33:     0x7b4b4634256f - <dyn rustc_hir_analysis[52c5e5868dd20650]::hir_ty_lowering::HirTyLowerer>::lower_ty
  34:     0x7b4b46339e7e - <dyn rustc_hir_analysis[52c5e5868dd20650]::hir_ty_lowering::HirTyLowerer>::lower_fn_ty
  35:     0x7b4b4634f4a0 - rustc_hir_analysis[52c5e5868dd20650]::collect::fn_sig
  36:     0x7b4b45cb60ed - rustc_query_impl[a79c5430108c0b60]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a79c5430108c0b60]::query_impl::fn_sig::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 24usize]>>
  37:     0x7b4b45cb60ad - <rustc_query_impl[a79c5430108c0b60]::query_impl::fn_sig::dynamic_query::{closure#2} as core[b38de05c6bab522f]::ops::function::FnOnce<(rustc_middle[c95cf357e72e9a85]::ty::context::TyCtxt, rustc_span[cb34d841a75ac9bc]::def_id::DefId)>>::call_once
  38:     0x7b4b45cb8f87 - rustc_query_system[ff51b95ecba2cb21]::query::plumbing::try_execute_query::<rustc_query_impl[a79c5430108c0b60]::DynamicConfig<rustc_query_system[ff51b95ecba2cb21]::query::caches::DefIdCache<rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[a79c5430108c0b60]::plumbing::QueryCtxt, false>
  39:     0x7b4b45cb85e2 - rustc_query_impl[a79c5430108c0b60]::query_impl::fn_sig::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7b4b460794bc - rustc_middle[c95cf357e72e9a85]::query::plumbing::query_get_at::<rustc_query_system[ff51b95ecba2cb21]::query::caches::DefIdCache<rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 24usize]>>>
  41:     0x7b4b46a38049 - rustc_hir_analysis[52c5e5868dd20650]::check::check::check_item_type
  42:     0x7b4b460655c6 - rustc_hir_analysis[52c5e5868dd20650]::check::wfcheck::check_well_formed
  43:     0x7b4b46064187 - rustc_query_impl[a79c5430108c0b60]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a79c5430108c0b60]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 1usize]>>
  44:     0x7b4b46063c29 - rustc_query_system[ff51b95ecba2cb21]::query::plumbing::try_execute_query::<rustc_query_impl[a79c5430108c0b60]::DynamicConfig<rustc_data_structures[9c6ee9e9e5334c83]::vec_cache::VecCache<rustc_span[cb34d841a75ac9bc]::def_id::LocalDefId, rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[ff51b95ecba2cb21]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[a79c5430108c0b60]::plumbing::QueryCtxt, false>
  45:     0x7b4b46063686 - rustc_query_impl[a79c5430108c0b60]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  46:     0x7b4b460612ac - rustc_hir_analysis[52c5e5868dd20650]::check::wfcheck::check_mod_type_wf
  47:     0x7b4b460610cb - rustc_query_impl[a79c5430108c0b60]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a79c5430108c0b60]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 1usize]>>
  48:     0x7b4b46985948 - rustc_query_system[ff51b95ecba2cb21]::query::plumbing::try_execute_query::<rustc_query_impl[a79c5430108c0b60]::DynamicConfig<rustc_query_system[ff51b95ecba2cb21]::query::caches::DefaultCache<rustc_span[cb34d841a75ac9bc]::def_id::LocalModDefId, rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a79c5430108c0b60]::plumbing::QueryCtxt, false>
  49:     0x7b4b469856f0 - rustc_query_impl[a79c5430108c0b60]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  50:     0x7b4b45da10e6 - rustc_hir_analysis[52c5e5868dd20650]::check_crate
  51:     0x7b4b45d9dc64 - rustc_interface[3e4af95fb941106a]::passes::run_required_analyses
  52:     0x7b4b469002de - rustc_interface[3e4af95fb941106a]::passes::analysis
  53:     0x7b4b469002af - rustc_query_impl[a79c5430108c0b60]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a79c5430108c0b60]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 0usize]>>
  54:     0x7b4b468ec015 - rustc_query_system[ff51b95ecba2cb21]::query::plumbing::try_execute_query::<rustc_query_impl[a79c5430108c0b60]::DynamicConfig<rustc_query_system[ff51b95ecba2cb21]::query::caches::SingleCache<rustc_middle[c95cf357e72e9a85]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[a79c5430108c0b60]::plumbing::QueryCtxt, false>
  55:     0x7b4b468ebd4e - rustc_query_impl[a79c5430108c0b60]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  56:     0x7b4b46a0be69 - rustc_interface[3e4af95fb941106a]::passes::create_and_enter_global_ctxt::<core[b38de05c6bab522f]::option::Option<rustc_interface[3e4af95fb941106a]::queries::Linker>, rustc_driver_impl[88e265ae9927f55c]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  57:     0x7b4b4695a498 - rustc_interface[3e4af95fb941106a]::interface::run_compiler::<(), rustc_driver_impl[88e265ae9927f55c]::run_compiler::{closure#0}>::{closure#1}
  58:     0x7b4b46875f35 - std[65c60797a113df8d]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[3e4af95fb941106a]::util::run_in_thread_with_globals<rustc_interface[3e4af95fb941106a]::util::run_in_thread_pool_with_globals<rustc_interface[3e4af95fb941106a]::interface::run_compiler<(), rustc_driver_impl[88e265ae9927f55c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  59:     0x7b4b46875c19 - <<std[65c60797a113df8d]::thread::Builder>::spawn_unchecked_<rustc_interface[3e4af95fb941106a]::util::run_in_thread_with_globals<rustc_interface[3e4af95fb941106a]::util::run_in_thread_pool_with_globals<rustc_interface[3e4af95fb941106a]::interface::run_compiler<(), rustc_driver_impl[88e265ae9927f55c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[b38de05c6bab522f]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  60:     0x7b4b468753ab - std::sys::pal::unix::thread::Thread::new::thread_start::h7b9c2e4fdae6f3c1
  61:     0x7b4b40aa339d - <unknown>
  62:     0x7b4b40b2849c - <unknown>
  63:                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.86.0-nightly (e6f12c8b7 2025-01-30) running on x86_64-unknown-linux-gnu

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

query stack during panic:
#0 [dyn_compatibility_violations] determining dyn-compatibility of trait `A`
#1 [is_dyn_compatible] checking if trait `A` is dyn-compatible
#2 [fn_sig] computing function signature of `A::b`
#3 [check_well_formed] checking that `A` 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
error: aborting due to 2 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0601`.

@rustbot label +F-async_fn_in_dyn_trait

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Jan 30, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Jan 30, 2025
  3. added
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 4, 2025
  4. added
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    on Mar 9, 2025
  5. added a commit that references this issue on Mar 19, 2025
    351ba39
  6. added a commit that references this issue on Mar 19, 2025
    130a33a
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

    C-bugCategory: This is a bug.F-async_fn_in_dyn_trait`#![feature(async_fn_in_dyn_trait)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.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