rust-lang / rust-lang/rust

[ICE]: `failed to resolve instance for <() as Trait>::foo: Err(ErrorGuaranteed(()))`

Open
#152,410 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-ICE S-bug-has-test S-has-mcve T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

auto-reduced (treereduce-rust):

trait Trait {
    fn foo(&self);
}
impl Trait for () {}

const OBJECT: *const (dyn Trait + Send) = &();

const _: *const dyn Send = OBJECT as _;

original:

//! Test that non-coercion casts aren't allowed to drop the principal,
//~^ ERROR cannot add `u8` to `i32` [E0277]//!
//! We test this in a const context to guard against UB if this is allowed
//! in the future.

trait Trait {
    extern "rust-intrinsic" fn foo(&self); //~ ERROR invalid ABI
}
impl Trait for () {
//~^ ERROR E0119
    fn get(&self) -> usize { self.osd_recovery_max_chunk }
}

struct Wrapper<T: ?Sized>(T);

const OBJECT: *const (dyn Trait + Send) = &();

// coercions are allowed
const _: *const dyn Send = OBJECT as _;

// casts are **not** allowed
const _: *const Wrapper<dyn Send> = OBJECT as _;
const NAME: &'static str;

fn main() {}

Version information

rustc 1.95.0-nightly (71dc761bf 2026-02-09)
binary: rustc
commit-hash: 71dc761bfe791895c5997dda654dca1dad817413
commit-date: 2026-02-09
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 22.1.0

Possibly related line of code:
https://github.com/rust-lang/rust/blob/71dc761bfe791895c5997dda654dca1dad817413/compiler/rustc_middle/src/ty/instance.rs#L580-L592

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.PsKdDjoC4iy4/rustc_testrunner_tmpdir_reporting.HURYa8L3WTTo/mvce.rs:8:40
  |
