Skip to content

GCE ICE with nested impl trait ? #118403

New issue

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

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

Already on GitHub? # to your account

Closed
bend-n opened this issue Nov 28, 2023 · 8 comments · Fixed by #125501
Closed

GCE ICE with nested impl trait ? #118403

bend-n opened this issue Nov 28, 2023 · 8 comments · Fixed by #125501
Labels
C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` 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

@bend-n
Copy link
Contributor

bend-n commented Nov 28, 2023

Code

#![feature(generic_const_exprs)]
pub struct X<const N: usize> {}
impl<const Z: usize> X<Z> {
    pub fn y<'a, U: 'a>(&'a self) -> impl Iterator<Item = impl Iterator<Item = [u8; Z]> + '_> {
        (0..1).map(move |_| (0..1).map(move |_| loop {}))
    }
}

Meta

rustc --version --verbose:

rustc 1.76.0-nightly (6cf088810 2023-11-26)
binary: rustc
commit-hash: 6cf088810f66fff15d05bf7135c5f5888b7c93b4
commit-date: 2023-11-26
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.5

Error output

error: internal compiler error: compiler/rustc_borrowck/src/universal_regions.rs:823:36: cannot convert `ReEarlyParam(DefId(0:15 ~ fimg[56fb]::{impl#0}::y::{opaque#0}::'_), 3, '_)` to a region vid
Backtrace

thread 'rustc' panicked at /rustc/6cf088810f66fff15d05bf7135c5f5888b7c93b4/compiler/rustc_errors/src/lib.rs:1659:9:
Box<dyn Any>
stack backtrace:
   0:     0x7fe84a173ae1 - std::backtrace_rs::backtrace::libunwind::trace::h971466d927277fa3
                               at /rustc/6cf088810f66fff15d05bf7135c5f5888b7c93b4/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fe84a173ae1 - std::backtrace_rs::backtrace::trace_unsynchronized::hd7767fb2a34ebeb7
                               at /rustc/6cf088810f66fff15d05bf7135c5f5888b7c93b4/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fe84a173ae1 - std::backtrace::Backtrace::create::hb892135481a1b688
                               at /rustc/6cf088810f66fff15d05bf7135c5f5888b7c93b4/library/std/src/backtrace.rs:332:13
   3:     0x7fe84a173a30 - std::backtrace::Backtrace::force_capture::hcc0ff36807264feb
                               at /rustc/6cf088810f66fff15d05bf7135c5f5888b7c93b4/library/std/src/backtrace.rs:313:9
   4:     0x7fe84cef95bc - std[92f7436d37f6400b]::panicking::update_hook::<alloc[2cf79f262efb1c9d]::boxed::Box<rustc_driver_impl[ac0d00980e4e62ab]::install_ice_hook::{closure#0}>>::{closure#0}
   5:     0x7fe84a18ebe8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h7be51e3dc94f2e68
                               at /rustc/6cf088810f66fff15d05bf7135c5f5888b7c93b4/library/alloc/src/boxed.rs:2021:9
   6:     0x7fe84a18ebe8 - std::panicking::rust_panic_with_hook::hdda4d389ef743292
                               at /rustc/6cf088810f66fff15d05bf7135c5f5888b7c93b4/library/std/src/panicking.rs:783:13
   7:     0x7fe84d339644 - std[92f7436d37f6400b]::panicking::begin_panic::<rustc_errors[211aa307c3319be2]::ExplicitBug>::{closure#0}
   8:     0x7fe84d3339a6 - std[92f7436d37f6400b]::sys_common::backtrace::__rust_end_short_backtrace::<std[92f7436d37f6400b]::panicking::begin_panic<rustc_errors[211aa307c3319be2]::ExplicitBug>::{closure#0}, !>
   9:     0x7fe84d32e806 - std[92f7436d37f6400b]::panicking::begin_panic::<rustc_errors[211aa307c3319be2]::ExplicitBug>
  10:     0x7fe84d316d94 - <rustc_errors[211aa307c3319be2]::HandlerInner>::bug::<alloc[2cf79f262efb1c9d]::string::String>
  11:     0x7fe84d316a9a - <rustc_errors[211aa307c3319be2]::Handler>::bug::<alloc[2cf79f262efb1c9d]::string::String>
  12:     0x7fe84d3b462d - rustc_middle[1557ee54da0b70b7]::util::bug::opt_span_bug_fmt::<rustc_span[9b7676b76ade8fc9]::span_encoding::Span>::{closure#0}
  13:     0x7fe84d39b66a - rustc_middle[1557ee54da0b70b7]::ty::context::tls::with_opt::<rustc_middle[1557ee54da0b70b7]::util::bug::opt_span_bug_fmt<rustc_span[9b7676b76ade8fc9]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7fe84d39b508 - rustc_middle[1557ee54da0b70b7]::ty::context::tls::with_context_opt::<rustc_middle[1557ee54da0b70b7]::ty::context::tls::with_opt<rustc_middle[1557ee54da0b70b7]::util::bug::opt_span_bug_fmt<rustc_span[9b7676b76ade8fc9]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7fe84b373ce0 - rustc_middle[1557ee54da0b70b7]::util::bug::bug_fmt
  16:     0x7fe84b6f2ecd - rustc_borrowck[7a3380052636860a]::type_check::type_check
  17:     0x7fe84b6c72a2 - rustc_borrowck[7a3380052636860a]::nll::compute_regions
  18:     0x7fe84efb840b - rustc_borrowck[7a3380052636860a]::do_mir_borrowck
  19:     0x7fe84efa8a4a - rustc_borrowck[7a3380052636860a]::mir_borrowck
  20:     0x7fe84efa84ef - rustc_query_impl[5c4dc8ec47f4c245]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5c4dc8ec47f4c245]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1557ee54da0b70b7]::query::erase::Erased<[u8; 8usize]>>
  21:     0x7fe84e78b484 - rustc_query_system[2959241e02d82320]::query::plumbing::try_execute_query::<rustc_query_impl[5c4dc8ec47f4c245]::DynamicConfig<rustc_query_system[2959241e02d82320]::query::caches::VecCache<rustc_span[9b7676b76ade8fc9]::def_id::LocalDefId, rustc_middle[1557ee54da0b70b7]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[5c4dc8ec47f4c245]::plumbing::QueryCtxt, true>
  22:     0x7fe84ed098b5 - rustc_query_impl[5c4dc8ec47f4c245]::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace
  23:     0x7fe84ed09e03 - rustc_interface[b8b215ac97ffc74d]::passes::analysis
  24:     0x7fe84ed098f7 - rustc_query_impl[5c4dc8ec47f4c245]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5c4dc8ec47f4c245]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1557ee54da0b70b7]::query::erase::Erased<[u8; 1usize]>>
  25:     0x7fe84f07198b - rustc_query_system[2959241e02d82320]::query::plumbing::try_execute_query::<rustc_query_impl[5c4dc8ec47f4c245]::DynamicConfig<rustc_query_system[2959241e02d82320]::query::caches::SingleCache<rustc_middle[1557ee54da0b70b7]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[5c4dc8ec47f4c245]::plumbing::QueryCtxt, true>
  26:     0x7fe84f071634 - rustc_query_impl[5c4dc8ec47f4c245]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  27:     0x7fe84f13b247 - rustc_interface[b8b215ac97ffc74d]::interface::run_compiler::<core[5c51d25db8a09f66]::result::Result<(), rustc_span[9b7676b76ade8fc9]::ErrorGuaranteed>, rustc_driver_impl[ac0d00980e4e62ab]::run_compiler::{closure#0}>::{closure#0}
  28:     0x7fe84f0ceb14 - std[92f7436d37f6400b]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[b8b215ac97ffc74d]::util::run_in_thread_with_globals<rustc_interface[b8b215ac97ffc74d]::util::run_in_thread_pool_with_globals<rustc_interface[b8b215ac97ffc74d]::interface::run_compiler<core[5c51d25db8a09f66]::result::Result<(), rustc_span[9b7676b76ade8fc9]::ErrorGuaranteed>, rustc_driver_impl[ac0d00980e4e62ab]::run_compiler::{closure#0}>::{closure#0}, core[5c51d25db8a09f66]::result::Result<(), rustc_span[9b7676b76ade8fc9]::ErrorGuaranteed>>::{closure#0}, core[5c51d25db8a09f66]::result::Result<(), rustc_span[9b7676b76ade8fc9]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5c51d25db8a09f66]::result::Result<(), rustc_span[9b7676b76ade8fc9]::ErrorGuaranteed>>
  29:     0x7fe84f0ce93d - <<std[92f7436d37f6400b]::thread::Builder>::spawn_unchecked_<rustc_interface[b8b215ac97ffc74d]::util::run_in_thread_with_globals<rustc_interface[b8b215ac97ffc74d]::util::run_in_thread_pool_with_globals<rustc_interface[b8b215ac97ffc74d]::interface::run_compiler<core[5c51d25db8a09f66]::result::Result<(), rustc_span[9b7676b76ade8fc9]::ErrorGuaranteed>, rustc_driver_impl[ac0d00980e4e62ab]::run_compiler::{closure#0}>::{closure#0}, core[5c51d25db8a09f66]::result::Result<(), rustc_span[9b7676b76ade8fc9]::ErrorGuaranteed>>::{closure#0}, core[5c51d25db8a09f66]::result::Result<(), rustc_span[9b7676b76ade8fc9]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5c51d25db8a09f66]::result::Result<(), rustc_span[9b7676b76ade8fc9]::ErrorGuaranteed>>::{closure#1} as core[5c51d25db8a09f66]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x7fe84a198a85 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb8a1936cb2bbfa85
                               at /rustc/6cf088810f66fff15d05bf7135c5f5888b7c93b4/library/alloc/src/boxed.rs:2007:9
  31:     0x7fe84a198a85 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9073c4fb64c8bde9
                               at /rustc/6cf088810f66fff15d05bf7135c5f5888b7c93b4/library/alloc/src/boxed.rs:2007:9
  32:     0x7fe84a198a85 - std::sys::unix::thread::Thread::new::thread_start::hd722b95607df8f1b
                               at /rustc/6cf088810f66fff15d05bf7135c5f5888b7c93b4/library/std/src/sys/unix/thread.rs:108:17
  33:     0x7fe849f899eb - <unknown>
  34:     0x7fe84a00d7cc - <unknown>
  35:                0x0 - <unknown>


rustc version: 1.76.0-nightly (6cf088810 2023-11-26)
platform: x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `<impl at src/lib.rs:3:1: 3:26>::y::{constant#0}`
#1 [analysis] running analysis passes on this crate
end of query stack

@bend-n bend-n added C-bug Category: This is a bug. 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. labels Nov 28, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 28, 2023
@saethlin saethlin added the F-generic_const_exprs `#![feature(generic_const_exprs)]` label Nov 28, 2023
@saethlin
Copy link
Member

Is this a duplicate of #114464?

@bend-n
Copy link
Contributor Author

bend-n commented Nov 28, 2023

i think so

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 28, 2023
@saethlin
Copy link
Member

I wish there were a "close as duplidate" for this. Ah well.

@bend-n
Copy link
Contributor Author

bend-n commented Nov 28, 2023

there is actually, if you click the drop down on the close button

@saethlin
Copy link
Member

Hunh, they mean to include that in "not planned". Strange.

@saethlin saethlin closed this as not planned Won't fix, can't repro, duplicate, stale Nov 28, 2023
@bend-n
Copy link
Contributor Author

bend-n commented May 19, 2024

@saethlin the "duplicate" issue is closed but this is still failing.

@bend-n
Copy link
Contributor Author

bend-n commented May 20, 2024

Also ive found that even if you do this without nesting the impl trait it still ICE's.

@bend-n
Copy link
Contributor Author

bend-n commented May 20, 2024

And if you do

#![feature(generic_const_exprs)]
pub struct X<const N: usize> {}
impl<const Z: usize> X<Z> {
    pub fn y<U>(&self) -> impl Iterator<Item = impl Iterator<Item = [u8; Z]> + '_> {
        (0..1).map(move |_| (0..1).map(move |_| loop {}))
    }
}

it succeeds.

@bors bors closed this as completed in 104e1a4 May 24, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 24, 2024
Rollup merge of rust-lang#125501 - compiler-errors:opaque-opaque-anon-ct, r=BoxyUwU

Resolve anon const's parent predicates to direct parent instead of opaque's parent

When an anon const is inside of an opaque, rust-lang#99801 added a hack to resolve the anon const's parent predicates *not* to the opaque's predicates, but to the opaque's *parent's* predicates. This is insufficient when considering nested opaques.

This means that the `predicates_of` an anon const might reference duplicated lifetimes (installed by `compute_bidirectional_outlives_predicates`) when computing known outlives in MIR borrowck, leading to these ICEs:
Fixes rust-lang#121574
Fixes rust-lang#118403

~~Instead, we should be using the `OpaqueTypeOrigin` to acquire the owner item (fn/type alias/etc) of the opaque, whose predicates we're fine to mention.~~

~~I think it's a bit sketchy that we're doing this at all, tbh; I think it *should* be fine for the anon const to inherit the predicates of the opaque it's located inside. However, that would also mean that we need to make sure the `generics_of` that anon const line up in the same way.~~

~~None of this is important to solve right now; I just want to fix these ICEs so we can land rust-lang#125468, which accidentally fixes these issues in a different and unrelated way.~~

edit: We don't need this special case anyways because we install the right parent item in `generics_of` anyways:
https://github.com/rust-lang/rust/blob/213ad10c8f0fc275648552366275dc4e07f97462/compiler/rustc_hir_analysis/src/collect/generics_of.rs#L150

r? `@BoxyUwU`
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` 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
3 participants