Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cushionbadak opened this issue May 22, 2025 · 0 comments · Fixed by #141431
Closed

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

cushionbadak opened this issue May 22, 2025 · 0 comments · Fixed by #141431
Assignees
Labels
C-bug Category: This is a bug. F-unsafe_binders `#![feature(unsafe_binders)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cushionbadak
Copy link

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

@cushionbadak cushionbadak added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 22, 2025
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-unsafe_binders `#![feature(unsafe_binders)]` labels May 22, 2025
@jieyouxu jieyouxu added requires-incomplete-features This issue requires the use of incomplete features. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 22, 2025
@compiler-errors compiler-errors self-assigned this May 23, 2025
@bors bors closed this as completed in 0e710d0 May 26, 2025
rust-timer added a commit that referenced this issue May 26, 2025
Rollup merge of #141431 - compiler-errors:open-drop, r=oli-obk

Emit dummy open drop for unsafe binder

Fixes #141394

We can't taint the body in wfcheck when we have a `T: Copy` bound failure, so we end up binding MIR here. Emit a dummy open drop so that drop elaboration doesn't fail.

r? oli-obk
github-actions bot pushed a commit to rust-lang/miri that referenced this issue May 27, 2025
Emit dummy open drop for unsafe binder

Fixes rust-lang/rust#141394

We can't taint the body in wfcheck when we have a `T: Copy` bound failure, so we end up binding MIR here. Emit a dummy open drop so that drop elaboration doesn't fail.

r? oli-obk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-unsafe_binders `#![feature(unsafe_binders)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants