Skip to content

ICE: unexpected region #133118

Closed
Closed
@matthiaskrgr

Description

@matthiaskrgr

auto-reduced (treereduce-rust):

// Traits:

pub trait Alpha {
    fn alpha(self) -> usize;
}

pub trait Beta {
    type Gamma;
    fn gamma(&self) -> Self::Gamma;
}

pub fn assert_alpha<T: Alpha>(x: T) -> usize {
    x.alpha()
}

pub fn desugared_contraint_region_forall<B: ?Sized>(beta: &B) -> usize
where
    for<'a> &'a B: Beta,
    for<'a> <&'a B as Beta>::Gamma: Alpha,
{
    let g1 = beta.gamma();

    assert_alpha(g1) + assert_alpha(g1)
}
original code

original:

// Traits:

pub trait Alpha {
    fn alpha(self) -> usize;
}

pub trait Beta {
    type Gamma;
    fn gamma(&self) -> Self::Gamma;
}

pub trait Delta {
    fn delta(self) -> usize;
}

pub trait Epsilon<'a> {
    type Zeta;
    fn zeta(&'a self) -> Self::Zeta;

    fn epsilon(&'a self) -> usize;
}

pub trait Eta {
    fn eta(self) -> usize;
}

// Assertions:

pub fn assert_alpha<T: Alpha>(x: T) -> usize { x.alpha() }
pub fn assert_static<T: 'static>(_: T) -> usize { 24 }
pub fn assert_delta<T: Delta>(x: T) -> usize { x.delta() }
pub fn assert_epsilon_specific<'a, T: 'a + Epsilon<'a>>(x: for<'a> <&'a B as Beta>::Gamma'a T) -> usize { x.epsilon() }
pub fn assert_epsilon_forall<T: for<'a> Epsilon<'a>>() {}
pub fn assert_forall_epsilon_zeta_satisfies_eta<T>(x: T) -> usize
where
    T: for<'a> Epsilon<'a>,
    for<'a> <T as Epsilon<'a>>::Zeta: Eta,
{
    x.epsilon() + x.zeta().eta()
}

// Implementations and types:

#[derive(Copy, Clone)]
pub struct BetaType;

#[derive(Copy, Clone)]
pub struct GammaType;

#[derive(Copy, Clone)]
pub struct ZetaType;

impl<T> Beta for &(dyn Beta<Gamma = T> + Send) {
    type Gamma = T;
    fn gamma(&self) -> Self::Gamma { (*self).gamma() }
}

impl Beta for BetaType {
    type Gamma = GammaType;
    fn gamma(&self) -> Self::Gamma { GammaType }
}

impl<'a> Beta for &'a BetaType {
    type Gamma = GammaType;
    fn gamma(&self) -> Self::Gamma { GammaType }
}

impl Beta for GammaType {
    type Gamma = Self;
    fn gamma(&self) -> Self::Gamma { Self }
}

impl Alpha for GammaType {
    fn alpha(self) -> usize { 42 }
}

impl Delta for GammaType {
    fn delta(self) -> usize { 1337 }
}

