Skip to content
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

ICE with higher-ranked nested RPIT #97099

Closed
Dirbaio opened this issue May 17, 2022 · 4 comments · Fixed by #113575
Closed

ICE with higher-ranked nested RPIT #97099

Dirbaio opened this issue May 17, 2022 · 4 comments · Fixed by #113575
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-lifetimes Area: Lifetimes / regions glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@Dirbaio
Copy link
Contributor

Dirbaio commented May 17, 2022

I arrived at this by trying to make #97098 work on stable. I don't know if the root cause is the same, since the ICE message is different I'm posting it anyway.

playground

pub trait Trait<'a> {
    type Assoc;
}

struct Struct;
impl<'a> Trait<'a> for Struct {
    type Assoc = &'a u32;
}

fn blah() -> impl for<'a> Trait<'a, Assoc = impl Sized> {
    Struct
}

It fails to build in stable (I think it should build though..?)

error: implementation of `Trait` is not general enough
  --> src/lib.rs:10:14
   |
10 | fn blah() -> impl for<'a> Trait<'a, Assoc = impl Sized> {
   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Trait` is not general enough
   |
   = note: `Struct` must implement `Trait<'0>`, for any lifetime `'0`...
   = note: ...but it actually implements `Trait<'1>`, for some specific lifetime `'1`

but It ICEs in latest nightly

thread 'rustc' panicked at 'assertion failed: self.scc_universes[scc] == ty::UniverseIndex::ROOT', compiler/rustc_borrowck/src/region_infer/mod.rs:708:9
stack backtrace:
   0:     0x7f078620ef8d - std::backtrace_rs::backtrace::libunwind::trace::h67b1c8cf8ce320d0
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f078620ef8d - std::backtrace_rs::backtrace::trace_unsynchronized::hd715d6ee36d01457
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f078620ef8d - std::sys_common::backtrace::_print_fmt::h86f2d6902c17b72b
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f078620ef8d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2f28719fc9d49991
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f078626ac1c - core::fmt::write::h58d80b2387526c14
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/core/src/fmt/mod.rs:1196:17
   5:     0x7f0786200661 - std::io::Write::write_fmt::h51e24b646b1d9dea
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/io/mod.rs:1654:15
   6:     0x7f0786211ca5 - std::sys_common::backtrace::_print::h08306e60302c2601
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f0786211ca5 - std::sys_common::backtrace::print::h8bee5b1ce7ed0828
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f0786211ca5 - std::panicking::default_hook::{{closure}}::h0135f80d264aa3cb
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/panicking.rs:295:22
   9:     0x7f0786211919 - std::panicking::default_hook::haf57ee52e612f636
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/panicking.rs:314:9
  10:     0x7f07869d7b21 - rustc_driver[52a5108fb431eaec]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f0786212476 - std::panicking::rust_panic_with_hook::h4cd397120086e208
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/panicking.rs:702:17
  12:     0x7f0786212239 - std::panicking::begin_panic_handler::{{closure}}::hf500f2fbd8a1acc4
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/panicking.rs:586:13
  13:     0x7f078620f444 - std::sys_common::backtrace::__rust_end_short_backtrace::h67b4e62db9dc2797
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/sys_common/backtrace.rs:138:18
  14:     0x7f0786211fa9 - rust_begin_unwind
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/panicking.rs:584:5
  15:     0x7f07861d7223 - core::panicking::panic_fmt::h99ba80b725ad2949
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/core/src/panicking.rs:142:14
  16:     0x7f07861d70ed - core::panicking::panic::hfa244e9d3623fb7d
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/core/src/panicking.rs:48:5
  17:     0x7f07882bc4b8 - <rustc_borrowck[7ebf6aea16ae1e27]::region_infer::RegionInferenceContext>::solve
  18:     0x7f0788222077 - rustc_borrowck[7ebf6aea16ae1e27]::nll::compute_regions
  19:     0x7f078828da2e - rustc_borrowck[7ebf6aea16ae1e27]::do_mir_borrowck
  20:     0x7f07882866b9 - rustc_borrowck[7ebf6aea16ae1e27]::mir_borrowck
  21:     0x7f0788283420 - <rustc_borrowck[7ebf6aea16ae1e27]::provide::{closure#0} as core[696ac347caa2bd44]::ops::function::FnOnce<(rustc_middle[98c7c48ec55f2d30]::ty::context::TyCtxt, rustc_span[6ccf8f5ca5317a27]::def_id::LocalDefId)>>::call_once
  22:     0x7f07884b3d50 - rustc_query_system[202e2af03b29f868]::query::plumbing::try_execute_query::<rustc_query_impl[571ef98d1fbb149a]::plumbing::QueryCtxt, rustc_query_system[202e2af03b29f868]::query::caches::DefaultCache<rustc_span[6ccf8f5ca5317a27]::def_id::LocalDefId, &rustc_middle[98c7c48ec55f2d30]::mir::query::BorrowCheckResult>>
  23:     0x7f078847eeea - <rustc_query_impl[571ef98d1fbb149a]::Queries as rustc_middle[98c7c48ec55f2d30]::ty::query::QueryEngine>::mir_borrowck
  24:     0x7f0787fd0d80 - rustc_typeck[bf5d8a66ba319940]::collect::type_of::type_of
  25:     0x7f07884fa517 - rustc_query_system[202e2af03b29f868]::query::plumbing::get_query::<rustc_query_impl[571ef98d1fbb149a]::queries::type_of, rustc_query_impl[571ef98d1fbb149a]::plumbing::QueryCtxt>
  26:     0x7f0787fdac95 - rustc_typeck[bf5d8a66ba319940]::check::check::check_item_type
  27:     0x7f0787fe01fb - rustc_typeck[bf5d8a66ba319940]::check::check::check_mod_item_types
  28:     0x7f07884b5d70 - rustc_query_system[202e2af03b29f868]::query::plumbing::try_execute_query::<rustc_query_impl[571ef98d1fbb149a]::plumbing::QueryCtxt, rustc_query_system[202e2af03b29f868]::query::caches::DefaultCache<rustc_span[6ccf8f5ca5317a27]::def_id::LocalDefId, ()>>
  29:     0x7f0789009ae3 - rustc_query_system[202e2af03b29f868]::query::plumbing::get_query::<rustc_query_impl[571ef98d1fbb149a]::queries::check_mod_item_types, rustc_query_impl[571ef98d1fbb149a]::plumbing::QueryCtxt>
  30:     0x7f0788d2585d - <rustc_middle[98c7c48ec55f2d30]::hir::map::Map>::for_each_module::<rustc_typeck[bf5d8a66ba319940]::check_crate::{closure#6}::{closure#0}>
  31:     0x7f0788d03668 - <rustc_session[abce4e7f97e3a707]::session::Session>::time::<(), rustc_typeck[bf5d8a66ba319940]::check_crate::{closure#6}>
  32:     0x7f0788cebe68 - rustc_typeck[bf5d8a66ba319940]::check_crate
  33:     0x7f0788a85e87 - rustc_interface[f634dffaf1f1ed4]::passes::analysis
  34:     0x7f0788fd7574 - rustc_query_system[202e2af03b29f868]::query::plumbing::try_execute_query::<rustc_query_impl[571ef98d1fbb149a]::plumbing::QueryCtxt, rustc_query_system[202e2af03b29f868]::query::caches::DefaultCache<(), core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>>>
  35:     0x7f0789018c7e - rustc_query_system[202e2af03b29f868]::query::plumbing::get_query::<rustc_query_impl[571ef98d1fbb149a]::queries::analysis, rustc_query_impl[571ef98d1fbb149a]::plumbing::QueryCtxt>
  36:     0x7f0788a668e7 - <rustc_interface[f634dffaf1f1ed4]::passes::QueryContext>::enter::<rustc_driver[52a5108fb431eaec]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>>
  37:     0x7f0788a51938 - <rustc_interface[f634dffaf1f1ed4]::interface::Compiler>::enter::<rustc_driver[52a5108fb431eaec]::run_compiler::{closure#1}::{closure#2}, core[696ac347caa2bd44]::result::Result<core[696ac347caa2bd44]::option::Option<rustc_interface[f634dffaf1f1ed4]::queries::Linker>, rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>>
  38:     0x7f0788a7a02f - rustc_span[6ccf8f5ca5317a27]::with_source_map::<core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>, rustc_interface[f634dffaf1f1ed4]::interface::create_compiler_and_run<core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>, rustc_driver[52a5108fb431eaec]::run_compiler::{closure#1}>::{closure#1}>
  39:     0x7f0788a525a4 - rustc_interface[f634dffaf1f1ed4]::interface::create_compiler_and_run::<core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>, rustc_driver[52a5108fb431eaec]::run_compiler::{closure#1}>
  40:     0x7f0788a4fe42 - <scoped_tls[5bcfd69aea41704b]::ScopedKey<rustc_span[6ccf8f5ca5317a27]::SessionGlobals>>::set::<rustc_interface[f634dffaf1f1ed4]::interface::run_compiler<core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>, rustc_driver[52a5108fb431eaec]::run_compiler::{closure#1}>::{closure#0}, core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>>
  41:     0x7f0788a66f6f - std[6756e547c62c76a1]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[f634dffaf1f1ed4]::util::run_in_thread_pool_with_globals<rustc_interface[f634dffaf1f1ed4]::interface::run_compiler<core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>, rustc_driver[52a5108fb431eaec]::run_compiler::{closure#1}>::{closure#0}, core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>>::{closure#0}, core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>>
  42:     0x7f0788a670a9 - <<std[6756e547c62c76a1]::thread::Builder>::spawn_unchecked_<rustc_interface[f634dffaf1f1ed4]::util::run_in_thread_pool_with_globals<rustc_interface[f634dffaf1f1ed4]::interface::run_compiler<core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>, rustc_driver[52a5108fb431eaec]::run_compiler::{closure#1}>::{closure#0}, core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>>::{closure#0}, core[696ac347caa2bd44]::result::Result<(), rustc_errors[a3b3cd9ac4cd0404]::ErrorGuaranteed>>::{closure#1} as core[696ac347caa2bd44]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x7f078621c393 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h14e46baa6d22d347
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/alloc/src/boxed.rs:1872:9
  44:     0x7f078621c393 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6ebfb42aa2b9da7a
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/alloc/src/boxed.rs:1872:9
  45:     0x7f078621c393 - std::sys::unix::thread::Thread::new::thread_start::hff1811d6a35504cb
                               at /rustc/42e1761c704f074b7b8c7ff8a7433acfd65d2ee9/library/std/src/sys/unix/thread.rs:108:17
  46:     0x7f078614c609 - start_thread
  47:     0x7f0786065133 - clone
  48:                0x0 - <unknown>

error: internal compiler error: unexpected panic

note: 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: rustc 1.63.0-nightly (42e1761c7 2022-05-15) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [mir_borrowck] borrow-checking `blah`
#1 [type_of] computing type of `blah::{opaque#0}`
#2 [check_mod_item_types] checking item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
@aliemjay
Copy link
Member

aliemjay commented May 17, 2022

This the the error-to-ICE regresion version of #96194 (comment)

#97039 isn't intended to reject this case and there's no tracking issue of this ICE, so

@rustbot label regression-from-stable-to-beta A-impl-trait A-lifetimes T-compiler

@aliemjay
Copy link
Member

It fails to build in stable (I think it should build though..?)

Note that the error is correct here. If the inner opaque type is intended to capture 'a, it should be:

fn blah() -> impl for<'a> Trait<'a, Assoc = impl Sized + 'a> {

But then it's rejected as unsupported as per #97039.

@rustbot rustbot added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-lifetimes Area: Lifetimes / regions regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 17, 2022
@apiraino
Copy link
Contributor

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels May 18, 2022
@lasernoises
Copy link

I don't know if this is at all helpful, but I have stumbled across a slightly different way to trigger this panic that requires an extra level of impl-trait indirection to work:

trait Trait<E> {
    type Assoc;
}

struct Foo;

impl<'a> Trait<&'a ()> for Foo {
    type Assoc = ();
}

fn foo() -> impl for<'a> Trait<&'a ()> {
    Foo
}

fn bar() -> impl for<'a> Trait<&'a (), Assoc = impl Sized> {
    foo()
}

It compiles when I return Foo from bar directly.

This causes a panic both on stable and on the latest nightly (the above now seems to panic on stable as well) with the same error as above:

thread 'rustc' panicked at 'assertion failed: self.scc_universes[scc] == ty::UniverseIndex::ROOT', compiler/rustc_borrowck/src/region_infer/mod.rs:708:9

@pietroalbini pietroalbini added this to the 1.62.0 milestone Jun 24, 2022
matthiaskrgr added a commit to matthiaskrgr/glacier that referenced this issue Jun 25, 2022
matthiaskrgr added a commit to matthiaskrgr/glacier that referenced this issue Jun 25, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jun 25, 2022
@workingjubilee workingjubilee added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Jul 6, 2022
@jyn514 jyn514 added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jul 4, 2023
@bors bors closed this as completed in 03181e0 Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. A-lifetimes Area: Lifetimes / regions glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
9 participants