Skip to content

ICE: open drop from non-ADT with unsafe_binder #141394

Closed
@cushionbadak

Description

@cushionbadak

Code

#![feature(unsafe_binders)]
#![allow(incomplete_features)]
use std::unsafe_binder::unwrap_binder;

fn id<T>(x: unsafe<> T) -> T {
    unwrap_binder!(x)
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (bf64d66bd 2025-05-21)
binary: rustc
commit-hash: bf64d66bd58719fac2585eae5e546e5e1d9947f5
commit-date: 2025-05-21
host: aarch64-apple-darwin
release: 1.89.0-nightly
LLVM version: 20.1.5

Error output

command: rustc

error[E0277]: the trait bound `T: Copy` is not satisfied
 --> abc.rs:5:13
  |
5 | fn id<T>(x: unsafe<> T) -> T {
  |             ^^^^^^^^^^ the trait `Copy` is not implemented for `T`
  |
help: consider restricting type parameter `T` with trait `Copy`
  |
5 | fn id<T: std::marker::Copy>(x: unsafe<> T) -> T {
  |        +++++++++++++++++++

error[E0133]: unsafe binder cast is unsafe and requires unsafe block or unsafe fn
 --> abc.rs:6:5
  |
6 |     unwrap_binder!(x)
  |     ^^^^^^^^^^^^^^^^^ unsafe binder cast
  |
  = note: this error originates in the macro `unwrap_binder` (in Nightly builds, run with -Z macro-backtrace for more info)

error: internal compiler error: compiler/rustc_mir_transform/src/elaborate_drop.rs:1281:18: open drop from non-ADT `Binder { value: T/#0, bound_vars: [] }`
 --> abc.rs:7:1
  |
7 | }
  | ^


thread 'rustc' panicked at compiler/rustc_mir_transform/src/elaborate_drop.rs:1281:18:
Box<dyn Any>
Backtrace

thread 'rustc' panicked at compiler/rustc_mir_transform/src/elaborate_drop.rs:1281:18:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: <rustc_errors::DiagCtxtHandle>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <rustc_mir_transform::elaborate_drop::DropCtxt<rustc_mir_transform::elaborate_drops::ElaborateDropsCtxt>>::elaborate_drop
   8: <rustc_mir_transform::elaborate_drops::ElaborateDrops as rustc_mir_transform::pass_manager::MirPass>::run_pass
   9: rustc_mir_transform::pass_manager::run_passes_inner
  10: rustc_mir_transform::run_analysis_to_runtime_passes
  11: rustc_mir_transform::mir_drops_elaborated_and_const_checked
      [... omitted 1 frame ...]
  12: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  13: rustc_interface::passes::run_required_analyses
  14: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  15: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  16: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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: please attach the file at `/Users/jisukbyun/workspace/250203 scratch/rustc-ice-2025-05-22T13_24_03-44785.txt` to your bug report

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `id`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

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

Bisects to

searched nightlies: from nightly-2024-05-01 to nightly-2025-05-22
regressed nightly: nightly-2025-02-02
searched commit range: 854f225...8239a37
regressed commit: 8239a37

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --end=2025-05-22 --regress ice --preserve --script rustc -- abc.rs
********************************************************************************
Regression in 8239a37f9c0951a037cfc51763ea52a20e71e6bd
********************************************************************************

Attempting to search unrolled perf builds
Found commits ["be995312", "150da37e", "20325765", "9264389d", "d38d22f1", "590d9bf4"]
installing be995312299b441ca428237a2b2ba69b769d517e
rust-std-nightly-x86_64-unknown-linux-gnu: 30.31 MB / 30.31 MB [=======================================================================] 100.00 % 13.40 MB/s testing...
RESULT: be995312299b441ca428237a2b2ba69b769d517e, ===> Script found ICE

Regression in https://github.com/rust-lang-ci/rust/commit/be995312299b441ca428237a2b2ba69b769d517e
The PR introducing the regression in this rollup is #130514: Implement MIR lowering for unsafe binders

Notes

  • ICE location: rustc_mir_transform/src/elaborate_drop.rs Line-1281

    fn open_drop(&mut self) -> BasicBlock {
    let ty = self.place_ty(self.place);
    match ty.kind() {
    ty::Closure(_, args) => self.open_drop_for_tuple(args.as_closure().upvar_tys()),
    ty::CoroutineClosure(_, args) => {
    self.open_drop_for_tuple(args.as_coroutine_closure().upvar_tys())
    }
    // Note that `elaborate_drops` only drops the upvars of a coroutine,
    // and this is ok because `open_drop` here can only be reached
    // within that own coroutine's resume function.
    // This should only happen for the self argument on the resume function.
    // It effectively only contains upvars until the coroutine transformation runs.
    // See librustc_body/transform/coroutine.rs for more details.
    ty::Coroutine(_, args) => self.open_drop_for_tuple(args.as_coroutine().upvar_tys()),
    ty::Tuple(fields) => self.open_drop_for_tuple(fields),
    ty::Adt(def, args) => self.open_drop_for_adt(*def, args),
    ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind),
    ty::Array(ety, size) => {
    let size = size.try_to_target_usize(self.tcx());
    self.open_drop_for_array(ty, *ety, size)
    }
    ty::Slice(ety) => self.drop_loop_trio_for_slice(*ety),
    _ => span_bug!(self.source_info.span, "open drop from non-ADT `{:?}`", ty),
    }
    }

  • ICE: open drop from non-ADT  #140930 has identical ICE location and currently open, but it requires different feature & bisection results

@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.requires-incomplete-featuresThis issue requires the use of incomplete features.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions