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 associated_const_equality: const parameter types cannot be generic #113198

Closed
fmease opened this issue Jun 30, 2023 · 2 comments
Closed
Labels
C-bug Category: This is a bug. F-associated_const_equality `#![feature(associated_const_equality)]` 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

@fmease
Copy link
Member

fmease commented Jun 30, 2023

While working on generic consts and testing their interaction with associated const equality, I stumbled across this preexisting compiler panic. Reproducer:

#![feature(associated_const_equality)]

fn user() -> impl Owner<i32, C = 0> {}

trait Owner<K> { const C: K; }
impl<K: ConstDefault> Owner<K> for () { const C: K = K::DEFAULT; }

trait ConstDefault { const DEFAULT: Self; }
impl ConstDefault for i32 { const DEFAULT: Self = 0; }

fn main() {}

Stderr:

thread 'rustc' panicked at 'const parameter types cannot be generic', compiler/rustc_hir_analysis/src/collect/type_of.rs:79:22

Although I'm not that familiar with the implementation details of associated const equality (sth. sth. assoc const projections), I'd very much like to have a go at fixing this bug since I'm already working in this area at the moment and I'd like to see it fixed before I open the generic consts PR.
@rustbot claim

Backtrace
stack backtrace:
   0:     0x7ff103367e31 - std::backtrace_rs::backtrace::libunwind::trace::h5d192c9c54b15f60
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7ff103367e31 - std::backtrace_rs::backtrace::trace_unsynchronized::hc7d3204e467fac03
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ff103367e31 - std::sys_common::backtrace::_print_fmt::h2af83df47bc668bf
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7ff103367e31 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf5a4fac06076e902
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ff1033c95df - core::fmt::rt::Argument::fmt::h1f69f816cde54b71
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/core/src/fmt/rt.rs:138:9
   5:     0x7ff1033c95df - core::fmt::write::h555ebd423ad27fc9
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/core/src/fmt/mod.rs:1094:21
   6:     0x7ff10335a967 - std::io::Write::write_fmt::ha768284cce22c0d1
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/io/mod.rs:1714:15
   7:     0x7ff103367c45 - std::sys_common::backtrace::_print::hd74993f4555d3caf
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7ff103367c45 - std::sys_common::backtrace::print::h55223f11226300d1
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7ff10336a9f3 - std::panicking::default_hook::{{closure}}::h434fb03b0a8c72cd
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/panicking.rs:269:22
  10:     0x7ff10336a784 - std::panicking::default_hook::h26d4937b6653693a
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/panicking.rs:288:9
  11:     0x7ff106601f4b - rustc_driver_impl[374d8943f7df2d38]::install_ice_hook::{closure#0}
  12:     0x7ff10336b21e - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h3bf5cd9997a69c0a
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/alloc/src/boxed.rs:2007:9
  13:     0x7ff10336b21e - std::panicking::rust_panic_with_hook::hb4f1f210fa9d7d78
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/panicking.rs:709:13
  14:     0x7ff10336afa7 - std::panicking::begin_panic_handler::{{closure}}::hf85afca6633673cc
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/panicking.rs:597:13
  15:     0x7ff103368266 - std::sys_common::backtrace::__rust_end_short_backtrace::hac73181de0e5c7e1
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/sys_common/backtrace.rs:151:18
  16:     0x7ff10336acf2 - rust_begin_unwind
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/panicking.rs:593:5
  17:     0x7ff1033c5833 - core::panicking::panic_fmt::hc9e695bf13427368
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/core/src/panicking.rs:67:14
  18:     0x7ff1033c5593 - core::panicking::panic_display::h39d8ed8855fb9673
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/core/src/panicking.rs:150:5
  19:     0x7ff1033c5593 - core::panicking::panic_str::h51f44eeb1d108324
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/core/src/panicking.rs:134:5
  20:     0x7ff1033c5593 - core::option::expect_failed::h4e46f6e39b5295d7
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/core/src/option.rs:1952:5
  21:     0x7ff10574276a - rustc_hir_analysis[12ff737570cd8dab]::collect::type_of::type_of
  22:     0x7ff1047603c3 - rustc_query_impl[6d34ccc9082d3cbf]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6d34ccc9082d3cbf]::query_impl::type_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7578aedf3d8ae35a]::query::erase::Erased<[u8; 8usize]>>
  23:     0x7ff104760380 - <rustc_query_impl[6d34ccc9082d3cbf]::query_impl::type_of::dynamic_query::{closure#2} as core[6907b49ead676d89]::ops::function::FnOnce<(rustc_middle[7578aedf3d8ae35a]::ty::context::TyCtxt, rustc_span[59b12f7e70a4d344]::def_id::DefId)>>::call_once
  24:     0x7ff104653075 - rustc_query_system[8ef922b68c9e8ac6]::query::plumbing::try_execute_query::<rustc_query_impl[6d34ccc9082d3cbf]::DynamicConfig<rustc_query_system[8ef922b68c9e8ac6]::query::caches::DefaultCache<rustc_span[59b12f7e70a4d344]::def_id::DefId, rustc_middle[7578aedf3d8ae35a]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6d34ccc9082d3cbf]::plumbing::QueryCtxt, false>
  25:     0x7ff105f89963 - rustc_query_impl[6d34ccc9082d3cbf]::query_impl::type_of::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7ff10546a504 - rustc_middle[7578aedf3d8ae35a]::query::plumbing::query_get_at::<rustc_query_system[8ef922b68c9e8ac6]::query::caches::DefaultCache<rustc_span[59b12f7e70a4d344]::def_id::DefId, rustc_middle[7578aedf3d8ae35a]::query::erase::Erased<[u8; 8usize]>>>
  27:     0x7ff1054699ab - <rustc_middle[7578aedf3d8ae35a]::ty::consts::Const>::from_anon_const
  28:     0x7ff10596ba49 - <dyn rustc_hir_analysis[12ff737570cd8dab]::astconv::AstConv>::instantiate_poly_trait_ref_inner
  29:     0x7ff105966425 - <dyn rustc_hir_analysis[12ff737570cd8dab]::astconv::AstConv>::instantiate_poly_trait_ref
  30:     0x7ff105965f30 - <dyn rustc_hir_analysis[12ff737570cd8dab]::astconv::AstConv>::add_bounds::<core[6907b49ead676d89]::slice::iter::Iter<rustc_hir[75c69f6f15d5d6ca]::hir::GenericBound>>
  31:     0x7ff1057b1ac8 - rustc_hir_analysis[12ff737570cd8dab]::collect::item_bounds::opaque_type_bounds
  32:     0x7ff1057b05f2 - rustc_hir_analysis[12ff737570cd8dab]::collect::item_bounds::explicit_item_bounds
  33:     0x7ff1059c6c81 - rustc_query_impl[6d34ccc9082d3cbf]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6d34ccc9082d3cbf]::query_impl::explicit_item_bounds::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7578aedf3d8ae35a]::query::erase::Erased<[u8; 16usize]>>
  34:     0x7ff1059c6c55 - <rustc_query_impl[6d34ccc9082d3cbf]::query_impl::explicit_item_bounds::dynamic_query::{closure#2} as core[6907b49ead676d89]::ops::function::FnOnce<(rustc_middle[7578aedf3d8ae35a]::ty::context::TyCtxt, rustc_span[59b12f7e70a4d344]::def_id::DefId)>>::call_once
  35:     0x7ff1046baded - rustc_query_system[8ef922b68c9e8ac6]::query::plumbing::try_execute_query::<rustc_query_impl[6d34ccc9082d3cbf]::DynamicConfig<rustc_query_system[8ef922b68c9e8ac6]::query::caches::DefaultCache<rustc_span[59b12f7e70a4d344]::def_id::DefId, rustc_middle[7578aedf3d8ae35a]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[6d34ccc9082d3cbf]::plumbing::QueryCtxt, false>
  36:     0x7ff105f952a8 - rustc_query_impl[6d34ccc9082d3cbf]::query_impl::explicit_item_bounds::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7ff104f4a5a5 - <rustc_hir_analysis[12ff737570cd8dab]::collect::CollectItemTypesVisitor as rustc_hir[75c69f6f15d5d6ca]::intravisit::Visitor>::visit_item
  38:     0x7ff104f45f33 - rustc_hir_analysis[12ff737570cd8dab]::collect::collect_mod_item_types
  39:     0x7ff1052be61c - rustc_query_impl[6d34ccc9082d3cbf]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6d34ccc9082d3cbf]::query_impl::collect_mod_item_types::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7578aedf3d8ae35a]::query::erase::Erased<[u8; 0usize]>>
  40:     0x7ff1052be5fe - <rustc_query_impl[6d34ccc9082d3cbf]::query_impl::collect_mod_item_types::dynamic_query::{closure#2} as core[6907b49ead676d89]::ops::function::FnOnce<(rustc_middle[7578aedf3d8ae35a]::ty::context::TyCtxt, rustc_span[59b12f7e70a4d344]::def_id::LocalDefId)>>::call_once
  41:     0x7ff104d1498f - rustc_query_system[8ef922b68c9e8ac6]::query::plumbing::try_execute_query::<rustc_query_impl[6d34ccc9082d3cbf]::DynamicConfig<rustc_query_system[8ef922b68c9e8ac6]::query::caches::VecCache<rustc_span[59b12f7e70a4d344]::def_id::LocalDefId, rustc_middle[7578aedf3d8ae35a]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[6d34ccc9082d3cbf]::plumbing::QueryCtxt, false>
  42:     0x7ff105fab3a4 - rustc_query_impl[6d34ccc9082d3cbf]::query_impl::collect_mod_item_types::get_query_non_incr::__rust_end_short_backtrace
  43:     0x7ff105aaf117 - <rustc_middle[7578aedf3d8ae35a]::hir::map::Map>::for_each_module::<rustc_hir_analysis[12ff737570cd8dab]::check_crate::{closure#0}::{closure#0}::{closure#0}>
  44:     0x7ff105aaecf2 - <rustc_session[6ee1fe53d65fb5ae]::session::Session>::track_errors::<rustc_hir_analysis[12ff737570cd8dab]::check_crate::{closure#0}, ()>
  45:     0x7ff105aad501 - rustc_hir_analysis[12ff737570cd8dab]::check_crate
  46:     0x7ff105aa613a - rustc_interface[25e9143dc71174ae]::passes::analysis
  47:     0x7ff105aedf3a - rustc_query_impl[6d34ccc9082d3cbf]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6d34ccc9082d3cbf]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[7578aedf3d8ae35a]::query::erase::Erased<[u8; 1usize]>>
  48:     0x7ff105aedf29 - <rustc_query_impl[6d34ccc9082d3cbf]::query_impl::analysis::dynamic_query::{closure#2} as core[6907b49ead676d89]::ops::function::FnOnce<(rustc_middle[7578aedf3d8ae35a]::ty::context::TyCtxt, ())>>::call_once
  49:     0x7ff105c7bfa8 - rustc_query_system[8ef922b68c9e8ac6]::query::plumbing::try_execute_query::<rustc_query_impl[6d34ccc9082d3cbf]::DynamicConfig<rustc_query_system[8ef922b68c9e8ac6]::query::caches::SingleCache<rustc_middle[7578aedf3d8ae35a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[6d34ccc9082d3cbf]::plumbing::QueryCtxt, false>
  50:     0x7ff105c7bd79 - rustc_query_impl[6d34ccc9082d3cbf]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  51:     0x7ff105c34465 - <rustc_middle[7578aedf3d8ae35a]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[374d8943f7df2d38]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[6907b49ead676d89]::result::Result<(), rustc_span[59b12f7e70a4d344]::ErrorGuaranteed>>
  52:     0x7ff1057b7c9b - <rustc_interface[25e9143dc71174ae]::interface::Compiler>::enter::<rustc_driver_impl[374d8943f7df2d38]::run_compiler::{closure#1}::{closure#2}, core[6907b49ead676d89]::result::Result<core[6907b49ead676d89]::option::Option<rustc_interface[25e9143dc71174ae]::queries::Linker>, rustc_span[59b12f7e70a4d344]::ErrorGuaranteed>>
  53:     0x7ff1057b3ae9 - rustc_span[59b12f7e70a4d344]::set_source_map::<core[6907b49ead676d89]::result::Result<(), rustc_span[59b12f7e70a4d344]::ErrorGuaranteed>, rustc_interface[25e9143dc71174ae]::interface::run_compiler<core[6907b49ead676d89]::result::Result<(), rustc_span[59b12f7e70a4d344]::ErrorGuaranteed>, rustc_driver_impl[374d8943f7df2d38]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  54:     0x7ff1057b3615 - <scoped_tls[6d925012d1f68df7]::ScopedKey<rustc_span[59b12f7e70a4d344]::SessionGlobals>>::set::<rustc_interface[25e9143dc71174ae]::interface::run_compiler<core[6907b49ead676d89]::result::Result<(), rustc_span[59b12f7e70a4d344]::ErrorGuaranteed>, rustc_driver_impl[374d8943f7df2d38]::run_compiler::{closure#1}>::{closure#0}, core[6907b49ead676d89]::result::Result<(), rustc_span[59b12f7e70a4d344]::ErrorGuaranteed>>
  55:     0x7ff1057b2c36 - std[dcf3549276dd02fc]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[25e9143dc71174ae]::util::run_in_thread_pool_with_globals<rustc_interface[25e9143dc71174ae]::interface::run_compiler<core[6907b49ead676d89]::result::Result<(), rustc_span[59b12f7e70a4d344]::ErrorGuaranteed>, rustc_driver_impl[374d8943f7df2d38]::run_compiler::{closure#1}>::{closure#0}, core[6907b49ead676d89]::result::Result<(), rustc_span[59b12f7e70a4d344]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6907b49ead676d89]::result::Result<(), rustc_span[59b12f7e70a4d344]::ErrorGuaranteed>>
  56:     0x7ff105e7aff5 - <<std[dcf3549276dd02fc]::thread::Builder>::spawn_unchecked_<rustc_interface[25e9143dc71174ae]::util::run_in_thread_pool_with_globals<rustc_interface[25e9143dc71174ae]::interface::run_compiler<core[6907b49ead676d89]::result::Result<(), rustc_span[59b12f7e70a4d344]::ErrorGuaranteed>, rustc_driver_impl[374d8943f7df2d38]::run_compiler::{closure#1}>::{closure#0}, core[6907b49ead676d89]::result::Result<(), rustc_span[59b12f7e70a4d344]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[6907b49ead676d89]::result::Result<(), rustc_span[59b12f7e70a4d344]::ErrorGuaranteed>>::{closure#1} as core[6907b49ead676d89]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  57:     0x7ff103375695 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7bd6d94c21941047
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/alloc/src/boxed.rs:1993:9
  58:     0x7ff103375695 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h16cbf2f6802b7a97
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/alloc/src/boxed.rs:1993:9
  59:     0x7ff103375695 - std::sys::unix::thread::Thread::new::thread_start::h654b71fdae4d62c8
                               at /rustc/f7ca9df69549470541fbf542f87a03eb9ed024b6/library/std/src/sys/unix/thread.rs:108:17
  60:     0x7ff1030e6bb5 - <unknown>
  61:     0x7ff103168d90 - <unknown>
  62:                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: rustc 1.72.0-nightly (f7ca9df69 2023-06-24) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [type_of] computing type of `user::{constant#0}`
#1 [explicit_item_bounds] finding item bounds for `user::{opaque#0}`
#2 [collect_mod_item_types] collecting item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack

@rustbot label C-bug T-compiler I-ICE F-associated_const_equality

@rustbot rustbot added C-bug Category: This is a bug. F-associated_const_equality `#![feature(associated_const_equality)]` 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 Jun 30, 2023
@fmease
Copy link
Member Author

fmease commented Jun 30, 2023

Oops, duplicate of #108271. Somehow that didn't show up in search earlier 😅

@fmease fmease closed this as not planned Won't fix, can't repro, duplicate, stale Jun 30, 2023
@fmease
Copy link
Member Author

fmease commented Jun 30, 2023

@rustbot release-assignment

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-associated_const_equality `#![feature(associated_const_equality)]` 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

No branches or pull requests

2 participants