rust-lang / rust

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

Compiler crash: type parameter `D/#3` (D/#3/3) out of range when substituting (project with feature generic_const_exprs) #117460

Open panzi opened 12 months ago

panzi commented 12 months ago

When I add the default generic parameter then the error about that part goes away, but the crash remains.

Code

This is a very broken intermediate state where I try to replace a field data: Box<[T; X * Y]> with a generic field that has AsRef<[T; X * Y]>.

https://github.com/panzi/rust-matrix/commit/64fecf7b75eeea7b50f01a5779a3c08d942474cf

Meta

rustc --version --verbose:

rustc 1.75.0-nightly (31bc7e2c4 2023-10-30)
binary: rustc
commit-hash: 31bc7e2c47e82798a392c770611975a6883132c8
commit-date: 2023-10-30
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.3

Error output

error: generic parameters with a default must be trailing
  --> src/bycolumn.rs:11:57
   |
11 | pub struct IntoByColumn<const X: usize, const Y: usize, T: Number=f64, D: AsRef<[T; X * Y]>>
   |                                                         ^

error: internal compiler error: compiler/rustc_middle/src/ty/generic_args.rs:905:9: type parameter `D/#3` (D/#3/3) out of range when substituting, args=[X/#1: usize, Y/#2: usize, T/#3]
Backtrace

``` error: generic parameters with a default must be trailing --> src/bycolumn.rs:11:57 | 11 | pub struct IntoByColumn> | ^ error: internal compiler error: compiler/rustc_middle/src/ty/generic_args.rs:905:9: type parameter `D/#3` (D/#3/3) out of range when substituting, args=[X/#1: usize, Y/#2: usize, T/#3] thread 'rustc' panicked at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/compiler/rustc_errors/src/lib.rs:1661:9: Box stack backtrace: 0: 0x7f837f03acfc - std::backtrace_rs::backtrace::libunwind::trace::h974857262e179b17 at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5 1: 0x7f837f03acfc - std::backtrace_rs::backtrace::trace_unsynchronized::h6adce2053c056ac9 at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f837f03acfc - std::sys_common::backtrace::_print_fmt::hcf2018a5ad956761 at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/std/src/sys_common/backtrace.rs:67:5 3: 0x7f837f03acfc - ::fmt::h3d39e48ce4d7e36f at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f837f09cf50 - core::fmt::rt::Argument::fmt::hef0ae15422a7f61d at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/core/src/fmt/rt.rs:142:9 5: 0x7f837f09cf50 - core::fmt::write::hf465a4ba34489409 at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/core/src/fmt/mod.rs:1117:17 6: 0x7f837f02ec1f - std::io::Write::write_fmt::hf34ad5986fa99e89 at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/std/src/io/mod.rs:1763:15 7: 0x7f837f03aae4 - std::sys_common::backtrace::_print::h5aa7f1d99916c125 at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7f837f03aae4 - std::sys_common::backtrace::print::h036d85b5c81889eb at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7f837f03d777 - std::panicking::default_hook::{{closure}}::h9b311bcc8d2b2a40 10: 0x7f837f03d4df - std::panicking::default_hook::hd7a03fd029ce4ee2 at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/std/src/panicking.rs:292:9 11: 0x7f8381bb16a0 - std[d7fc13cc5242579e]::panicking::update_hook::>::{closure#0} 12: 0x7f837f03deb8 - as core::ops::function::Fn>::call::h079168172b9ee18d at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/alloc/src/boxed.rs:2021:9 13: 0x7f837f03deb8 - std::panicking::rust_panic_with_hook::h9ec5267af19ebd61 at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/std/src/panicking.rs:783:13 14: 0x7f8381f79614 - std[d7fc13cc5242579e]::panicking::begin_panic::::{closure#0} 15: 0x7f8381f70df6 - std[d7fc13cc5242579e]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7f8381f6b936 - std[d7fc13cc5242579e]::panicking::begin_panic:: 17: 0x7f8381f53154 - ::bug:: 18: 0x7f8381f52f14 - ::bug:: 19: 0x7f8381ff322d - rustc_middle[604fc891fd74f2d8]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x7f8381fdb68a - rustc_middle[604fc891fd74f2d8]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x7f8381fdb508 - rustc_middle[604fc891fd74f2d8]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x7f838009ae30 - rustc_middle[604fc891fd74f2d8]::util::bug::bug_fmt 23: 0x7f8381fe9a06 - ::type_param_out_of_range 24: 0x7f8382cd8bdd - >::fold_ty 25: 0x7f8382d7b858 - <&rustc_middle[604fc891fd74f2d8]::ty::list::List as rustc_type_ir[d22dfb366bb74f41]::fold::TypeFoldable>::try_fold_with:: 26: 0x7f8382d7c5d6 - >::fold_const 27: 0x7f8382cd7820 - >::fold_ty 28: 0x7f8382cd3a48 - >::fold_ty 29: 0x7f838310197e - <::create_args_for_ast_path::{closure#0}::SubstsForAstPathCtxt as rustc_hir_analysis[7dbe6ed907447fd9]::astconv::CreateSubstsForGenericArgsCtxt>::inferred_kind 30: 0x7f8380893313 - ::res_to_ty 31: 0x7f8382e04e5b - ::ast_ty_to_ty_inner 32: 0x7f8382e05399 - ::ast_ty_to_ty_inner 33: 0x7f83802e624b - rustc_hir_analysis[7dbe6ed907447fd9]::collect::type_of::type_of 34: 0x7f8382d30b69 - rustc_query_impl[688c8a72794c2a04]::plumbing::__rust_begin_short_backtrace::> 35: 0x7f8382eeff29 - rustc_query_system[92afb14951a5a4cf]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[688c8a72794c2a04]::plumbing::QueryCtxt, true> 36: 0x7f8382efece9 - rustc_query_impl[688c8a72794c2a04]::query_impl::type_of::get_query_incr::__rust_end_short_backtrace 37: 0x7f8382dddcf7 - rustc_middle[604fc891fd74f2d8]::query::plumbing::query_get_at::>> 38: 0x7f83838ddaa3 - rustc_hir_analysis[7dbe6ed907447fd9]::outlives::inferred_outlives_crate 39: 0x7f83837da221 - rustc_query_impl[688c8a72794c2a04]::plumbing::__rust_begin_short_backtrace::> 40: 0x7f8383bc1ef2 - rustc_query_system[92afb14951a5a4cf]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[688c8a72794c2a04]::plumbing::QueryCtxt, true> 41: 0x7f8383cf35cc - rustc_query_impl[688c8a72794c2a04]::query_impl::inferred_outlives_crate::get_query_incr::__rust_end_short_backtrace 42: 0x7f8382e3f0ca - rustc_hir_analysis[7dbe6ed907447fd9]::outlives::inferred_outlives_of 43: 0x7f8382e3e18c - rustc_query_impl[688c8a72794c2a04]::plumbing::__rust_begin_short_backtrace::> 44: 0x7f838312ed5d - rustc_query_system[92afb14951a5a4cf]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[688c8a72794c2a04]::plumbing::QueryCtxt, true> 45: 0x7f838312d518 - rustc_query_impl[688c8a72794c2a04]::query_impl::inferred_outlives_of::get_query_incr::__rust_end_short_backtrace 46: 0x7f8382f9f19c - rustc_hir_analysis[7dbe6ed907447fd9]::collect::predicates_defined_on 47: 0x7f8382f9efd3 - rustc_query_impl[688c8a72794c2a04]::plumbing::__rust_begin_short_backtrace::> 48: 0x7f8383258041 - rustc_query_system[92afb14951a5a4cf]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[688c8a72794c2a04]::plumbing::QueryCtxt, true> 49: 0x7f8383256b95 - rustc_query_impl[688c8a72794c2a04]::query_impl::predicates_defined_on::get_query_incr::__rust_end_short_backtrace 50: 0x7f8382f9d629 - rustc_hir_analysis[7dbe6ed907447fd9]::collect::predicates_of::predicates_of 51: 0x7f8382f9d513 - rustc_query_impl[688c8a72794c2a04]::plumbing::__rust_begin_short_backtrace::> 52: 0x7f8383258003 - rustc_query_system[92afb14951a5a4cf]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[688c8a72794c2a04]::plumbing::QueryCtxt, true> 53: 0x7f8382efe1b6 - rustc_query_impl[688c8a72794c2a04]::query_impl::predicates_of::get_query_incr::__rust_end_short_backtrace 54: 0x7f838314c3f4 - ::visit_item 55: 0x7f838314aea8 - rustc_hir_analysis[7dbe6ed907447fd9]::collect::collect_mod_item_types 56: 0x7f838314ae3d - rustc_query_impl[688c8a72794c2a04]::plumbing::__rust_begin_short_backtrace::> 57: 0x7f83834ed629 - rustc_query_system[92afb14951a5a4cf]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[688c8a72794c2a04]::plumbing::QueryCtxt, true> 58: 0x7f8383198640 - rustc_query_impl[688c8a72794c2a04]::query_impl::collect_mod_item_types::get_query_incr::__rust_end_short_backtrace 59: 0x7f83831988e6 - rustc_hir_analysis[7dbe6ed907447fd9]::check_crate 60: 0x7f83834db516 - rustc_interface[90d65b0f51490bf6]::passes::analysis 61: 0x7f83834daf35 - rustc_query_impl[688c8a72794c2a04]::plumbing::__rust_begin_short_backtrace::> 62: 0x7f83837c3844 - rustc_query_system[92afb14951a5a4cf]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[688c8a72794c2a04]::plumbing::QueryCtxt, true> 63: 0x7f83837c3520 - rustc_query_impl[688c8a72794c2a04]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace 64: 0x7f8383a14643 - std[d7fc13cc5242579e]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[88c66c37425cba72]::run_compiler::{closure#1}>::{closure#0}, core[53bdee0566a68c19]::result::Result<(), rustc_span[88faddf4715d2d43]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[53bdee0566a68c19]::result::Result<(), rustc_span[88faddf4715d2d43]::ErrorGuaranteed>> 65: 0x7f8383a13909 - <::spawn_unchecked_, rustc_driver_impl[88c66c37425cba72]::run_compiler::{closure#1}>::{closure#0}, core[53bdee0566a68c19]::result::Result<(), rustc_span[88faddf4715d2d43]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[53bdee0566a68c19]::result::Result<(), rustc_span[88faddf4715d2d43]::ErrorGuaranteed>>::{closure#1} as core[53bdee0566a68c19]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 66: 0x7f837f048c85 - as core::ops::function::FnOnce>::call_once::he310d06a8f297797 at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/alloc/src/boxed.rs:2007:9 67: 0x7f837f048c85 - as core::ops::function::FnOnce>::call_once::h69350f715ad37c20 at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/alloc/src/boxed.rs:2007:9 68: 0x7f837f048c85 - std::sys::unix::thread::Thread::new::thread_start::h7310dea1d780d6a0 at /rustc/31bc7e2c47e82798a392c770611975a6883132c8/library/std/src/sys/unix/thread.rs:108:17 69: 0x7f837eefd3f9 - start_thread 70: 0x7f837ee284c3 - clone 71: 0x0 - 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: please attach the file at `/home/panzi/src/rust/matrix/rustc-ice-2023-10-31T19_27_35-16286.txt` to your bug report note: compiler flags: --crate-type lib -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: #0 [type_of] computing type of `bycolumn::ByColumn::matrix` #1 [inferred_outlives_crate] computing the inferred outlives predicates for items in this crate #2 [inferred_outlives_of] computing inferred outlives predicates of `vector::Vector` #3 [predicates_defined_on] computing predicates of `vector::Vector` #4 [predicates_of] computing predicates of `vector::Vector` #5 [collect_mod_item_types] collecting item types in module `vector` #6 [analysis] running analysis passes on this crate end of query stack error: could not compile `matrix` (lib) due to previous error ```

panzi commented 12 months ago

The file it said to attach: rustc-ice-2023-10-31T19_27_35-16286.txt

panzi commented 11 months ago

Made a minimal example for this compiler crash in this repository: https://github.com/panzi/rust-compiler-crash
It includes 6 functions that crash the compiler (I think in the same way) and the output of the crashes (stdout of cargo and the written rust-ice file). Hope that helps.

cyrgani commented 1 month ago

Reduced (from crash1):

#![feature(generic_const_exprs)]

struct Matrix<D = [(); 2 + 2]> {
    d: D,
}

impl Matrix {}