Skip to content

ICE: compiler panic when trait async method is implemented as non-async function #145921

Closed

Description

@starbugs-qurong

Code

trait SignedUnsigned {
    type Opposite;
    async fn convert(self) -> Self::OString;
}

impl SignedUnsigned for isize {
    type Opposite = usize;

    fn convert(self) -> usize {
        self as usize
    }
}

impl SignedUnsigned for usize {
    type Opposite = isize;

    fn convert(self) -> isize {
        self as isize
    }
}

fn get(x: isize) -> <isize as SignedUnsigned>::Opposite {
    x.convert()
}

fn main() {
    let x = get(22);
    assert_eq!(22, x);
}

Meta

rustc --version --verbose:

rustc version: 1.88.0-nightly (38c560ae6 2025-04-15)
platform: x86_64-unknown-linux-gnu

Error output

thread 'rustc' panicked at compiler/rustc_middle/src/ty/assoc.rs:43:25:
name of non-Rpitit assoc item
stack backtrace:
   0:     0x7f4961607665 - std::backtrace::Backtrace::create::hc21e599262d351fb
   1:     0x7f495fa08e85 - std::backtrace::Backtrace::force_capture::h17d9d7e5175bd88b
   2:     0x7f495ea973c1 - std[578a540cb1055794]::panicking::update_hook::<alloc[c7bac661b78ee32a]::boxed::Box<rustc_driver_impl[b0be92c9b081b175]::install_ice_hook::{closure#1}>>::{closure#0}
   3:     0x7f495fa227e3 - std::panicking::rust_panic_with_hook::hd7119d7cf1d6a8a6
   4:     0x7f495fa224da - std::panicking::begin_panic_handler::{{closure}}::hf5929578e2038605
   5:     0x7f495fa1ec69 - std::sys::backtrace::__rust_end_short_backtrace::h5904f09f45ae42e5
   6:     0x7f495fa2219d - __rustc[370de465637bfaa7]::rust_begin_unwind
   7:     0x7f495c3c4e00 - core::panicking::panic_fmt::h5acbb1dde8a99479
   8:     0x7f495d570c2b - core::option::expect_failed::h0587386df803e6c8
   9:     0x7f495e31f3b4 - <core[73e3539c07be93ec]::iter::adapters::filter_map::FilterMap<core[73e3539c07be93ec]::iter::adapters::flatten::FlatMap<core[73e3539c07be93ec]::slice::iter::Iter<rustc_span[ca70e3dc5ca374d0]::def_id::DefId>, core[73e3539c07be93ec]::iter::adapters::map::Map<core[73e3539c07be93ec]::iter::adapters::map::Map<core[73e3539c07be93ec]::slice::iter::Iter<(core[73e3539c07be93ec]::option::Option<rustc_span[ca70e3dc5ca374d0]::symbol::Symbol>, rustc_middle[765a8dd7c8651dad]::ty::assoc::AssocItem)>, <rustc_data_structures[8aaded25a193fa02]::sorted_map::index_map::SortedIndexMultiMap<u32, core[73e3539c07be93ec]::option::Option<rustc_span[ca70e3dc5ca374d0]::symbol::Symbol>, rustc_middle[765a8dd7c8651dad]::ty::assoc::AssocItem>>::iter::{closure#0}>, <rustc_middle[765a8dd7c8651dad]::ty::assoc::AssocItems>::in_definition_order::{closure#0}>, <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::complain_about_assoc_item_not_found<rustc_type_ir[c5fe605a4634044b]::elaborate::FilterToTraits<rustc_middle[765a8dd7c8651dad]::ty::context::TyCtxt, rustc_type_ir[c5fe605a4634044b]::elaborate::Elaborator<rustc_middle[765a8dd7c8651dad]::ty::context::TyCtxt, rustc_middle[765a8dd7c8651dad]::ty::predicate::Clause>>, <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::lower_assoc_path_shared::{closure#0}::{closure#1}>::{closure#4}>, <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::complain_about_assoc_item_not_found<rustc_type_ir[c5fe605a4634044b]::elaborate::FilterToTraits<rustc_middle[765a8dd7c8651dad]::ty::context::TyCtxt, rustc_type_ir[c5fe605a4634044b]::elaborate::Elaborator<rustc_middle[765a8dd7c8651dad]::ty::context::TyCtxt, rustc_middle[765a8dd7c8651dad]::ty::predicate::Clause>>, <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::lower_assoc_path_shared::{closure#0}::{closure#1}>::{closure#5}> as core[73e3539c07be93ec]::iter::traits::iterator::Iterator>::next
  10:     0x7f4960e5afa7 - <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::probe_single_bound_for_assoc_item::<core[73e3539c07be93ec]::iter::sources::from_fn::FromFn<rustc_infer[12d18ba463e0aca0]::traits::util::transitive_bounds_that_define_assoc_item<core[73e3539c07be93ec]::iter::adapters::filter_map::FilterMap<rustc_type_ir[c5fe605a4634044b]::binder::IterIdentityCopied<&[(rustc_middle[765a8dd7c8651dad]::ty::predicate::Clause, rustc_span[ca70e3dc5ca374d0]::span_encoding::Span)]>, <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::probe_single_ty_param_bound_for_assoc_item::{closure#0}::{closure#0}::{closure#0}>>::{closure#0}>, <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::probe_single_ty_param_bound_for_assoc_item::{closure#0}::{closure#0}>::{closure#0}
  11:     0x7f4960e53bae - <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::lower_assoc_path_shared::{closure#0}
  12:     0x7f4960e536c0 - <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::lower_assoc_path_ty
  13:     0x7f4960437310 - <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::lower_ty
  14:     0x7f4960e5f9c1 - <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::lower_assoc_item_constraint
  15:     0x7f496042ce0f - <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::lower_poly_trait_ref
  16:     0x7f496042c024 - <dyn rustc_hir_analysis[487753ec01fba80f]::hir_ty_lowering::HirTyLowerer>::lower_bounds::<&[rustc_hir[f344a81df18c2898]::hir::GenericBound]>
  17:     0x7f4960f7d861 - rustc_hir_analysis[487753ec01fba80f]::collect::item_bounds::associated_type_bounds
  18:     0x7f4960f7ce94 - rustc_hir_analysis[487753ec01fba80f]::collect::item_bounds::explicit_item_bounds
  19:     0x7f4960f7ce67 - rustc_query_impl[c0a700bc271d3d61]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c0a700bc271d3d61]::query_impl::explicit_item_bounds::dynamic_query::{closure#2}::{closure#0}, rustc_middle[765a8dd7c8651dad]::query::erase::Erased<[u8; 16usize]>>
  20:     0x7f4960f7ce2b - <rustc_query_impl[c0a700bc271d3d61]::query_impl::explicit_item_bounds::dynamic_query::{closure#2} as core[73e3539c07be93ec]::ops::function::FnOnce<(rustc_middle[765a8dd7c8651dad]::ty::context::TyCtxt, rustc_span[ca70e3dc5ca374d0]::def_id::DefId)>>::call_once
  21:     0x7f4960364990 - rustc_query_system[fc17e5d2cc829803]::query::plumbing::try_execute_query::<rustc_query_impl[c0a700bc271d3d61]::DynamicConfig<rustc_query_system[fc17e5d2cc829803]::query::caches::DefIdCache<rustc_middle[765a8dd7c8651dad]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[c0a700bc271d3d61]::plumbing::QueryCtxt, false>
  22:     0x7f4960ae2160 - rustc_query_impl[c0a700bc271d3d61]::query_impl::explicit_item_bounds::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7f495ec4d418 - <rustc_hir_analysis[487753ec01fba80f]::check::compare_impl_item::ImplTraitInTraitCollector<rustc_trait_selection[e2a4737cc054f26c]::traits::FulfillmentError> as rustc_type_ir[c5fe605a4634044b]::fold::TypeFolder<rustc_middle[765a8dd7c8651dad]::ty::context::TyCtxt>>::fold_ty
  24:     0x7f495ebc558a - <&rustc_middle[765a8dd7c8651dad]::ty::list::RawList<(), rustc_middle[765a8dd7c8651dad]::ty::Ty> as rustc_type_ir[c5fe605a4634044b]::fold::TypeFoldable<rustc_middle[765a8dd7c8651dad]::ty::context::TyCtxt>>::try_fold_with::<rustc_hir_analysis[487753ec01fba80f]::check::compare_impl_item::ImplTraitInTraitCollector<rustc_trait_selection[e2a4737cc054f26c]::traits::FulfillmentError>>
  25:     0x7f495ec9e7e7 - rustc_hir_analysis[487753ec01fba80f]::check::compare_impl_item::collect_return_position_impl_trait_in_trait_tys::{closure#0}
  26:     0x7f495f50bb13 - rustc_query_impl[c0a700bc271d3d61]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c0a700bc271d3d61]::query_impl::collect_return_position_impl_trait_in_trait_tys::dynamic_query::{closure#2}::{closure#0}, rustc_middle[765a8dd7c8651dad]::query::erase::Erased<[u8; 8usize]>>
  27:     0x7f49604194af - rustc_query_system[fc17e5d2cc829803]::query::plumbing::try_execute_query::<rustc_query_impl[c0a700bc271d3d61]::DynamicConfig<rustc_query_system[fc17e5d2cc829803]::query::caches::DefIdCache<rustc_middle[765a8dd7c8651dad]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[c0a700bc271d3d61]::plumbing::QueryCtxt, false>
  28:     0x7f495f510718 - rustc_query_impl[c0a700bc271d3d61]::query_impl::collect_return_position_impl_trait_in_trait_tys::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7f49604219f5 - rustc_hir_analysis[487753ec01fba80f]::collect::type_of::type_of
  30:     0x7f496041f178 - rustc_query_impl[c0a700bc271d3d61]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c0a700bc271d3d61]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[765a8dd7c8651dad]::query::erase::Erased<[u8; 8usize]>>
  31:     0x7f49604194af - rustc_query_system[fc17e5d2cc829803]::query::plumbing::try_execute_query::<rustc_query_impl[c0a700bc271d3d61]::DynamicConfig<rustc_query_system[fc17e5d2cc829803]::query::caches::DefIdCache<rustc_middle[765a8dd7c8651dad]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[c0a700bc271d3d61]::plumbing::QueryCtxt, false>
  32:     0x7f496041905f - rustc_query_impl[c0a700bc271d3d61]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7f4960936efa - rustc_hir_analysis[487753ec01fba80f]::check::wfcheck::check_well_formed
  34:     0x7f4960934ceb - rustc_query_impl[c0a700bc271d3d61]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c0a700bc271d3d61]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[765a8dd7c8651dad]::query::erase::Erased<[u8; 1usize]>>
  35:     0x7f4960934594 - rustc_query_system[fc17e5d2cc829803]::query::plumbing::try_execute_query::<rustc_query_impl[c0a700bc271d3d61]::DynamicConfig<rustc_data_structures[8aaded25a193fa02]::vec_cache::VecCache<rustc_span[ca70e3dc5ca374d0]::def_id::LocalDefId, rustc_middle[765a8dd7c8651dad]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[fc17e5d2cc829803]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[c0a700bc271d3d61]::plumbing::QueryCtxt, false>
  36:     0x7f4960934083 - rustc_query_impl[c0a700bc271d3d61]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7f49609304e5 - rustc_hir_analysis[487753ec01fba80f]::check::wfcheck::check_mod_type_wf
  38:     0x7f49609302dd - rustc_query_impl[c0a700bc271d3d61]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c0a700bc271d3d61]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[765a8dd7c8651dad]::query::erase::Erased<[u8; 1usize]>>
  39:     0x7f4960cbecd9 - rustc_query_system[fc17e5d2cc829803]::query::plumbing::try_execute_query::<rustc_query_impl[c0a700bc271d3d61]::DynamicConfig<rustc_query_system[fc17e5d2cc829803]::query::caches::DefaultCache<rustc_span[ca70e3dc5ca374d0]::def_id::LocalModDefId, rustc_middle[765a8dd7c8651dad]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c0a700bc271d3d61]::plumbing::QueryCtxt, false>
  40:     0x7f4960cbea4c - rustc_query_impl[c0a700bc271d3d61]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7f49603a2266 - rustc_hir_analysis[487753ec01fba80f]::check_crate
  42:     0x7f4960533972 - rustc_interface[c20367986e3c43b9]::passes::run_required_analyses
  43:     0x7f4960cbfd1e - rustc_interface[c20367986e3c43b9]::passes::analysis
  44:     0x7f4960cbfcf3 - rustc_query_impl[c0a700bc271d3d61]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c0a700bc271d3d61]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[765a8dd7c8651dad]::query::erase::Erased<[u8; 0usize]>>
  45:     0x7f496114717d - rustc_query_system[fc17e5d2cc829803]::query::plumbing::try_execute_query::<rustc_query_impl[c0a700bc271d3d61]::DynamicConfig<rustc_query_system[fc17e5d2cc829803]::query::caches::SingleCache<rustc_middle[765a8dd7c8651dad]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[c0a700bc271d3d61]::plumbing::QueryCtxt, false>
  46:     0x7f4961146e78 - rustc_query_impl[c0a700bc271d3d61]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  47:     0x7f496103b2fe - rustc_interface[c20367986e3c43b9]::passes::create_and_enter_global_ctxt::<core[73e3539c07be93ec]::option::Option<rustc_interface[c20367986e3c43b9]::queries::Linker>, rustc_driver_impl[b0be92c9b081b175]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  48:     0x7f4961251804 - rustc_interface[c20367986e3c43b9]::interface::run_compiler::<(), rustc_driver_impl[b0be92c9b081b175]::run_compiler::{closure#0}>::{closure#1}
  49:     0x7f4961043668 - std[578a540cb1055794]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[c20367986e3c43b9]::util::run_in_thread_with_globals<rustc_interface[c20367986e3c43b9]::util::run_in_thread_pool_with_globals<rustc_interface[c20367986e3c43b9]::interface::run_compiler<(), rustc_driver_impl[b0be92c9b081b175]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  50:     0x7f4961043f6b - <<std[578a540cb1055794]::thread::Builder>::spawn_unchecked_<rustc_interface[c20367986e3c43b9]::util::run_in_thread_with_globals<rustc_interface[c20367986e3c43b9]::util::run_in_thread_pool_with_globals<rustc_interface[c20367986e3c43b9]::interface::run_compiler<(), rustc_driver_impl[b0be92c9b081b175]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[73e3539c07be93ec]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  51:     0x7f4961045377 - std::sys::pal::unix::thread::Thread::new::thread_start::hd6f89f3f1c8122ca
  52:     0x7f495b0f0609 - start_thread
                               at /build/glibc-FcRMwW/glibc-2.31/nptl/pthread_create.c:477:8
  53:     0x7f495b015353 - clone
                               at /build/glibc-FcRMwW/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95:0
  54:                0x0 - <unknown>

rustc version: 1.88.0-nightly (38c560ae6 2025-04-15)
platform: x86_64-unknown-linux-gnu

query stack during panic:
#0 [explicit_item_bounds] finding item bounds for `SignedUnsigned::{anon_assoc#0}`
#1 [collect_return_position_impl_trait_in_trait_tys] comparing an impl and trait method signature, inferring any hidden `impl Trait` types in the process
#2 [type_of] computing type of `<impl at /home/qurong/compiler-testing/rust/2025-8-25-retest/test/associated-types-constant-type-str10.rs:6:1: 6:30>::{anon_assoc#0}`
#3 [check_well_formed] checking that `<impl at /home/qurong/compiler-testing/rust/2025-8-25-retest/test/associated-types-constant-type-str10.rs:6:1: 6:30>` 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

Activity

  1. added
    I-ICE
    T-compiler
    C-bug
    on Aug 27, 2025
  2. added
    needs-triage
    on Aug 27, 2025
  3. cyrgani commented on Aug 27, 2025

    @cyrgani
    Contributor

    Can you reproduce this after upgrading your compiler? 1.88-nightly is several versions old (current is 1.91-nightly) and the given code does not ICE on current stable, beta or nightly.

  4. added
    F-async_fn_in_trait
    on Aug 27, 2025
  5. xizheyin commented on Aug 27, 2025

    @xizheyin
    Member

    This may have been fixed. Please update the version of your compiler.
    https://play.rust-lang.org/?version=stable&mode=debug&edition=2024

  6. compiler-errors commented on Aug 27, 2025

    @compiler-errors
    Contributor

    Yeah, agree w/ the other comments above. Feel free to reopen this issue if it persists on nightly/beta/stable.

  7. removed
    needs-triage
    on Aug 27, 2025
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-bugF-async_fn_in_traitI-ICET-compiler

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions