Skip to content

[ICE]: self-type &unsafe<'a> &'a (dyn Bar + 'a) for ObjectPick never dereferenced to an object #151311

@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: --edition=2024 -Znext-solver=globally
use std::ops::Deref;

trait Foo: Deref<Target = unsafe<'a> &'a dyn Bar> {
    fn method(self: &unsafe<'ops> &'a Bar) {}
}

trait Bar {}

fn test(x: &dyn Foo) {
    x.method();
}

fn main() {}

original:

#![cfg_attr(not(bootstrap), allow(internal_features))]

use std::ops::Deref;

trait Foo: Deref<Target = unsafe<'a> &'a dyn Bar> {
    fn method(self: &unsafe<'ops> &'a  Bar) {}
}

trait Bar {}

fn test(x: &dyn Foo) {
    x.method();
}

fn main() {}

Version information

rustc 1.95.0-nightly (621d76794 2026-01-18)
binary: rustc
commit-hash: 621d76794c76fc21c0a6151fbc090120e0230a91
commit-date: 2026-01-18
host: x86_64-unknown-linux-gnu
release: 1.95.0-nightly
LLVM version: 21.1.8

Possibly related line of code:

span_bug!(self.span, "calling trait method on empty object?")
}),
)),
_ => None,
})
.unwrap_or_else(|| {
span_bug!(
self.span,
"self-type `{}` for ObjectPick never dereferenced to an object",
self_ty
)
})
}

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

Program output

error[E0261]: use of undeclared lifetime name `'a`
 --> /tmp/icemaker_global_tempdir.RozcYyTmCCm3/rustc_testrunner_tmpdir_reporting.h5dx6zsheWVA/mvce.rs:4:36
  |
4 |     fn method(self: &unsafe<'ops> &'a Bar) {}
  |                                    ^^ undeclared lifetime
  |
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the type lifetime-generic with a new `'a` lifetime
  |
