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 generic_const_exprs: expected bits of usize, got (Sub: 2_usize, 1_usize): usize #116637

Open
13ros27 opened this issue Oct 11, 2023 · 3 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@13ros27
Copy link

13ros27 commented Oct 11, 2023

This will compile fine in a release build, only breaking in debug. I have found it in release with a much larger piece of code but haven't been able to minimise this, I guess its some abstraction stopping it from optimising the problem away (the backtrace for that is also under the backtrace drop down).

Code

#![feature(generic_const_exprs)]

fn main() {
    test::<2>();
}

struct Test<const N: usize>;

fn new<const N: usize>() -> Test<N>
where
    [(); N * 1]: Sized,
{
    Test
}

fn test<const N: usize>() -> Test<{ N - 1 }>
where
    [(); (N - 1) * 1]: Sized,
{
    new()
}

Meta

rustc --version --verbose:

rustc 1.75.0-nightly (d627cf07c 2023-10-10)
binary: rustc
commit-hash: d627cf07ce46d230a93732a4714d16f00df9466b
commit-date: 2023-10-10
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.2

Error output

error: internal compiler error: /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/compiler/rustc_middle/src/ty/consts.rs:354:32: expected bits of usize, got (Sub: 2_usize, 1_usize): usize

thread 'rustc' panicked at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/compiler/rustc_errors/src/lib.rs:1656:9:
Box<dyn Any>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.75.0-nightly (d627cf07c 2023-10-10) running on x86_64-unknown-linux-gnu
                                                                                                                                                                                         
note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

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

query stack during panic:                                                                                                                                                                
end of query stack
Backtrace

