rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.86k stars 12.67k forks source link

ICE with `generic_const_exprs`: `expected bits of usize, got (Sub: 2_usize, 1_usize): usize` #116637

Open 13ros27 opened 1 year ago

13ros27 commented 1 year ago

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 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::>::{closure#0} 5: 0x7f342c1668c8 - as core::ops::function::Fn>::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::::{closure#0} 8: 0x7f342f0b7006 - std[b26b9704b147c2d]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 9: 0x7f342f0b19b6 - std[b26b9704b147c2d]::panicking::begin_panic:: 10: 0x7f342f09a674 - ::bug:: 11: 0x7f342f09a434 - ::bug:: 12: 0x7f342f13bcfd - rustc_middle[32ae946643ac3c85]::util::bug::opt_span_bug_fmt::::{closure#0} 13: 0x7f342f122c5a - rustc_middle[32ae946643ac3c85]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 14: 0x7f342f122b38 - rustc_middle[32ae946643ac3c85]::ty::context::tls::with_context_opt::::{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 - ::dbg_scope_fn 18: 0x7f342d8ed7bc - rustc_codegen_ssa[39500a6ae9e3be9a]::mir::codegen_mir:: 19: 0x7f342d8dcc55 - rustc_codegen_llvm[ea079d7c3475f688]::base::compile_codegen_unit::module_codegen 20: 0x7f342d8dab8c - ::compile_codegen_unit 21: 0x7f342d8d2ff8 - ::codegen_crate 22: 0x7f342e4f3fc5 - rustc_interface[ae17b0dc96344795]::passes::start_codegen 23: 0x7f342e4f3616 - ::ongoing_codegen 24: 0x7f342e4e2292 - std[b26b9704b147c2d]::sys_common::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 - as core::ops::function::FnOnce>::call_once::h1414df2002a63d1b at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/alloc/src/boxed.rs:2007:9 27: 0x7f342c171835 - as core::ops::function::FnOnce>::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 - 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 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::>::{closure#0} 5: 0x7fa790bd88c8 - as core::ops::function::Fn>::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::::{closure#0} 8: 0x7fa7900b7006 - std[b26b9704b147c2d]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 9: 0x7fa7900b19b6 - std[b26b9704b147c2d]::panicking::begin_panic:: 10: 0x7fa79009a674 - ::bug:: 11: 0x7fa79009a434 - ::bug:: 12: 0x7fa79013bcfd - rustc_middle[32ae946643ac3c85]::util::bug::opt_span_bug_fmt::::{closure#0} 13: 0x7fa790122c5a - rustc_middle[32ae946643ac3c85]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 14: 0x7fa790122b38 - rustc_middle[32ae946643ac3c85]::ty::context::tls::with_context_opt::::{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::> 21: 0x7fa78f611279 - >::call_once 22: 0x7fa78f610e42 - rustc_query_system[a4e9c8652a0c2e4c]::query::plumbing::try_execute_query::>, 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 - ::codegen_crate 25: 0x7fa78f4f3fc5 - rustc_interface[ae17b0dc96344795]::passes::start_codegen 26: 0x7fa78f4f3616 - ::ongoing_codegen 27: 0x7fa78f4e2292 - std[b26b9704b147c2d]::sys_common::backtrace::__rust_begin_short_backtrace::, 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 - <::spawn_unchecked_, 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 - as core::ops::function::FnOnce>::call_once::h1414df2002a63d1b at /rustc/d627cf07ce46d230a93732a4714d16f00df9466b/library/alloc/src/boxed.rs:2007:9 30: 0x7fa790be3835 - as core::ops::function::FnOnce>::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 - 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 commented 1 year ago

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

matthiaskrgr commented 1 year ago

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 8681d4cffcd23bbe619984ab62772a91827a40dc and 80a96467ec5675e9f69683b5c075a8b15950c341 within last 167 days

trueb2 commented 1 year ago

This reminds me of https://github.com/rust-lang/rust/issues/106423