Skip to content

ICE: has escaping bound vars, so it cannot be wrapped in a dummy binder with unsafe_binders #141422

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 23, 2025 · 0 comments · Fixed by #141429
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) ❄️ 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)]

#[derive(PartialEq, Eq)]
enum O<T> {
    Some(T),
    None,
}

const C: &[O<unsafe<'a, 'b> &'b Box<dyn Fn(Box<dyn Fn() -> &'a isize>)>>] = &[O::None];

fn main() {
    let x = O::None;
    match &[x][..] {
        C => (),
        _ => (),
    }
}

A mutant from glacier2's fixed/134764.rs

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (2eef47813 2025-05-22)
binary: rustc
commit-hash: 2eef47813f25df637026ce3288880e5c587abd92
commit-date: 2025-05-22
host: x86_64-apple-darwin
release: 1.89.0-nightly
LLVM version: 20.1.5

Error output

command: rustc

thread 'rustc' panicked at compiler/rustc_middle/src/ty/predicate.rs:510:9:
`<std::boxed::Box<dyn std::ops::Fn(std::boxed::Box<dyn std::ops::Fn() -> &'a isize>)> as std::cmp::PartialEq>` has escaping bound vars, so it cannot be wrapped in a dummy binder.
Backtrace

stack backtrace:
   0: __rustc::rust_begin_unwind
   1: core::panicking::panic_fmt
   2: <rustc_middle::ty::predicate::Predicate as rustc_type_ir::upcast::UpcastFrom<rustc_middle::ty::context::TyCtxt, rustc_type_ir::predicate::TraitRef<rustc_middle::ty::context::TyCtxt>>>::upcast_from
   3: rustc_mir_build::thir::pattern::const_to_pat::type_has_partial_eq_impl
   4: <rustc_mir_build::thir::pattern::const_to_pat::extend_type_not_partial_eq::UsedParamsNeedInstantiationVisitor as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
   5: <rustc_mir_build::thir::pattern::const_to_pat::extend_type_not_partial_eq::UsedParamsNeedInstantiationVisitor as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
   6: <rustc_mir_build::thir::pattern::const_to_pat::extend_type_not_partial_eq::UsedParamsNeedInstantiationVisitor as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
   7: <rustc_middle::ty::Ty as rustc_type_ir::visit::TypeSuperVisitable<rustc_middle::ty::context::TyCtxt>>::super_visit_with::<rustc_mir_build::thir::pattern::const_to_pat::extend_type_not_partial_eq::UsedParamsNeedInstantiationVisitor>
   8: <rustc_mir_build::thir::pattern::const_to_pat::extend_type_not_partial_eq::UsedParamsNeedInstantiationVisitor as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
   9: <rustc_mir_build::thir::pattern::const_to_pat::extend_type_not_partial_eq::UsedParamsNeedInstantiationVisitor as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  10: <rustc_mir_build::thir::pattern::const_to_pat::extend_type_not_partial_eq::UsedParamsNeedInstantiationVisitor as rustc_type_ir::visit::TypeVisitor<rustc_middle::ty::context::TyCtxt>>::visit_ty
  11: <rustc_mir_build::thir::pattern::PatCtxt>::const_to_pat
  12: <rustc_mir_build::thir::pattern::PatCtxt>::lower_pat_expr
  13: <rustc_mir_build::thir::pattern::PatCtxt>::lower_pattern
  14: <rustc_mir_build::thir::cx::ThirBuildCx>::pattern_from_hir
  15: <rustc_mir_build::thir::cx::ThirBuildCx>::make_mirror_unadjusted::{closure#0}
  16: <rustc_mir_build::thir::cx::ThirBuildCx>::mirror_expr_inner
  17: <rustc_mir_build::thir::cx::ThirBuildCx>::mirror_block
  18: <rustc_mir_build::thir::cx::ThirBuildCx>::make_mirror_unadjusted::{closure#0}
  19: <rustc_mir_build::thir::cx::ThirBuildCx>::mirror_expr_inner
  20: rustc_mir_build::thir::cx::thir_body
      [... omitted 2 frames ...]
  21: rustc_mir_build::check_unsafety::check_unsafety
      [... omitted 1 frame ...]
  22: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  23: rustc_interface::passes::run_required_analyses
  24: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  25: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  26: 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.

error: the compiler unexpectedly panicked. this is a bug.

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 `/Volumes/T7/workspace/scratch_250523/run_250522_250505_feat_unsafe_binder/scratch/rustc-ice-2025-05-23T05_41_54-40103.txt` to your bug report

query stack during panic:
#0 [thir_body] building THIR for `main`
#1 [check_unsafety] unsafety-checking `main`
#2 [analysis] running analysis passes on this crate
end of query stack

Bisects to

searched nightlies: from nightly-2024-05-01 to nightly-2025-05-22
regressed nightly: nightly-2024-12-25
searched commit range: bdc6b3d...409998c
regressed commit: f334342

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 -- uncl1_r.rs

Notes

  • ICE location: compiler/rustc_middle/src/ty/predicate.rs Line-510
    impl<'tcx> UpcastFrom<TyCtxt<'tcx>, TraitRef<'tcx>> for Predicate<'tcx> {
    fn upcast_from(from: TraitRef<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
    ty::Binder::dummy(from).upcast(tcx)
    }
    }
  • There are several other ICE issues with the same ICE location as this one, but require different feature and have different query stack.

@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 23, 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 23, 2025
@compiler-errors compiler-errors self-assigned this May 23, 2025
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 23, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 23, 2025
…structural-match, r=spastorino

Dont walk into unsafe binders when emiting error for non-structural type match

Fixes rust-lang#141422.

The other two binder-having types are also special cased here, unsurprisingly.

r? oli-obk
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 24, 2025
…structural-match, r=spastorino

Dont walk into unsafe binders when emiting error for non-structural type match

Fixes rust-lang#141422.

The other two binder-having types are also special cased here, unsurprisingly.

r? oli-obk
@bors bors closed this as completed in 293977a May 24, 2025
rust-timer added a commit that referenced this issue May 24, 2025
Rollup merge of #141429 - compiler-errors:unsafe-binder-non-structural-match, r=spastorino

Dont walk into unsafe binders when emiting error for non-structural type match

Fixes #141422.

The other two binder-having types are also special cased here, unsurprisingly.

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) ❄️ 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