4 |     fn method(self: &unsafe<'a, 'ops> &'a Bar) {}
  |                             +++
help: consider introducing lifetime `'a` here
  |
4 |     fn method<'a>(self: &unsafe<'ops> &'a Bar) {}
  |              ++++
help: consider introducing lifetime `'a` here
  |
3 | trait Foo<'a>: Deref<Target = unsafe<'a> &'a dyn Bar> {
  |          ++++

error[E0658]: unsafe binder types are experimental
 --> /tmp/icemaker_global_tempdir.RozcYyTmCCm3/rustc_testrunner_tmpdir_reporting.h5dx6zsheWVA/mvce.rs:3:27
  |
3 | trait Foo: Deref<Target = unsafe<'a> &'a dyn Bar> {
  |                           ^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
  = help: add `#![feature(unsafe_binders)]` to the crate attributes to enable
  = note: this compiler was built on 2026-01-18; consider upgrading it if it is out of date

error[E0658]: unsafe binder types are experimental
 --> /tmp/icemaker_global_tempdir.RozcYyTmCCm3/rustc_testrunner_tmpdir_reporting.h5dx6zsheWVA/mvce.rs:4:22
  |
4 |     fn method(self: &unsafe<'ops> &'a Bar) {}
  |                      ^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
  = help: add `#![feature(unsafe_binders)]` to the crate attributes to enable
  = note: this compiler was built on 2026-01-18; consider upgrading it if it is out of date

error[E0782]: expected a type, found a trait
 --> /tmp/icemaker_global_tempdir.RozcYyTmCCm3/rustc_testrunner_tmpdir_reporting.h5dx6zsheWVA/mvce.rs:4:39
  |
4 |     fn method(self: &unsafe<'ops> &'a Bar) {}
  |                                       ^^^
  |
help: you can add the `dyn` keyword if you want a trait object
  |
4 |     fn method(self: &unsafe<'ops> &'a dyn Bar) {}
  |                                       +++

error: internal compiler error: /rustc-dev/621d76794c76fc21c0a6151fbc090120e0230a91/compiler/rustc_hir_typeck/src/method/confirm.rs:376:17: self-type `&unsafe<'a> &'a (dyn Bar + 'a)` for ObjectPick never dereferenced to an object
  --> /tmp/icemaker_global_tempdir.RozcYyTmCCm3/rustc_testrunner_tmpdir_reporting.h5dx6zsheWVA/mvce.rs:10:7
   |
10 |     x.method();
   |       ^^^^^^


thread 'rustc' (1256580) panicked at /rustc-dev/621d76794c76fc21c0a6151fbc090120e0230a91/compiler/rustc_hir_typeck/src/method/confirm.rs:376:17:
Box<dyn Any>
stack backtrace:
   0:     0x7f4799633fd3 - <<std[287527946f71f0bc]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[7477a31a1a34cc49]::fmt::Display>::fmt
   1:     0x7f4799c0e2c8 - core[7477a31a1a34cc49]::fmt::write
   2:     0x7f479964a9c6 - <std[287527946f71f0bc]::sys::stdio::unix::Stderr as std[287527946f71f0bc]::io::Write>::write_fmt
   3:     0x7f479960a048 - std[287527946f71f0bc]::panicking::default_hook::{closure#0}
   4:     0x7f4799627703 - std[287527946f71f0bc]::panicking::default_hook
   5:     0x7f47985fbb8a - std[287527946f71f0bc]::panicking::update_hook::<alloc[979041e9952e771b]::boxed::Box<rustc_driver_impl[517260a07841a630]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f47996279e2 - std[287527946f71f0bc]::panicking::panic_with_hook
   7:     0x7f4798638bc1 - std[287527946f71f0bc]::panicking::begin_panic::<rustc_errors[26c9ea40265c581b]::ExplicitBug>::{closure#0}
   8:     0x7f4798628fe6 - std[287527946f71f0bc]::sys::backtrace::__rust_end_short_backtrace::<std[287527946f71f0bc]::panicking::begin_panic<rustc_errors[26c9ea40265c581b]::ExplicitBug>::{closure#0}, !>
   9:     0x7f47986264b9 - std[287527946f71f0bc]::panicking::begin_panic::<rustc_errors[26c9ea40265c581b]::ExplicitBug>
  10:     0x7f4798656901 - <rustc_errors[26c9ea40265c581b]::diagnostic::BugAbort as rustc_errors[26c9ea40265c581b]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7f4798be492c - <rustc_errors[26c9ea40265c581b]::DiagCtxtHandle>::span_bug::<rustc_span[851f35e07e3c2dd4]::span_encoding::Span, alloc[979041e9952e771b]::string::String>
  12:     0x7f4798c074d6 - rustc_middle[725063e074f29df]::util::bug::opt_span_bug_fmt::<rustc_span[851f35e07e3c2dd4]::span_encoding::Span>::{closure#0}
  13:     0x7f4798c07682 - rustc_middle[725063e074f29df]::ty::context::tls::with_opt::<rustc_middle[725063e074f29df]::util::bug::opt_span_bug_fmt<rustc_span[851f35e07e3c2dd4]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7f4798bf8cab - rustc_middle[725063e074f29df]::ty::context::tls::with_context_opt::<rustc_middle[725063e074f29df]::ty::context::tls::with_opt<rustc_middle[725063e074f29df]::util::bug::opt_span_bug_fmt<rustc_span[851f35e07e3c2dd4]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7f47964afa68 - rustc_middle[725063e074f29df]::util::bug::span_bug_fmt::<rustc_span[851f35e07e3c2dd4]::span_encoding::Span>
  16:     0x7f479a3d3936 - <rustc_hir_typeck[ed5453188701a25b]::method::confirm::ConfirmContext>::confirm
  17:     0x7f4799fe6d83 - <rustc_hir_typeck[ed5453188701a25b]::fn_ctxt::FnCtxt>::check_expr_method_call
  18:     0x7f479a019963 - <rustc_hir_typeck[ed5453188701a25b]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  19:     0x7f479a014ac2 - <rustc_hir_typeck[ed5453188701a25b]::fn_ctxt::FnCtxt>::check_expr_block
  20:     0x7f479a01998b - <rustc_hir_typeck[ed5453188701a25b]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  21:     0x7f4799ffa1a6 - rustc_hir_typeck[ed5453188701a25b]::check::check_fn
  22:     0x7f479a9b3d33 - rustc_hir_typeck[ed5453188701a25b]::typeck_with_inspect::{closure#0}
  23:     0x7f479a9b26b4 - rustc_query_impl[f20b8284200e680a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f20b8284200e680a]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[725063e074f29df]::query::erase::Erased<[u8; 8usize]>>
  24:     0x7f4799d5522a - rustc_query_system[b7e73caa2c2ad9a]::query::plumbing::try_execute_query::<rustc_query_impl[f20b8284200e680a]::DynamicConfig<rustc_data_structures[e0d8483206daafa2]::vec_cache::VecCache<rustc_span[851f35e07e3c2dd4]::def_id::LocalDefId, rustc_middle[725063e074f29df]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[b7e73caa2c2ad9a]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[f20b8284200e680a]::plumbing::QueryCtxt, false>
  25:     0x7f4799d54b09 - rustc_query_impl[f20b8284200e680a]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7f479a73fdb5 - <rustc_middle[725063e074f29df]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_hir_analysis[1a80394817eddfdd]::check_crate::{closure#2}>::{closure#0}
  27:     0x7f479a73f7c4 - rustc_hir_analysis[1a80394817eddfdd]::check_crate
  28:     0x7f4799d493db - rustc_interface[5c48368f5debe80d]::passes::analysis
  29:     0x7f4799d49035 - rustc_query_impl[f20b8284200e680a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f20b8284200e680a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[725063e074f29df]::query::erase::Erased<[u8; 0usize]>>
  30:     0x7f479ada4be3 - rustc_query_system[b7e73caa2c2ad9a]::query::plumbing::try_execute_query::<rustc_query_impl[f20b8284200e680a]::DynamicConfig<rustc_query_system[b7e73caa2c2ad9a]::query::caches::SingleCache<rustc_middle[725063e074f29df]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[f20b8284200e680a]::plumbing::QueryCtxt, false>
  31:     0x7f479ada49ce - rustc_query_impl[f20b8284200e680a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7f479af82c11 - <rustc_interface[5c48368f5debe80d]::passes::create_and_enter_global_ctxt<core[7477a31a1a34cc49]::option::Option<rustc_interface[5c48368f5debe80d]::queries::Linker>, rustc_driver_impl[517260a07841a630]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[7477a31a1a34cc49]::ops::function::FnOnce<(&rustc_session[eb79e6d3104f29ae]::session::Session, rustc_middle[725063e074f29df]::ty::context::CurrentGcx, alloc[979041e9952e771b]::sync::Arc<rustc_data_structures[e0d8483206daafa2]::jobserver::Proxy>, &std[287527946f71f0bc]::sync::once_lock::OnceLock<rustc_middle[725063e074f29df]::ty::context::GlobalCtxt>, &rustc_data_structures[e0d8483206daafa2]::sync::worker_local::WorkerLocal<rustc_middle[725063e074f29df]::arena::Arena>, &rustc_data_structures[e0d8483206daafa2]::sync::worker_local::WorkerLocal<rustc_hir[7eac7792dedc1861]::Arena>, rustc_driver_impl[517260a07841a630]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  33:     0x7f479adf5d34 - rustc_interface[5c48368f5debe80d]::interface::run_compiler::<(), rustc_driver_impl[517260a07841a630]::run_compiler::{closure#0}>::{closure#1}
  34:     0x7f479ad5aa3a - std[287527946f71f0bc]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[5c48368f5debe80d]::util::run_in_thread_with_globals<rustc_interface[5c48368f5debe80d]::util::run_in_thread_pool_with_globals<rustc_interface[5c48368f5debe80d]::interface::run_compiler<(), rustc_driver_impl[517260a07841a630]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  35:     0x7f479ad5a7fe - <std[287527946f71f0bc]::thread::lifecycle::spawn_unchecked<rustc_interface[5c48368f5debe80d]::util::run_in_thread_with_globals<rustc_interface[5c48368f5debe80d]::util::run_in_thread_pool_with_globals<rustc_interface[5c48368f5debe80d]::interface::run_compiler<(), rustc_driver_impl[517260a07841a630]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[7477a31a1a34cc49]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  36:     0x7f479ad5c5c4 - <std[287527946f71f0bc]::sys::thread::unix::Thread>::new::thread_start
  37:     0x7f479469698b - <unknown>
  38:     0x7f479471a9cc - <unknown>
  39:                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 (621d76794 2026-01-18) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z next-solver=globally -Z dump-mir-dir=dir

query stack during panic:
#0 [typeck] type-checking `test`
#1 [analysis] running analysis passes on crate `mvce`
end of query stack
error: aborting due to 5 previous errors

Some errors have detailed explanations: E0261, E0658, E0782.
For more information about an error, try `rustc --explain E0261`.

@rustbot label +WG-trait-system-refactor

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-unsafe_binders`#![feature(unsafe_binders)]`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.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions