Skip to content

ICE: Unexpected type Binder for Field projection #141418

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 #141433
Closed

ICE: Unexpected type Binder for Field projection #141418

cushionbadak opened this issue May 23, 2025 · 0 comments · Fixed by #141433
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

cushionbadak commented May 23, 2025

Code

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

use std::unsafe_binder::unwrap_binder;

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

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

fn main() {}

A mutant from tests/ui/attributes/no-mangle-closure.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 --edition=2021

error: internal compiler error: compiler/rustc_middle/src/ty/closure.rs:116:25: Unexpected type Binder { value: S, bound_vars: [Region(BrNamed(DefId(0:5 ~ clos_r[2488]::outer_function::'a), 'a))] } for `Field` projection


thread 'rustc' panicked at compiler/rustc_middle/src/ty/closure.rs:116:25:
Box<dyn Any>
Backtrace

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_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: 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}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: <rustc_middle::ty::closure::CapturedPlace>::to_symbol
   7: <core::iter::adapters::map::Map<core::iter::adapters::enumerate::Enumerate<itertools::zip_eq_impl::ZipEq<core::slice::iter::Iter<&rustc_middle::ty::closure::CapturedPlace>, core::iter::adapters::copied::Copied<core::slice::iter::Iter<rustc_middle::ty::Ty>>>>, <rustc_mir_build::builder::Builder>::insert_upvar_arg::{closure#0}> as core::iter::traits::iterator::Iterator>::next
   8: rustc_mir_build::builder::construct_fn
   9: rustc_mir_build::builder::build_mir
  10: rustc_mir_transform::mir_built
      [... omitted 1 frame ...]
  11: <rustc_mir_build::check_unsafety::UnsafetyVisitor>::visit_inner_body
  12: <rustc_mir_build::check_unsafety::UnsafetyVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  13: <rustc_mir_build::check_unsafety::UnsafetyVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  14: <rustc_mir_build::check_unsafety::UnsafetyVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  15: rustc_middle::thir::visit::walk_expr::<rustc_mir_build::check_unsafety::UnsafetyVisitor>
  16: <rustc_mir_build::check_unsafety::UnsafetyVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  17: <rustc_mir_build::check_unsafety::UnsafetyVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  18: <rustc_mir_build::check_unsafety::UnsafetyVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  19: <rustc_mir_build::check_unsafety::UnsafetyVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
  20: rustc_mir_build::check_unsafety::check_unsafety
      [... omitted 1 frame ...]
  21: <rustc_middle::ty::context::TyCtxt>::par_hir_body_owners::<rustc_interface::passes::run_required_analyses::{closure#2}::{closure#0}>::{closure#0}
  22: rustc_interface::passes::run_required_analyses
  23: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  24: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
  25: 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 `/Volumes/T7/workspace/scratch_250523/run_250522_250505_feat_unsafe_binder/scratch/rustc-ice-2025-05-23T04_29_20-9154.txt` to your bug report

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

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 -- clos_r.rs --edition=2021
********************************************************************************
Regression in 8239a37f9c0951a037cfc51763ea52a20e71e6bd
********************************************************************************

Attempting to search unrolled perf builds
Found commits ["be995312", "150da37e", "20325765", "9264389d", "d38d22f1", "590d9bf4"]
installing be995312299b441ca428237a2b2ba69b769d517e
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: compiler/rustc_middle/src/ty/closure.rs Line-116

    pub fn to_symbol(&self) -> Symbol {
    let mut symbol = self.var_ident.to_string();
    let mut ty = self.place.base_ty;
    for proj in self.place.projections.iter() {
    match proj.kind {
    HirProjectionKind::Field(idx, variant) => match ty.kind() {
    ty::Tuple(_) => write!(&mut symbol, "__{}", idx.index()).unwrap(),
    ty::Adt(def, ..) => {
    write!(
    &mut symbol,
    "__{}",
    def.variant(variant).fields[idx].name.as_str(),
    )
    .unwrap();
    }
    ty => {
    bug!("Unexpected type {:?} for `Field` projection", ty)
    }
    },

  • Issue-117707 has identical ICE location

  • The code in this report is nearly identical to that in ICE: could not resolve upvar: LocalVarId(HirId(DefId)) #141417, except that it uses x: unsafe<'a> S as a parameter, whereas issue-141417 uses x: unsafe<'a> &'a S.

@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
@bors bors closed this as completed in 9f93c48 May 26, 2025
rust-timer added a commit that referenced this issue May 26, 2025
Rollup merge of #141433 - compiler-errors:unsafe-binder-captures, r=oli-obk

Properly analyze captures from unsafe binders

We need to represent the unsafe binder unwrap as an adjustment in HIR. Pretty straightforward b/c we already represent it as a projection elem in MIR.

Fixes #141418
Fixes #141417

r? oli-obk
flip1995 pushed a commit to flip1995/rust that referenced this issue May 31, 2025
…ures, r=oli-obk

Properly analyze captures from unsafe binders

We need to represent the unsafe binder unwrap as an adjustment in HIR. Pretty straightforward b/c we already represent it as a projection elem in MIR.

Fixes rust-lang#141418
Fixes rust-lang#141417

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