thread 'rustc' panicked at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/compiler/rustc_errors/src/lib.rs:1656:9:
Box<dyn Any>
stack backtrace:
   0:     0x7f342c14a454 - std::backtrace_rs::backtrace::libunwind::trace::he58e745adb760569
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f342c14a454 - std::backtrace_rs::backtrace::trace_unsynchronized::h4670f523f11d085c
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f342c14a454 - std::backtrace::Backtrace::create::h1e50583854726c8c
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/std/src/backtrace.rs:331:13
   3:     0x7f342c14a390 - std::backtrace::Backtrace::force_capture::h455800a0db6f3f7b
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/std/src/backtrace.rs:313:9
   4:     0x7f342ed0eb6e - std[b26b9704b147c2d]::panicking::update_hook::<alloc[eed55dc9fbda562b]::boxed::Box<rustc_driver_impl[2651547ecd42fa48]::install_ice_hook::{closure#0}>>::{closure#0}
   5:     0x7f342c1668c8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hb2346c3bc2643035
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/alloc/src/boxed.rs:2021:9
   6:     0x7f342c1668c8 - std::panicking::rust_panic_with_hook::ha6534e6ac616d42e
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/std/src/panicking.rs:735:13
   7:     0x7f342f0c0f44 - std[b26b9704b147c2d]::panicking::begin_panic::<rustc_errors[eb3fa16f16611621]::ExplicitBug>::{closure#0}
   8:     0x7f342f0b7006 - std[b26b9704b147c2d]::sys_common::backtrace::__rust_end_short_backtrace::<std[b26b9704b147c2d]::panicking::begin_panic<rustc_errors[eb3fa16f16611621]::ExplicitBug>::{closure#0}, !>
   9:     0x7f342f0b19b6 - std[b26b9704b147c2d]::panicking::begin_panic::<rustc_errors[eb3fa16f16611621]::ExplicitBug>
  10:     0x7f342f09a674 - <rustc_errors[eb3fa16f16611621]::HandlerInner>::bug::<alloc[eed55dc9fbda562b]::string::String>
  11:     0x7f342f09a434 - <rustc_errors[eb3fa16f16611621]::Handler>::bug::<alloc[eed55dc9fbda562b]::string::String>
  12:     0x7f342f13bcfd - rustc_middle[32ae946643ac3c85]::util::bug::opt_span_bug_fmt::<rustc_span[2258fd5a24697d4]::span_encoding::Span>::{closure#0}
  13:     0x7f342f122c5a - rustc_middle[32ae946643ac3c85]::ty::context::tls::with_opt::<rustc_middle[32ae946643ac3c85]::util::bug::opt_span_bug_fmt<rustc_span[2258fd5a24697d4]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7f342f122b38 - rustc_middle[32ae946643ac3c85]::ty::context::tls::with_context_opt::<rustc_middle[32ae946643ac3c85]::ty::context::tls::with_opt<rustc_middle[32ae946643ac3c85]::util::bug::opt_span_bug_fmt<rustc_span[2258fd5a24697d4]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7f342d14d7c0 - rustc_middle[32ae946643ac3c85]::util::bug::bug_fmt
  16:     0x7f342d92fcc5 - rustc_codegen_ssa[39500a6ae9e3be9a]::debuginfo::type_names::push_generic_params
  17:     0x7f342d926e19 - <rustc_codegen_llvm[ea079d7c3475f688]::context::CodegenCx as rustc_codegen_ssa[39500a6ae9e3be9a]::traits::debuginfo::DebugInfoMethods>::dbg_scope_fn
  18:     0x7f342d8ed7bc - rustc_codegen_ssa[39500a6ae9e3be9a]::mir::codegen_mir::<rustc_codegen_llvm[ea079d7c3475f688]::builder::Builder>
  19:     0x7f342d8dcc55 - rustc_codegen_llvm[ea079d7c3475f688]::base::compile_codegen_unit::module_codegen
  20:     0x7f342d8dab8c - <rustc_codegen_llvm[ea079d7c3475f688]::LlvmCodegenBackend as rustc_codegen_ssa[39500a6ae9e3be9a]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  21:     0x7f342d8d2ff8 - <rustc_codegen_llvm[ea079d7c3475f688]::LlvmCodegenBackend as rustc_codegen_ssa[39500a6ae9e3be9a]::traits::backend::CodegenBackend>::codegen_crate
  22:     0x7f342e4f3fc5 - rustc_interface[ae17b0dc96344795]::passes::start_codegen
  23:     0x7f342e4f3616 - <rustc_interface[ae17b0dc96344795]::queries::Queries>::ongoing_codegen
  24:     0x7f342e4e2292 - std[b26b9704b147c2d]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[ae17b0dc96344795]::util::run_in_thread_with_globals<rustc_interface[ae17b0dc96344795]::interface::run_compiler<core[49a1b4ca451b5b93]::result::Result<(), rustc_span[2258fd5a24697d4]::ErrorGuaranteed>, rustc_driver_impl[2651547ecd42fa48]::run_compiler::{closure#1}>::{closure#0}, core[49a1b4ca451b5b93]::result::Result<(), rustc_span[2258fd5a24697d4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[49a1b4ca451b5b93]::result::Result<(), rustc_span[2258fd5a24697d4]::ErrorGuaranteed>>
  25:     0x7f342e4e14f3 - <<std[b26b9704b147c2d]::thread::Builder>::spawn_unchecked_<rustc_interface[ae17b0dc96344795]::util::run_in_thread_with_globals<rustc_interface[ae17b0dc96344795]::interface::run_compiler<core[49a1b4ca451b5b93]::result::Result<(), rustc_span[2258fd5a24697d4]::ErrorGuaranteed>, rustc_driver_impl[2651547ecd42fa48]::run_compiler::{closure#1}>::{closure#0}, core[49a1b4ca451b5b93]::result::Result<(), rustc_span[2258fd5a24697d4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[49a1b4ca451b5b93]::result::Result<(), rustc_span[2258fd5a24697d4]::ErrorGuaranteed>>::{closure#1} as core[49a1b4ca451b5b93]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  26:     0x7f342c171835 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1414df2002a63d1b
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/alloc/src/boxed.rs:2007:9
  27:     0x7f342c171835 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h763b81210c017496
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/alloc/src/boxed.rs:2007:9
  28:     0x7f342c171835 - std::sys::unix::thread::Thread::new::thread_start::h7411b328d0362935
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/std/src/sys/unix/thread.rs:108:17
  29:     0x7f342be94ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  30:     0x7f342bf26a40 - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  31:                0x0 - <unknown>


rustc version: 1.75.0-nightly (d627cf07c 2023-10-10)
platform: x86_64-unknown-linux-gnu

query stack during panic:
end of query stack


Backtrace for larger code on release:
thread 'rustc' panicked at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/compiler/rustc_errors/src/lib.rs:1656:9:
Box<dyn Any>
stack backtrace:
   0:     0x7fa790bbc454 - std::backtrace_rs::backtrace::libunwind::trace::he58e745adb760569
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fa790bbc454 - std::backtrace_rs::backtrace::trace_unsynchronized::h4670f523f11d085c
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fa790bbc454 - std::backtrace::Backtrace::create::h1e50583854726c8c
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/std/src/backtrace.rs:331:13
   3:     0x7fa790bbc390 - std::backtrace::Backtrace::force_capture::h455800a0db6f3f7b
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/std/src/backtrace.rs:313:9
   4:     0x7fa78fd0eb6e - std[b26b9704b147c2d]::panicking::update_hook::<alloc[eed55dc9fbda562b]::boxed::Box<rustc_driver_impl[2651547ecd42fa48]::install_ice_hook::{closure#0}>>::{closure#0}
   5:     0x7fa790bd88c8 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hb2346c3bc2643035
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/alloc/src/boxed.rs:2021:9
   6:     0x7fa790bd88c8 - std::panicking::rust_panic_with_hook::ha6534e6ac616d42e
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/std/src/panicking.rs:735:13
   7:     0x7fa7900c0f44 - std[b26b9704b147c2d]::panicking::begin_panic::<rustc_errors[eb3fa16f16611621]::ExplicitBug>::{closure#0}
   8:     0x7fa7900b7006 - std[b26b9704b147c2d]::sys_common::backtrace::__rust_end_short_backtrace::<std[b26b9704b147c2d]::panicking::begin_panic<rustc_errors[eb3fa16f16611621]::ExplicitBug>::{closure#0}, !>
   9:     0x7fa7900b19b6 - std[b26b9704b147c2d]::panicking::begin_panic::<rustc_errors[eb3fa16f16611621]::ExplicitBug>
  10:     0x7fa79009a674 - <rustc_errors[eb3fa16f16611621]::HandlerInner>::bug::<alloc[eed55dc9fbda562b]::string::String>
  11:     0x7fa79009a434 - <rustc_errors[eb3fa16f16611621]::Handler>::bug::<alloc[eed55dc9fbda562b]::string::String>
  12:     0x7fa79013bcfd - rustc_middle[32ae946643ac3c85]::util::bug::opt_span_bug_fmt::<rustc_span[2258fd5a24697d4]::span_encoding::Span>::{closure#0}
  13:     0x7fa790122c5a - rustc_middle[32ae946643ac3c85]::ty::context::tls::with_opt::<rustc_middle[32ae946643ac3c85]::util::bug::opt_span_bug_fmt<rustc_span[2258fd5a24697d4]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7fa790122b38 - rustc_middle[32ae946643ac3c85]::ty::context::tls::with_context_opt::<rustc_middle[32ae946643ac3c85]::ty::context::tls::with_opt<rustc_middle[32ae946643ac3c85]::util::bug::opt_span_bug_fmt<rustc_span[2258fd5a24697d4]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7fa78e14d7c0 - rustc_middle[32ae946643ac3c85]::util::bug::bug_fmt
  16:     0x7fa78f04327e - rustc_monomorphize[53f3c55261279dff]::collector::collect_items_rec::{closure#0}
  17:     0x7fa78f02fad4 - rustc_monomorphize[53f3c55261279dff]::collector::collect_items_rec
  18:     0x7fa78f030250 - rustc_monomorphize[53f3c55261279dff]::collector::collect_items_rec
  19:     0x7fa78f2207f4 - rustc_monomorphize[53f3c55261279dff]::partitioning::collect_and_partition_mono_items
  20:     0x7fa78f6112c6 - rustc_query_impl[aa7cda36b1573e15]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[aa7cda36b1573e15]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[32ae946643ac3c85]::query::erase::Erased<[u8; 24usize]>>
  21:     0x7fa78f611279 - <rustc_query_impl[aa7cda36b1573e15]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[49a1b4ca451b5b93]::ops::function::FnOnce<(rustc_middle[32ae946643ac3c85]::ty::context::TyCtxt, ())>>::call_once
  22:     0x7fa78f610e42 - rustc_query_system[a4e9c8652a0c2e4c]::query::plumbing::try_execute_query::<rustc_query_impl[aa7cda36b1573e15]::DynamicConfig<rustc_query_system[a4e9c8652a0c2e4c]::query::caches::SingleCache<rustc_middle[32ae946643ac3c85]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[aa7cda36b1573e15]::plumbing::QueryCtxt, false>
  23:     0x7fa78f7eac5d - rustc_query_impl[aa7cda36b1573e15]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
  24:     0x7fa78e8d2a7d - <rustc_codegen_llvm[ea079d7c3475f688]::LlvmCodegenBackend as rustc_codegen_ssa[39500a6ae9e3be9a]::traits::backend::CodegenBackend>::codegen_crate
  25:     0x7fa78f4f3fc5 - rustc_interface[ae17b0dc96344795]::passes::start_codegen
  26:     0x7fa78f4f3616 - <rustc_interface[ae17b0dc96344795]::queries::Queries>::ongoing_codegen
  27:     0x7fa78f4e2292 - std[b26b9704b147c2d]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[ae17b0dc96344795]::util::run_in_thread_with_globals<rustc_interface[ae17b0dc96344795]::interface::run_compiler<core[49a1b4ca451b5b93]::result::Result<(), rustc_span[2258fd5a24697d4]::ErrorGuaranteed>, rustc_driver_impl[2651547ecd42fa48]::run_compiler::{closure#1}>::{closure#0}, core[49a1b4ca451b5b93]::result::Result<(), rustc_span[2258fd5a24697d4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[49a1b4ca451b5b93]::result::Result<(), rustc_span[2258fd5a24697d4]::ErrorGuaranteed>>
  28:     0x7fa78f4e14f3 - <<std[b26b9704b147c2d]::thread::Builder>::spawn_unchecked_<rustc_interface[ae17b0dc96344795]::util::run_in_thread_with_globals<rustc_interface[ae17b0dc96344795]::interface::run_compiler<core[49a1b4ca451b5b93]::result::Result<(), rustc_span[2258fd5a24697d4]::ErrorGuaranteed>, rustc_driver_impl[2651547ecd42fa48]::run_compiler::{closure#1}>::{closure#0}, core[49a1b4ca451b5b93]::result::Result<(), rustc_span[2258fd5a24697d4]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[49a1b4ca451b5b93]::result::Result<(), rustc_span[2258fd5a24697d4]::ErrorGuaranteed>>::{closure#1} as core[49a1b4ca451b5b93]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  29:     0x7fa790be3835 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1414df2002a63d1b
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/alloc/src/boxed.rs:2007:9
  30:     0x7fa790be3835 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h763b81210c017496
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/alloc/src/boxed.rs:2007:9
  31:     0x7fa790be3835 - std::sys::unix::thread::Thread::new::thread_start::h7411b328d0362935
                               at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/std/src/sys/unix/thread.rs:108:17
  32:     0x7fa78ce94ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  33:     0x7fa78cf26a40 - clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  34:                0x0 - <unknown>


rustc version: 1.75.0-nightly (d627cf07c 2023-10-10)
platform: x86_64-unknown-linux-gnu

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

@13ros27 13ros27 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 Oct 11, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 11, 2023
@13ros27
Copy link
Author

13ros27 commented Oct 11, 2023

The last nightly version this compiles on is nightly-2022-11-26

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Oct 11, 2023

Interesting, this needs -Cdebuginfo=1/2 to crash.

Regression in nightly-2022-11-27
found 8 bors merge commits in the specified range
commit[0] 2022-11-25: Auto merge of #104902 - matthiaskrgr:rollup-oo27a4u, r=matthiaskrgr
commit[1] 2022-11-25: Auto merge of #99798 - JulianKnodt:ac1, r=BoxyUwU
commit[2] 2022-11-26: Auto merge of #104431 - alistair23:alistair/rv64-profiler, r=Mark-Simulacrum
commit[3] 2022-11-26: Auto merge of #104730 - petrochenkov:modchild5, r=cjgillot
commit[4] 2022-11-26: Auto merge of #103556 - clubby789:specialize-option-partial-eq, r=scottmcm
commit[5] 2022-11-26: Auto merge of #104935 - matthiaskrgr:rollup-nuca86l, r=matthiaskrgr
commit[6] 2022-11-26: Auto merge of #104731 - compiler-errors:early-binder-iter-size-hint, r=cjgillot
commit[7] 2022-11-26: Auto merge of #104945 - GuillaumeGomez:rollup-ygzbpbe, r=GuillaumeGomez
ERROR: no CI builds available between 8681d4c and 80a9646 within last 167 days

@trueb2
Copy link
Contributor

trueb2 commented Oct 11, 2023

This reminds me of #106423

@fmease fmease added A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) F-generic_const_exprs `#![feature(generic_const_exprs)]` and removed A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) labels Oct 11, 2023
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 15, 2023
@BoxyUwU BoxyUwU added the A-const-generics Area: const generics (parameters and arguments) label Oct 23, 2023
@matthiaskrgr matthiaskrgr added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 19, 2024
@workingjubilee workingjubilee added the requires-incomplete-features This issue requires the use of incomplete features. label Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-generic_const_exprs `#![feature(generic_const_exprs)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-incomplete-features This issue requires the use of incomplete features. 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

8 participants