Skip to content

ICE: Unexpected projection UnwrapUnsafeBinder in captured place #141655

Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

//@compile-flags: --edition=2024
use std::unsafe_binder::unwrap_binder;

pub struct S([usize; 8]);

pub fn by_ref(x: unsafe<'a> &'a S) -> usize {
    unsafe { (|| unwrap_binder!(x).0[0])() }
}

fn main() {}

original:

//@ check-pass

#![feature(unsafe_binders)]
#![allow(incomplete_features)]

use std::unsafe_binder::unwrap_binder;

#[derive(Copy, Clone)]
pub struct S([usize; 8]);

// Regression test for <https://github.com/rust-lang/rust/issues/141418>.
pub fn by_value() -> usize {
    unsafe { (|| unwrap_binder!(x).0[0])() }
}

// Regression test for <https://github.com/rust-lang/rust/issues/141417>.
pub fn by_ref(x: unsafe<'a> &'a S) -> usize {
    unsafe { (|| unwrap_binder!(x).0[0])() }
}

fn main() {}

Version information

rustc 1.89.0-nightly (0fc6f1672 2025-05-27)
binary: rustc
commit-hash: 0fc6f1672bdde8163164f10e46d2d9ffcaeb2161
commit-date: 2025-05-27
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5

Possibly related line of code:

// Ignore derefs for now, as they are likely caused by
// autoderefs that don't appear in the original code.
HirProjectionKind::Deref => {}
// Just change the type to the hidden type, so we can actually project.
HirProjectionKind::OpaqueCast => {}
proj => bug!("Unexpected projection {:?} in captured place", proj),
}
ty = proj.ty;
}
Symbol::intern(&symbol)
}

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

Program output

error[E0658]: use of unstable library feature `unsafe_binders`
 --> /tmp/icemaker_global_tempdir.50zfwHHDvwXl/rustc_testrunner_tmpdir_reporting.4OcdbwBUYhu3/mvce.rs:6:18
  |
6 |     unsafe { (|| unwrap_binder!(x).0[0])() }
  |                  ^^^^^^^^^^^^^
  |
  = 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 2025-05-27; consider upgrading it if it is out of date

error[E0658]: unsafe binder types are experimental
 --> /tmp/icemaker_global_tempdir.50zfwHHDvwXl/rustc_testrunner_tmpdir_reporting.4OcdbwBUYhu3/mvce.rs:5:18
  |
