Repository: rust
Issue: ICE with `generic_const_exprs`: `expected bits of usize, got (Sub: 2_usize, 1_usize): usize`
Labels: I-ICE,E-needs-test,T-compiler,C-bug,A-const-generics,F-generic_const_exprs,requires-incomplete-features

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

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

```Rust
#![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
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`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
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
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
```

</p>
</details>