8 | const _: *const dyn Send = OBJECT as _;
  |                                        ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.PsKdDjoC4iy4/rustc_testrunner_tmpdir_reporting.HURYa8L3WTTo/mvce.rs`

error[E0046]: not all trait items implemented, missing: `foo`
 --> /tmp/icemaker_global_tempdir.PsKdDjoC4iy4/rustc_testrunner_tmpdir_reporting.HURYa8L3WTTo/mvce.rs:4:1
  |
2 |     fn foo(&self);
  |     -------------- `foo` from trait
3 | }
4 | impl Trait for () {}
  | ^^^^^^^^^^^^^^^^^ missing `foo` in implementation

error: internal compiler error: /rustc-dev/71dc761bfe791895c5997dda654dca1dad817413/compiler/rustc_middle/src/ty/instance.rs:586:25: failed to resolve instance for <() as Trait>::foo: Err(
                                    ErrorGuaranteed(
                                        (),
                                    ),
                                )
 --> /tmp/icemaker_global_tempdir.PsKdDjoC4iy4/rustc_testrunner_tmpdir_reporting.HURYa8L3WTTo/mvce.rs:2:5
  |
2 |     fn foo(&self);
  |     ^^^^^^^^^^^^^^


thread 'rustc' (400413) panicked at /rustc-dev/71dc761bfe791895c5997dda654dca1dad817413/compiler/rustc_middle/src/ty/instance.rs:586:25:
Box<dyn Any>
stack backtrace:
   0:     0x7fc5d618d1ab - <<std[523e6283ac0dcea1]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[d5547d90765c137c]::fmt::Display>::fmt
   1:     0x7fc5d680ee08 - core[d5547d90765c137c]::fmt::write
   2:     0x7fc5d61a4496 - <std[523e6283ac0dcea1]::sys::stdio::unix::Stderr as std[523e6283ac0dcea1]::io::Write>::write_fmt
   3:     0x7fc5d61631e8 - std[523e6283ac0dcea1]::panicking::default_hook::{closure#0}
   4:     0x7fc5d61805b3 - std[523e6283ac0dcea1]::panicking::default_hook
   5:     0x7fc5d515a1af - std[523e6283ac0dcea1]::panicking::update_hook::<alloc[436da888e1a143af]::boxed::Box<rustc_driver_impl[64ec58da98f47e83]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7fc5d6180892 - std[523e6283ac0dcea1]::panicking::panic_with_hook
   7:     0x7fc5d518dbc1 - std[523e6283ac0dcea1]::panicking::begin_panic::<rustc_errors[3ee7d435477a86d1]::ExplicitBug>::{closure#0}
   8:     0x7fc5d5186a76 - std[523e6283ac0dcea1]::sys::backtrace::__rust_end_short_backtrace::<std[523e6283ac0dcea1]::panicking::begin_panic<rustc_errors[3ee7d435477a86d1]::ExplicitBug>::{closure#0}, !>
   9:     0x7fc5d5184438 - std[523e6283ac0dcea1]::panicking::begin_panic::<rustc_errors[3ee7d435477a86d1]::ExplicitBug>
  10:     0x7fc5d51991d1 - <rustc_errors[3ee7d435477a86d1]::diagnostic::BugAbort as rustc_errors[3ee7d435477a86d1]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7fc5d572744c - <rustc_errors[3ee7d435477a86d1]::DiagCtxtHandle>::span_bug::<rustc_span[ca1e63ed549bf855]::span_encoding::Span, alloc[436da888e1a143af]::string::String>
  12:     0x7fc5d574f496 - rustc_middle[f4434c35d4311913]::util::bug::opt_span_bug_fmt::<rustc_span[ca1e63ed549bf855]::span_encoding::Span>::{closure#0}
  13:     0x7fc5d574f642 - rustc_middle[f4434c35d4311913]::ty::context::tls::with_opt::<rustc_middle[f4434c35d4311913]::util::bug::opt_span_bug_fmt<rustc_span[ca1e63ed549bf855]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7fc5d5740c4b - rustc_middle[f4434c35d4311913]::ty::context::tls::with_context_opt::<rustc_middle[f4434c35d4311913]::ty::context::tls::with_opt<rustc_middle[f4434c35d4311913]::util::bug::opt_span_bug_fmt<rustc_span[ca1e63ed549bf855]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7fc5d39c66f8 - rustc_middle[f4434c35d4311913]::util::bug::span_bug_fmt::<rustc_span[ca1e63ed549bf855]::span_encoding::Span>
  16:     0x7fc5d6e9a697 - <rustc_middle[f4434c35d4311913]::ty::instance::Instance>::expect_resolve
  17:     0x7fc5d6e9907d - <rustc_middle[f4434c35d4311913]::ty::instance::Instance>::expect_resolve_for_vtable
  18:     0x7fc5d7834f82 - rustc_trait_selection[85ebc299cff4bc96]::traits::vtable::vtable_entries::{closure#0}
  19:     0x7fc5d7836297 - rustc_trait_selection[85ebc299cff4bc96]::traits::vtable::vtable_entries
  20:     0x7fc5d7835c13 - rustc_query_impl[8a9214c7afe2a7db]::query_impl::vtable_entries::compute_fn::__rust_begin_short_backtrace
  21:     0x7fc5d7833c4c - rustc_query_impl[8a9214c7afe2a7db]::execution::try_execute_query::<rustc_query_system[fd37ce96506ffe7d]::query::caches::DefaultCache<rustc_type_ir[7432934aabbd4246]::predicate::TraitRef<rustc_middle[f4434c35d4311913]::ty::context::TyCtxt>, rustc_middle[f4434c35d4311913]::query::erase::ErasedData<[u8; 16usize]>>, {rustc_query_impl[8a9214c7afe2a7db]::QueryFlags { is_anon: false, is_depth_limit: false, is_feedable: false }}, false>
  22:     0x7fc5d7833995 - rustc_query_impl[8a9214c7afe2a7db]::query_impl::vtable_entries::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7fc5d50a93dd - <rustc_const_eval[4b2b708f0327aa2d]::interpret::eval_context::InterpCx<rustc_const_eval[4b2b708f0327aa2d]::const_eval::machine::CompileTimeMachine>>::vtable_entries
  24:     0x7fc5d6ceae3b - <rustc_const_eval[4b2b708f0327aa2d]::interpret::eval_context::InterpCx<rustc_const_eval[4b2b708f0327aa2d]::const_eval::machine::CompileTimeMachine>>::unsize_into_ptr::<rustc_const_eval[4b2b708f0327aa2d]::interpret::place::PlaceTy>
  25:     0x7fc5d7974b32 - <rustc_const_eval[4b2b708f0327aa2d]::interpret::eval_context::InterpCx<rustc_const_eval[4b2b708f0327aa2d]::const_eval::machine::CompileTimeMachine>>::eval_rvalue_into_place
  26:     0x7fc5d792e563 - rustc_const_eval[4b2b708f0327aa2d]::const_eval::eval_queries::eval_to_allocation_raw_provider
  27:     0x7fc5d792c2d8 - rustc_query_impl[8a9214c7afe2a7db]::query_impl::eval_to_allocation_raw::compute_fn::__rust_begin_short_backtrace
  28:     0x7fc5d792b5d9 - rustc_query_impl[8a9214c7afe2a7db]::execution::try_execute_query::<rustc_query_system[fd37ce96506ffe7d]::query::caches::DefaultCache<rustc_middle[f4434c35d4311913]::ty::PseudoCanonicalInput<rustc_middle[f4434c35d4311913]::mir::interpret::GlobalId>, rustc_middle[f4434c35d4311913]::query::erase::ErasedData<[u8; 24usize]>>, {rustc_query_impl[8a9214c7afe2a7db]::QueryFlags { is_anon: false, is_depth_limit: false, is_feedable: false }}, false>
  29:     0x7fc5d792b1b3 - rustc_query_impl[8a9214c7afe2a7db]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7fc5d6c98272 - rustc_const_eval[4b2b708f0327aa2d]::const_eval::eval_queries::eval_to_const_value_raw_provider
  31:     0x7fc5d6c97de0 - rustc_query_impl[8a9214c7afe2a7db]::query_impl::eval_to_const_value_raw::compute_fn::__rust_begin_short_backtrace
  32:     0x7fc5d6c96a38 - rustc_query_impl[8a9214c7afe2a7db]::execution::try_execute_query::<rustc_query_system[fd37ce96506ffe7d]::query::caches::DefaultCache<rustc_middle[f4434c35d4311913]::ty::PseudoCanonicalInput<rustc_middle[f4434c35d4311913]::mir::interpret::GlobalId>, rustc_middle[f4434c35d4311913]::query::erase::ErasedData<[u8; 24usize]>>, {rustc_query_impl[8a9214c7afe2a7db]::QueryFlags { is_anon: false, is_depth_limit: true, is_feedable: false }}, false>
  33:     0x7fc5d6c965f3 - rustc_query_impl[8a9214c7afe2a7db]::query_impl::eval_to_const_value_raw::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7fc5d744b3c7 - <rustc_middle[f4434c35d4311913]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[6e9b52c48913d37d]::check_crate::{closure#2}>::{closure#0}
  35:     0x7fc5d744a9f7 - rustc_hir_analysis[6e9b52c48913d37d]::check_crate
  36:     0x7fc5d744ea19 - rustc_interface[47dc46a86d51a4cb]::passes::analysis
  37:     0x7fc5d7a7e528 - rustc_query_impl[8a9214c7afe2a7db]::execution::try_execute_query::<rustc_query_system[fd37ce96506ffe7d]::query::caches::SingleCache<rustc_middle[f4434c35d4311913]::query::erase::ErasedData<[u8; 0usize]>>, {rustc_query_impl[8a9214c7afe2a7db]::QueryFlags { is_anon: false, is_depth_limit: false, is_feedable: false }}, false>
  38:     0x7fc5d7a7e30a - rustc_query_impl[8a9214c7afe2a7db]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7fc5d7bd9f27 - <rustc_interface[47dc46a86d51a4cb]::passes::create_and_enter_global_ctxt<core[d5547d90765c137c]::option::Option<rustc_interface[47dc46a86d51a4cb]::queries::Linker>, rustc_driver_impl[64ec58da98f47e83]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[d5547d90765c137c]::ops::function::FnOnce<(&rustc_session[3018a240f13a77c6]::session::Session, rustc_middle[f4434c35d4311913]::ty::context::CurrentGcx, alloc[436da888e1a143af]::sync::Arc<rustc_data_structures[574164e54f9dd1a8]::jobserver::Proxy>, &std[523e6283ac0dcea1]::sync::once_lock::OnceLock<rustc_middle[f4434c35d4311913]::ty::context::GlobalCtxt>, &rustc_data_structures[574164e54f9dd1a8]::sync::worker_local::WorkerLocal<rustc_middle[f4434c35d4311913]::arena::Arena>, &rustc_data_structures[574164e54f9dd1a8]::sync::worker_local::WorkerLocal<rustc_hir[3832a0b9a2077771]::Arena>, rustc_driver_impl[64ec58da98f47e83]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  40:     0x7fc5d7a44a79 - rustc_interface[47dc46a86d51a4cb]::interface::run_compiler::<(), rustc_driver_impl[64ec58da98f47e83]::run_compiler::{closure#0}>::{closure#1}
  41:     0x7fc5d7a6a93e - std[523e6283ac0dcea1]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[47dc46a86d51a4cb]::util::run_in_thread_with_globals<rustc_interface[47dc46a86d51a4cb]::util::run_in_thread_pool_with_globals<rustc_interface[47dc46a86d51a4cb]::interface::run_compiler<(), rustc_driver_impl[64ec58da98f47e83]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  42:     0x7fc5d7a6ae60 - <std[523e6283ac0dcea1]::thread::lifecycle::spawn_unchecked<rustc_interface[47dc46a86d51a4cb]::util::run_in_thread_with_globals<rustc_interface[47dc46a86d51a4cb]::util::run_in_thread_pool_with_globals<rustc_interface[47dc46a86d51a4cb]::interface::run_compiler<(), rustc_driver_impl[64ec58da98f47e83]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[d5547d90765c137c]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x7fc5d7a6bcec - <std[523e6283ac0dcea1]::sys::thread::unix::Thread>::new::thread_start
  44:     0x7fc5d129698b - <unknown>
  45:     0x7fc5d131a9cc - <unknown>
  46:                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.95.0-nightly (71dc761bf 2026-02-09) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [vtable_entries] finding all vtable entries for trait `Trait`
#1 [eval_to_allocation_raw] const-evaluating + checking `_`
#2 [eval_to_const_value_raw] simplifying constant for the type system `_`
#3 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 3 previous errors

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

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 by compiling the reduced Rust example from the issue with the reported nightly toolchain, then inspect compiler/rustc_middle/src/ty/instance.rs around lines 580-592 and the Instance::expect_resolve_for_vtable entry point shown in the backtrace. Done means the reproducer no longer triggers an internal compiler error and reports a normal diagnostic instead.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.