5 | pub fn by_ref(x: unsafe<'a> &'a S) -> usize {
  |                  ^^^^^^^^^^^^^^^^
  |
  = 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 2025-05-27; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `unsafe_binders`
 --> /tmp/icemaker_global_tempdir.50zfwHHDvwXl/rustc_testrunner_tmpdir_reporting.4OcdbwBUYhu3/mvce.rs:1:5
  |
1 | use std::unsafe_binder::unwrap_binder;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = 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 2025-05-27; consider upgrading it if it is out of date

error: internal compiler error: compiler/rustc_middle/src/ty/closure.rs:125:25: Unexpected projection UnwrapUnsafeBinder in captured place


thread 'rustc' panicked at compiler/rustc_middle/src/ty/closure.rs:125:25:
Box<dyn Any>
stack backtrace:
   0:     0x7672d3984be3 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h3b9a9a8f9afe2978
   1:     0x7672d4005877 - core::fmt::write::h4e1b49ee317ba2c1
   2:     0x7672d50a4b51 - std::io::Write::write_fmt::h8810ad49611643d5
   3:     0x7672d3984a42 - std::sys::backtrace::BacktraceLock::print::he7787a086340fe3d
   4:     0x7672d398863a - std::panicking::default_hook::{{closure}}::h3d0be24f46d3333d
   5:     0x7672d39881bf - std::panicking::default_hook::h6a26317d909b670e
   6:     0x7672d29ad4a3 - std[1de0a944af56b7fd]::panicking::update_hook::<alloc[9277edbaee065a35]::boxed::Box<rustc_driver_impl[f6bd67740645566a]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7672d3988eb3 - std::panicking::rust_panic_with_hook::h0389ddb72eaa80ab
   8:     0x7672d29e92e1 - std[1de0a944af56b7fd]::panicking::begin_panic::<rustc_errors[2964549f3939a786]::ExplicitBug>::{closure#0}
   9:     0x7672d29dd1b6 - std[1de0a944af56b7fd]::sys::backtrace::__rust_end_short_backtrace::<std[1de0a944af56b7fd]::panicking::begin_panic<rustc_errors[2964549f3939a786]::ExplicitBug>::{closure#0}, !>
  10:     0x7672d29d98b9 - std[1de0a944af56b7fd]::panicking::begin_panic::<rustc_errors[2964549f3939a786]::ExplicitBug>
  11:     0x7672d29f3a51 - <rustc_errors[2964549f3939a786]::diagnostic::BugAbort as rustc_errors[2964549f3939a786]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7672d30603ca - rustc_middle[2efbfaabdd3081e6]::util::bug::opt_span_bug_fmt::<rustc_span[d076f981bdc4ecb]::span_encoding::Span>::{closure#0}
  13:     0x7672d303a78a - rustc_middle[2efbfaabdd3081e6]::ty::context::tls::with_opt::<rustc_middle[2efbfaabdd3081e6]::util::bug::opt_span_bug_fmt<rustc_span[d076f981bdc4ecb]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7672d303a5fb - rustc_middle[2efbfaabdd3081e6]::ty::context::tls::with_context_opt::<rustc_middle[2efbfaabdd3081e6]::ty::context::tls::with_opt<rustc_middle[2efbfaabdd3081e6]::util::bug::opt_span_bug_fmt<rustc_span[d076f981bdc4ecb]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7672d028ddf0 - rustc_middle[2efbfaabdd3081e6]::util::bug::bug_fmt
  16:     0x7672d484534b - <rustc_middle[2efbfaabdd3081e6]::ty::closure::CapturedPlace>::to_symbol
  17:     0x7672d4845404 - <core[1208049e27034f4]::iter::adapters::map::Map<core[1208049e27034f4]::iter::adapters::enumerate::Enumerate<itertools[e2e07451e61e8fa7]::zip_eq_impl::ZipEq<core[1208049e27034f4]::slice::iter::Iter<&rustc_middle[2efbfaabdd3081e6]::ty::closure::CapturedPlace>, core[1208049e27034f4]::iter::adapters::copied::Copied<core[1208049e27034f4]::slice::iter::Iter<rustc_middle[2efbfaabdd3081e6]::ty::Ty>>>>, <rustc_mir_build[8f316e1c3d4f79aa]::builder::Builder>::insert_upvar_arg::{closure#0}> as core[1208049e27034f4]::iter::traits::iterator::Iterator>::next
  18:     0x7672d43a6c82 - rustc_mir_build[8f316e1c3d4f79aa]::builder::build_mir
  19:     0x7672d400a76b - rustc_mir_transform[321b234f88247587]::mir_built
  20:     0x7672d400a725 - rustc_query_impl[d2bb6511285c7951]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d2bb6511285c7951]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2efbfaabdd3081e6]::query::erase::Erased<[u8; 8usize]>>
  21:     0x7672d4385d26 - rustc_query_system[43ff9477352cc0fd]::query::plumbing::try_execute_query::<rustc_query_impl[d2bb6511285c7951]::DynamicConfig<rustc_data_structures[3347c203b1ac37ca]::vec_cache::VecCache<rustc_span[d076f981bdc4ecb]::def_id::LocalDefId, rustc_middle[2efbfaabdd3081e6]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[43ff9477352cc0fd]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[d2bb6511285c7951]::plumbing::QueryCtxt, false>
  22:     0x7672d4385852 - rustc_query_impl[d2bb6511285c7951]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  23:     0x7672d49fe8c0 - <rustc_mir_build[8f316e1c3d4f79aa]::check_unsafety::UnsafetyVisitor>::visit_inner_body
  24:     0x7672d4a00468 - <rustc_mir_build[8f316e1c3d4f79aa]::check_unsafety::UnsafetyVisitor as rustc_middle[2efbfaabdd3081e6]::thir::visit::Visitor>::visit_expr
  25:     0x7672d4a00ea3 - <rustc_mir_build[8f316e1c3d4f79aa]::check_unsafety::UnsafetyVisitor as rustc_middle[2efbfaabdd3081e6]::thir::visit::Visitor>::visit_expr
  26:     0x7672d4a00468 - <rustc_mir_build[8f316e1c3d4f79aa]::check_unsafety::UnsafetyVisitor as rustc_middle[2efbfaabdd3081e6]::thir::visit::Visitor>::visit_expr
  27:     0x7672d49fffca - <rustc_mir_build[8f316e1c3d4f79aa]::check_unsafety::UnsafetyVisitor as rustc_middle[2efbfaabdd3081e6]::thir::visit::Visitor>::visit_block
  28:     0x7672d4a00468 - <rustc_mir_build[8f316e1c3d4f79aa]::check_unsafety::UnsafetyVisitor as rustc_middle[2efbfaabdd3081e6]::thir::visit::Visitor>::visit_expr
  29:     0x7672d4a00468 - <rustc_mir_build[8f316e1c3d4f79aa]::check_unsafety::UnsafetyVisitor as rustc_middle[2efbfaabdd3081e6]::thir::visit::Visitor>::visit_expr
  30:     0x7672d49d5468 - rustc_mir_build[8f316e1c3d4f79aa]::check_unsafety::check_unsafety
  31:     0x7672d49d4f77 - rustc_query_impl[d2bb6511285c7951]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d2bb6511285c7951]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2efbfaabdd3081e6]::query::erase::Erased<[u8; 0usize]>>
  32:     0x7672d49d4585 - rustc_query_system[43ff9477352cc0fd]::query::plumbing::try_execute_query::<rustc_query_impl[d2bb6511285c7951]::DynamicConfig<rustc_data_structures[3347c203b1ac37ca]::vec_cache::VecCache<rustc_span[d076f981bdc4ecb]::def_id::LocalDefId, rustc_middle[2efbfaabdd3081e6]::query::erase::Erased<[u8; 0usize]>, rustc_query_system[43ff9477352cc0fd]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[d2bb6511285c7951]::plumbing::QueryCtxt, false>
  33:     0x7672d49d4253 - rustc_query_impl[d2bb6511285c7951]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7672d4384208 - <rustc_middle[2efbfaabdd3081e6]::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface[f309adbf33024a8]::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  35:     0x7672d4382532 - rustc_interface[f309adbf33024a8]::passes::run_required_analyses
  36:     0x7672d4f299de - rustc_interface[f309adbf33024a8]::passes::analysis
  37:     0x7672d4f299b5 - rustc_query_impl[d2bb6511285c7951]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d2bb6511285c7951]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2efbfaabdd3081e6]::query::erase::Erased<[u8; 0usize]>>
  38:     0x7672d4f2baba - rustc_query_system[43ff9477352cc0fd]::query::plumbing::try_execute_query::<rustc_query_impl[d2bb6511285c7951]::DynamicConfig<rustc_query_system[43ff9477352cc0fd]::query::caches::SingleCache<rustc_middle[2efbfaabdd3081e6]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[d2bb6511285c7951]::plumbing::QueryCtxt, false>
  39:     0x7672d4f2b78f - rustc_query_impl[d2bb6511285c7951]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  40:     0x7672d516fa07 - rustc_interface[f309adbf33024a8]::passes::create_and_enter_global_ctxt::<core[1208049e27034f4]::option::Option<rustc_interface[f309adbf33024a8]::queries::Linker>, rustc_driver_impl[f6bd67740645566a]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  41:     0x7672d519df0f - rustc_interface[f309adbf33024a8]::interface::run_compiler::<(), rustc_driver_impl[f6bd67740645566a]::run_compiler::{closure#0}>::{closure#1}
  42:     0x7672d509f006 - std[1de0a944af56b7fd]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[f309adbf33024a8]::util::run_in_thread_with_globals<rustc_interface[f309adbf33024a8]::util::run_in_thread_pool_with_globals<rustc_interface[f309adbf33024a8]::interface::run_compiler<(), rustc_driver_impl[f6bd67740645566a]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  43:     0x7672d509ecab - <<std[1de0a944af56b7fd]::thread::Builder>::spawn_unchecked_<rustc_interface[f309adbf33024a8]::util::run_in_thread_with_globals<rustc_interface[f309adbf33024a8]::util::run_in_thread_pool_with_globals<rustc_interface[f309adbf33024a8]::interface::run_compiler<(), rustc_driver_impl[f6bd67740645566a]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[1208049e27034f4]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  44:     0x7672d509fffd - std::sys::pal::unix::thread::Thread::new::thread_start::h1c226e95140392c7
  45:     0x7672ceea57eb - <unknown>
  46:     0x7672cef2918c - <unknown>
  47:                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.89.0-nightly (0fc6f1672 2025-05-27) running on x86_64-unknown-linux-gnu

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

query stack during panic:
#0 [mir_built] building MIR for `by_ref::{closure#0}`
#1 [check_unsafety] unsafety-checking `by_ref`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

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

@rustbot label +F-unsafe_binders

Metadata

Metadata

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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions