rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.61k stars 12.74k forks source link

ICE: `unexpected region` #133118

Open matthiaskrgr opened 14 hours ago

matthiaskrgr commented 14 hours ago

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: ````rust // 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(x: T) -> usize { x.alpha() } pub fn assert_static(_: T) -> usize { 24 } pub fn assert_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 Epsilon<'a>>() {} pub fn assert_forall_epsilon_zeta_satisfies_eta(x: T) -> usize where T: for<'a> Epsilon<'a>, for<'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 Beta for &(dyn Beta + 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(beta: &'a B) -> usize where B: Beta, B::Gamma: Alpha { let gamma: B::Gamma = beta.gamma(); assert_alpha::(gamma) } pub fn desugared_bound_region(beta: &B) -> usize where B: Beta, B::Gamma: 'static, { assert_static::(beta.gamma()) } pub fn desugared_bound_multi(beta: B) -> usize where B: Copy + Beta, B::Gamma: Alpha + 'static + Delta, { assert_alpha::(beta.gamma()) + assert_static::(beta.gamma()) + assert_delta::(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::(gamma) } pub fn desugared_bound_region_forall(beta: &B) -> usize where B: Beta, B::Gamma: Copy + for<'a> Epsilon<'a>, { assert_epsilon_forall::(); let g1: B::Gamma = beta.gamma(); let g2: B::Gamma = g1; assert_epsilon_specific::(&g1) + assert_epsilon_specific::(&g2) } pub fn desugared_bound_region_forall2(beta: &B) -> usize where B: Beta, B::Gamma: Copy + for<'a> Epsilon<'a>, for<'a> >::Zeta: Eta, { let gamma = beta.gamma(); assert_forall_epsilon_zeta_satisfies_eta::(gamma) } pub fn desugared_contraint_region_forall(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(beta: &B) -> usize where B: Beta, B::Gamma: Copy + Alpha + 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::(&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 - ::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::>::{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 - as rustc_type_ir[e277a8613b8235e]::fold::FallibleTypeFolder>::try_fold_region.cold 13: 0x709c560d53ec - as rustc_type_ir[e277a8613b8235e]::fold::TypeFolder>::fold_ty 14: 0x709c560d4665 - as rustc_type_ir[e277a8613b8235e]::fold::TypeFolder>::fold_ty 15: 0x709c560d53fc - as rustc_type_ir[e277a8613b8235e]::fold::TypeFolder>::fold_ty 16: 0x709c545dfdbf - as rustc_type_ir[e277a8613b8235e]::fold::TypeFoldable>::try_fold_with::> 17: 0x709c54683f10 - ::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::> 20: 0x709c56546a01 - rustc_query_system[b3451d088303aafc]::query::plumbing::try_execute_query::>, 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::> 25: 0x709c56fce5ee - rustc_query_system[b3451d088303aafc]::query::plumbing::try_execute_query::>, 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::, rustc_driver_impl[9c473e8d4e391989]::run_compiler::{closure#0}>::{closure#1} 28: 0x709c56f93f90 - std[6334da27d412de0b]::sys::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 - 32: 0x709c5876f49c - 33: 0x0 - 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`. ```

matthiaskrgr commented 14 hours ago

bisects to #132172

matthiaskrgr commented 13 hours ago

version with only ice, no errors

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

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

pub fn a<T: Alpha>(_x: T) -> usize {
    todo!();
}

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

pub fn main() {}
lqd commented 2 hours ago

cc @dianne

dianne commented 2 hours ago

oops! it looks like an easy fix, at least. @rustbot claim