impl<'a> Epsilon<'a> for GammaType {
    type Zeta = ZetaType;
    fn zeta(&'a self) -> Self::Zeta { ZetaType }

    fn epsilon(&'a self) -> usize { 7331 }
}

impl Eta for ZetaType {
    fn eta(self) -> usize { 7 }
}

// Desugared forms to check against:

pub fn desugared_bound<B: ?Sized>(beta: &'a B) -> usize
where
    B: Beta,
    B::Gamma: Alpha
{
    let gamma: B::Gamma = beta.gamma();
    assert_alpha::<B::Gamma>(gamma)
}

pub fn desugared_bound_region<B: ?Sized>(beta: &B) -> usize
where
    B: Beta,
    B::Gamma: 'static,
{
    assert_static::<B::Gamma>(beta.gamma())
}

pub fn desugared_bound_multi<B: ?Sized>(beta: B) -> usize
where
    B: Copy + Beta,
    B::Gamma: Alpha + 'static + Delta,
{
    assert_alpha::<B::Gamma>(beta.gamma()) +
    assert_static::<B::Gamma>(beta.gamma()) +
    assert_delta::<B::Gamma>(beta.gamma())
}

pub fn desugared_bound_region_specific<'a, B: ?Sized>(gamma: &'a B::Gamma) -> usize
where
    B: Beta,
    B::Gamma: 'a + Epsilon<'a>,
{
    assert_epsilon_specific::<B::Gamma>(gamma)
}

pub fn desugared_bound_region_forall<B: ?Sized>(beta: &B) -> usize
where
    B: Beta,
    B::Gamma: Copy + for<'a> Epsilon<'a>,
{
    assert_epsilon_forall::<B::Gamma>();
    let g1: B::Gamma = beta.gamma();
    let g2: B::Gamma = g1;
    assert_epsilon_specific::<B::Gamma>(&g1) +
    assert_epsilon_specific::<B::Gamma>(&g2)
}

pub fn desugared_bound_region_forall2<B: ?Sized>(beta: &B) -> usize
where
    B: Beta,
    B::Gamma: Copy + for<'a> Epsilon<'a>,
    for<'a> <B::Gamma as Epsilon<'a>>::Zeta: Eta,
{
    let gamma = beta.gamma();
    assert_forall_epsilon_zeta_satisfies_eta::<B::Gamma>(gamma)
}

pub fn desugared_contraint_region_forall<B: ?Sized>(beta: &B) -> usize
where
    for<'a> &'a B: Beta,
    for<'a> <&'a B as Beta>::Gamma: Alpha,
{
    let g1 = beta.gamma();
    let g2 = beta.gamma();
    assert_alpha(g1) + assert_alpha(g1)
}

pub fn desugared_bound_nested<B: ?Sized>(beta: &B) -> usize
where
    B: Beta,
    B::Gamma: Copy + Alpha + Beta,
    <B::Gamma as Beta>::Gamma: Delta,
{
    let go = beta.gamma();
    let gi = go.gamma();
    go.alpha() + gi.delta()
}

pub fn desugared() {
    let beta = BetaType;
    let gamma = beta.gamma();

    assert_eq!(42, desugared_bound(&beta));
    assert_eq!(24, desugared_bound_region(&beta));
    assert_eq!(42 + 24 + 1337, desugared_bound_multi(beta));
    assert_eq!(7331, desugared_bound_region_specific::<BetaType>(&gamma));
    assert_eq!(7331 * 2, desugared_bound_region_forall(&beta));
    assert_eq!(42 + 1337, desugared_bound_nested(&beta));
}

Version information

rustc 1.84.0-nightly (46e8d2030 2024-11-16)
binary: rustc
commit-hash: 46e8d20301cb4abe91ab0a4bea43bb085e1d4e4a
commit-date: 2024-11-16
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.7Mf1z6zUPbwx/rustc_testrunner_tmpdir_reporting.1L1DDxwRUtA0/mvce.rs:24:2
   |
24 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.7Mf1z6zUPbwx/rustc_testrunner_tmpdir_reporting.1L1DDxwRUtA0/mvce.rs`

thread 'rustc' panicked at /rustc/46e8d20301cb4abe91ab0a4bea43bb085e1d4e4a/compiler/rustc_type_ir/src/binder.rs:682:29:
unexpected region: '?8
stack backtrace:
   0:     0x709c55880ada - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h6cf6c58d1430674a
   1:     0x709c56003f26 - core::fmt::write::h12c8614131e5a0e2
   2:     0x709c574d2d51 - std::io::Write::write_fmt::h65426e05a409335a
   3:     0x709c55880932 - std::sys::backtrace::BacktraceLock::print::h23435b39816a063d
   4:     0x709c55882e36 - std::panicking::default_hook::{{closure}}::h7097ce04782c6128
   5:     0x709c55882c80 - std::panicking::default_hook::h6259d18d30797f5c
   6:     0x709c549088f1 - std[6334da27d412de0b]::panicking::update_hook::<alloc[7b2e653fc387f7f]::boxed::Box<rustc_driver_impl[9c473e8d4e391989]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x709c55883548 - std::panicking::rust_panic_with_hook::h7ab74d8372f90995
   8:     0x709c5588331a - std::panicking::begin_panic_handler::{{closure}}::h79c22ba4286836e5
   9:     0x709c55880f89 - std::sys::backtrace::__rust_end_short_backtrace::h9bfe3d1da29d1ed0
  10:     0x709c55882fdc - rust_begin_unwind
  11:     0x709c522e0c90 - core::panicking::panic_fmt::h4b8e026cf8be1259
  12:     0x709c576516b4 - <rustc_type_ir[e277a8613b8235e]::binder::ArgFolder<rustc_middle[4002b1cd02f10f55]::ty::context::TyCtxt> as rustc_type_ir[e277a8613b8235e]::fold::FallibleTypeFolder<rustc_middle[4002b1cd02f10f55]::ty::context::TyCtxt>>::try_fold_region.cold
  13:     0x709c560d53ec - <rustc_type_ir[e277a8613b8235e]::binder::ArgFolder<rustc_middle[4002b1cd02f10f55]::ty::context::TyCtxt> as rustc_type_ir[e277a8613b8235e]::fold::TypeFolder<rustc_middle[4002b1cd02f10f55]::ty::context::TyCtxt>>::fold_ty
  14:     0x709c560d4665 - <rustc_type_ir[e277a8613b8235e]::binder::ArgFolder<rustc_middle[4002b1cd02f10f55]::ty::context::TyCtxt> as rustc_type_ir[e277a8613b8235e]::fold::TypeFolder<rustc_middle[4002b1cd02f10f55]::ty::context::TyCtxt>>::fold_ty
  15:     0x709c560d53fc - <rustc_type_ir[e277a8613b8235e]::binder::ArgFolder<rustc_middle[4002b1cd02f10f55]::ty::context::TyCtxt> as rustc_type_ir[e277a8613b8235e]::fold::TypeFolder<rustc_middle[4002b1cd02f10f55]::ty::context::TyCtxt>>::fold_ty
  16:     0x709c545dfdbf - <rustc_type_ir[e277a8613b8235e]::predicate_kind::ClauseKind<rustc_middle[4002b1cd02f10f55]::ty::context::TyCtxt> as rustc_type_ir[e277a8613b8235e]::fold::TypeFoldable<rustc_middle[4002b1cd02f10f55]::ty::context::TyCtxt>>::try_fold_with::<rustc_type_ir[e277a8613b8235e]::binder::ArgFolder<rustc_middle[4002b1cd02f10f55]::ty::context::TyCtxt>>
  17:     0x709c54683f10 - <rustc_borrowck[5f36680e0c60219b]::MirBorrowckCtxt>::report_use_of_moved_or_uninitialized
  18:     0x709c571bcd14 - rustc_borrowck[5f36680e0c60219b]::do_mir_borrowck
  19:     0x709c5716d44a - rustc_query_impl[7a91563b1a661356]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7a91563b1a661356]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4002b1cd02f10f55]::query::erase::Erased<[u8; 8usize]>>
  20:     0x709c56546a01 - rustc_query_system[b3451d088303aafc]::query::plumbing::try_execute_query::<rustc_query_impl[7a91563b1a661356]::DynamicConfig<rustc_query_system[b3451d088303aafc]::query::caches::VecCache<rustc_span[e7b1f6f0fcf803a2]::def_id::LocalDefId, rustc_middle[4002b1cd02f10f55]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[7a91563b1a661356]::plumbing::QueryCtxt, false>
  21:     0x709c5654650d - rustc_query_impl[7a91563b1a661356]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  22:     0x709c5676d3f6 - rustc_interface[f004a466847c2b55]::passes::run_required_analyses
  23:     0x709c56dd92de - rustc_interface[f004a466847c2b55]::passes::analysis
  24:     0x709c56dd92af - rustc_query_impl[7a91563b1a661356]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7a91563b1a661356]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4002b1cd02f10f55]::query::erase::Erased<[u8; 1usize]>>
  25:     0x709c56fce5ee - rustc_query_system[b3451d088303aafc]::query::plumbing::try_execute_query::<rustc_query_impl[7a91563b1a661356]::DynamicConfig<rustc_query_system[b3451d088303aafc]::query::caches::SingleCache<rustc_middle[4002b1cd02f10f55]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7a91563b1a661356]::plumbing::QueryCtxt, false>
  26:     0x709c56fce2ce - rustc_query_impl[7a91563b1a661356]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  27:     0x709c56ee78fa - rustc_interface[f004a466847c2b55]::interface::run_compiler::<core[f9349800c250a8d6]::result::Result<(), rustc_span[e7b1f6f0fcf803a2]::ErrorGuaranteed>, rustc_driver_impl[9c473e8d4e391989]::run_compiler::{closure#0}>::{closure#1}
  28:     0x709c56f93f90 - std[6334da27d412de0b]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[f004a466847c2b55]::util::run_in_thread_with_globals<rustc_interface[f004a466847c2b55]::util::run_in_thread_pool_with_globals<rustc_interface[f004a466847c2b55]::interface::run_compiler<core[f9349800c250a8d6]::result::Result<(), rustc_span[e7b1f6f0fcf803a2]::ErrorGuaranteed>, rustc_driver_impl[9c473e8d4e391989]::run_compiler::{closure#0}>::{closure#1}, core[f9349800c250a8d6]::result::Result<(), rustc_span[e7b1f6f0fcf803a2]::ErrorGuaranteed>>::{closure#0}, core[f9349800c250a8d6]::result::Result<(), rustc_span[e7b1f6f0fcf803a2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f9349800c250a8d6]::result::Result<(), rustc_span[e7b1f6f0fcf803a2]::ErrorGuaranteed>>
  29:     0x709c56f943ab - <<std[6334da27d412de0b]::thread::Builder>::spawn_unchecked_<rustc_interface[f004a466847c2b55]::util::run_in_thread_with_globals<rustc_interface[f004a466847c2b55]::util::run_in_thread_pool_with_globals<rustc_interface[f004a466847c2b55]::interface::run_compiler<core[f9349800c250a8d6]::result::Result<(), rustc_span[e7b1f6f0fcf803a2]::ErrorGuaranteed>, rustc_driver_impl[9c473e8d4e391989]::run_compiler::{closure#0}>::{closure#1}, core[f9349800c250a8d6]::result::Result<(), rustc_span[e7b1f6f0fcf803a2]::ErrorGuaranteed>>::{closure#0}, core[f9349800c250a8d6]::result::Result<(), rustc_span[e7b1f6f0fcf803a2]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f9349800c250a8d6]::result::Result<(), rustc_span[e7b1f6f0fcf803a2]::ErrorGuaranteed>>::{closure#1} as core[f9349800c250a8d6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x709c56f94e79 - std::sys::pal::unix::thread::Thread::new::thread_start::h1cf41b20a7571fa9
  31:     0x709c586ea39d - <unknown>
  32:     0x709c5876f49c - <unknown>
  33:                0x0 - <unknown>

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: rustc 1.84.0-nightly (46e8d2030 2024-11-16) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `desugared_contraint_region_forall`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.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.T-typesRelevant to the types 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