rust-lang / rust

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

ICE: `unexpected const !2: usize` #121052

Open matthiaskrgr opened 7 months ago

matthiaskrgr commented 7 months ago

snippet:

#![feature(generic_const_exprs, with_negative_coherence)]

use std::ops::Mul;

pub trait Indices<const N: usize> {
    const NUM_ELEMS: usize;
}

impl<I: Indices<N>, J: Indices<N>, const N: usize> Mul for Tensor<I, N>
where
    I: Concat<J>,
    <I as Concat<J>>::Output: Indices<N>,
    [u8; I::NUM_ELEMS]: Sized,
    [u8; J::NUM_ELEMS]: Sized,
    [u8; <I as Concat<J>>::Output::NUM_ELEMS]: Sized,
{
}

pub trait Concat<J> {}

pub struct Tensor<I: Indices<N>, const N: usize> {}

impl<I: Indices<N>, J: Indices<N>, const N: usize> Mul for Tensor<I, N>
where
    I: Concat<J>,
    <I as Concat<J>>::Output: Indices<N>,
    [u8; I::NUM_ELEMS]: Sized,
    [u8; J::NUM_ELEMS]: Sized,
    [u8; <I as Concat<J>>::Output::NUM_ELEMS]: Sized,
{
}

Version information

rustc 1.78.0-nightly (a84bb95a1 2024-02-13)
binary: rustc
commit-hash: a84bb95a1f65bfe25038f188763a18e096a86ab2
commit-date: 2024-02-13
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

Command: /home/matthias/.rustup/toolchains/master/bin/rustc

Program output

``` error[E0576]: cannot find associated type `Output` in trait `Concat` --> /tmp/icemaker_global_tempdir.JmhHu65RE3t8/rustc_testrunner_tmpdir_reporting.SAuTnLQ72a4e/mvce.rs:12:23 | 12 | >::Output: Indices, | ^^^^^^ not found in `Concat` error[E0576]: cannot find associated type `Output` in trait `Concat` --> /tmp/icemaker_global_tempdir.JmhHu65RE3t8/rustc_testrunner_tmpdir_reporting.SAuTnLQ72a4e/mvce.rs:15:28 | 15 | [u8; >::Output::NUM_ELEMS]: Sized, | ^^^^^^ not found in `Concat` error[E0576]: cannot find associated type `Output` in trait `Concat` --> /tmp/icemaker_global_tempdir.JmhHu65RE3t8/rustc_testrunner_tmpdir_reporting.SAuTnLQ72a4e/mvce.rs:26:23 | 26 | >::Output: Indices, | ^^^^^^ not found in `Concat` error[E0576]: cannot find associated type `Output` in trait `Concat` --> /tmp/icemaker_global_tempdir.JmhHu65RE3t8/rustc_testrunner_tmpdir_reporting.SAuTnLQ72a4e/mvce.rs:29:28 | 29 | [u8; >::Output::NUM_ELEMS]: Sized, | ^^^^^^ not found in `Concat` warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes --> /tmp/icemaker_global_tempdir.JmhHu65RE3t8/rustc_testrunner_tmpdir_reporting.SAuTnLQ72a4e/mvce.rs:1:12 | 1 | #![feature(generic_const_exprs, with_negative_coherence)] | ^^^^^^^^^^^^^^^^^^^ | = note: see issue #76560 for more information = note: `#[warn(incomplete_features)]` on by default error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.JmhHu65RE3t8/rustc_testrunner_tmpdir_reporting.SAuTnLQ72a4e/mvce.rs:31:2 | 31 | } | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.JmhHu65RE3t8/rustc_testrunner_tmpdir_reporting.SAuTnLQ72a4e/mvce.rs` error[E0207]: the type parameter `J` is not constrained by the impl trait, self type, or predicates --> /tmp/icemaker_global_tempdir.JmhHu65RE3t8/rustc_testrunner_tmpdir_reporting.SAuTnLQ72a4e/mvce.rs:9:21 | 9 | impl, J: Indices, const N: usize> Mul for Tensor | ^ unconstrained type parameter error[E0207]: the type parameter `J` is not constrained by the impl trait, self type, or predicates --> /tmp/icemaker_global_tempdir.JmhHu65RE3t8/rustc_testrunner_tmpdir_reporting.SAuTnLQ72a4e/mvce.rs:23:21 | 23 | impl, J: Indices, const N: usize> Mul for Tensor | ^ unconstrained type parameter error: internal compiler error: compiler/rustc_infer/src/infer/freshen.rs:176:17: unexpected const !2: usize thread 'rustc' panicked at compiler/rustc_middle/src/util/bug.rs:35:44: Box stack backtrace: 0: 0x7f8228f8d086 - std::backtrace_rs::backtrace::libunwind::trace::h350c9bbd0d629e5a at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5 1: 0x7f8228f8d086 - std::backtrace_rs::backtrace::trace_unsynchronized::hb5ce80cf0732c5cf at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f8228f8d086 - std::sys_common::backtrace::_print_fmt::he116d0f55fe00810 at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/std/src/sys_common/backtrace.rs:68:5 3: 0x7f8228f8d086 - ::fmt::h71fa05f97c99f332 at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f8228fdd51c - core::fmt::rt::Argument::fmt::hfafe0bdb999ad9e2 at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/core/src/fmt/rt.rs:142:9 5: 0x7f8228fdd51c - core::fmt::write::h6115470fc2d68b0c at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/core/src/fmt/mod.rs:1120:17 6: 0x7f8228f80abf - std::io::Write::write_fmt::hdc66f4e88b29f74f at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/std/src/io/mod.rs:1854:15 7: 0x7f8228f8ce34 - std::sys_common::backtrace::_print::hcb29a46764838669 at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7f8228f8ce34 - std::sys_common::backtrace::print::h05e4e1c5c9b1d560 at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7f8228f8fb7b - std::panicking::default_hook::{{closure}}::h8d5ead34896ab42d 10: 0x7f8228f8f8c9 - std::panicking::default_hook::h78047fe2f192a868 at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/std/src/panicking.rs:292:9 11: 0x7f822bd463bc - std[466eff1cc2ed908f]::panicking::update_hook::>::{closure#0} 12: 0x7f8228f902e0 - as core::ops::function::Fn>::call::hcfe839bef410f29b at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/alloc/src/boxed.rs:2030:9 13: 0x7f8228f902e0 - std::panicking::rust_panic_with_hook::h1e5f7f410afd2444 at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/std/src/panicking.rs:785:13 14: 0x7f822bd73d24 - std[466eff1cc2ed908f]::panicking::begin_panic::::{closure#0} 15: 0x7f822bd70c36 - std[466eff1cc2ed908f]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7f822bd70636 - std[466eff1cc2ed908f]::panicking::begin_panic:: 17: 0x7f822bd7f671 - ::emit_producing_guarantee 18: 0x7f822c138b6e - ::bug:: 19: 0x7f822c1d265b - rustc_middle[80ff7a15503a7fbe]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x7f822c1b9ffa - rustc_middle[80ff7a15503a7fbe]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x7f822c1b9e98 - rustc_middle[80ff7a15503a7fbe]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x7f822a6a9470 - rustc_middle[80ff7a15503a7fbe]::util::bug::bug_fmt 23: 0x7f822d3dd2af - >::fold_const 24: 0x7f822a693797 - ::poly_select 25: 0x7f822d29381f - rustc_traits[ab147ed71eb77be]::codegen::codegen_select_candidate 26: 0x7f822d2932ef - rustc_query_impl[56a5a1cad20ac6aa]::plumbing::__rust_begin_short_backtrace::> 27: 0x7f822d292824 - rustc_query_system[790ca29724b87fee]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[56a5a1cad20ac6aa]::plumbing::QueryCtxt, false> 28: 0x7f822d2924dd - rustc_query_impl[56a5a1cad20ac6aa]::query_impl::codegen_select_candidate::get_query_non_incr::__rust_end_short_backtrace 29: 0x7f822aa2daf7 - rustc_ty_utils[1f3d0eb1fe395dcd]::instance::resolve_instance 30: 0x7f822d24acc5 - rustc_query_impl[56a5a1cad20ac6aa]::plumbing::__rust_begin_short_backtrace::> 31: 0x7f822d24b004 - rustc_query_system[790ca29724b87fee]::query::plumbing::try_execute_query::)>, rustc_middle[80ff7a15503a7fbe]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[56a5a1cad20ac6aa]::plumbing::QueryCtxt, false> 32: 0x7f822d24ac5d - rustc_query_impl[56a5a1cad20ac6aa]::query_impl::resolve_instance::get_query_non_incr::__rust_end_short_backtrace 33: 0x7f822b223c71 - ::const_eval_resolve 34: 0x7f822de55553 - rustc_const_eval[b73c79410a5da8b8]::const_eval::eval_queries::eval_body_using_ecx::{closure#0} 35: 0x7f822de52870 - rustc_const_eval[b73c79410a5da8b8]::const_eval::eval_queries::eval_in_interpreter 36: 0x7f822d55771a - rustc_const_eval[b73c79410a5da8b8]::const_eval::eval_queries::eval_to_allocation_raw_provider 37: 0x7f822d557576 - rustc_query_impl[56a5a1cad20ac6aa]::plumbing::__rust_begin_short_backtrace::> 38: 0x7f822d8b2451 - rustc_query_system[790ca29724b87fee]::query::plumbing::try_execute_query::, rustc_middle[80ff7a15503a7fbe]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[56a5a1cad20ac6aa]::plumbing::QueryCtxt, false> 39: 0x7f822d8b202c - rustc_query_impl[56a5a1cad20ac6aa]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace 40: 0x7f822dd1e114 - rustc_const_eval[b73c79410a5da8b8]::const_eval::valtrees::eval_to_valtree 41: 0x7f822dd1df30 - )>>::call_once 42: 0x7f822dd1df04 - rustc_query_impl[56a5a1cad20ac6aa]::plumbing::__rust_begin_short_backtrace::> 43: 0x7f822dd1dec5 - )>>::call_once 44: 0x7f822d8b252c - rustc_query_system[790ca29724b87fee]::query::plumbing::try_execute_query::, rustc_middle[80ff7a15503a7fbe]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[56a5a1cad20ac6aa]::plumbing::QueryCtxt, false> 45: 0x7f822d8b1e2c - rustc_query_impl[56a5a1cad20ac6aa]::query_impl::eval_to_valtree::get_query_non_incr::__rust_end_short_backtrace 46: 0x7f822d9abeee - rustc_middle[80ff7a15503a7fbe]::query::plumbing::query_get_at::, rustc_middle[80ff7a15503a7fbe]::query::erase::Erased<[u8; 24usize]>>> 47: 0x7f822d9abb19 - ::const_eval_global_id_for_typeck 48: 0x7f822d9ab39e - ::const_eval_resolve_for_typeck 49: 0x7f822c02d826 - ::const_eval_resolve 50: 0x7f822c00fafa - ::try_const_eval_resolve 51: 0x7f822c7c37a5 - ::try_const_eval_resolve 52: 0x7f822c7d1278 - ::with_new_goal::<::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}>::{closure#3} 53: 0x7f822c7ce013 - ::with_new_goal::<::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}> 54: 0x7f822c7c2478 - ::evaluate_goal 55: 0x7f822c83379f - ::try_evaluate_added_goals 56: 0x7f822c830c8d - ::try_normalize_term 57: 0x7f822c7d1d65 - ::with_new_goal::<::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}>::{closure#3} 58: 0x7f822c7ce013 - ::with_new_goal::<::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}> 59: 0x7f822c7c2478 - ::evaluate_goal 60: 0x7f822c83379f - ::try_evaluate_added_goals 61: 0x7f822c8310f1 - ::evaluate_added_goals_and_make_canonical_response 62: 0x7f822c7d5d21 - ::probe_and_match_goal_against_assumption::<::consider_implied_clause<[rustc_middle[80ff7a15503a7fbe]::traits::solve::Goal; 0usize]>::{closure#0}> 63: 0x7f822c830d18 - ::assemble_param_env_candidates:: 64: 0x7f822c7b9055 - ::assemble_and_evaluate_candidates:: 65: 0x7f822c7d197b - ::with_new_goal::<::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}>::{closure#3} 66: 0x7f822c7ce013 - ::with_new_goal::<::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}> 67: 0x7f822c7c2478 - ::evaluate_goal 68: 0x7f822c7c1e6c - ::enter_root::>), rustc_middle[80ff7a15503a7fbe]::traits::query::NoSolution>, ::evaluate_root_goal::{closure#0}> 69: 0x7f822c7c3ff3 - ::select_where_possible 70: 0x7f822d2911a5 - ::select_all_or_error 71: 0x7f822c7e0837 - rustc_trait_selection[4b445828abf7ba1d]::traits::coherence::impl_intersection_has_negative_obligation 72: 0x7f822d2406a6 - rustc_trait_selection[4b445828abf7ba1d]::traits::coherence::overlap 73: 0x7f822da3d42b - ::insert 74: 0x7f822da3c991 - ::insert 75: 0x7f822da3fb77 - rustc_trait_selection[4b445828abf7ba1d]::traits::specialize::specialization_graph_provider 76: 0x7f822da3f60d - rustc_query_impl[56a5a1cad20ac6aa]::plumbing::__rust_begin_short_backtrace::> 77: 0x7f822d0827a0 - rustc_query_system[790ca29724b87fee]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[56a5a1cad20ac6aa]::plumbing::QueryCtxt, false> 78: 0x7f822d583f9e - rustc_query_impl[56a5a1cad20ac6aa]::query_impl::specialization_graph_of::get_query_non_incr::__rust_end_short_backtrace 79: 0x7f822d58438d - rustc_hir_analysis[46d1d11b50942035]::coherence::coherent_trait 80: 0x7f822d584135 - rustc_query_impl[56a5a1cad20ac6aa]::plumbing::__rust_begin_short_backtrace::> 81: 0x7f822d0f2a16 - rustc_query_system[790ca29724b87fee]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[56a5a1cad20ac6aa]::plumbing::QueryCtxt, false> 82: 0x7f822d615e55 - rustc_query_impl[56a5a1cad20ac6aa]::query_impl::coherent_trait::get_query_non_incr::__rust_end_short_backtrace 83: 0x7f822d1c8396 - rustc_hir_analysis[46d1d11b50942035]::check_crate 84: 0x7f822d9e8c13 - rustc_interface[b495b14b2a666c1a]::passes::analysis 85: 0x7f822d9e8869 - rustc_query_impl[56a5a1cad20ac6aa]::plumbing::__rust_begin_short_backtrace::> 86: 0x7f822daaf3a5 - rustc_query_system[790ca29724b87fee]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[56a5a1cad20ac6aa]::plumbing::QueryCtxt, false> 87: 0x7f822daaf109 - rustc_query_impl[56a5a1cad20ac6aa]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 88: 0x7f822dcea77b - rustc_interface[b495b14b2a666c1a]::interface::run_compiler::, rustc_driver_impl[c431125988ed1f11]::run_compiler::{closure#0}>::{closure#0} 89: 0x7f822df7e854 - std[466eff1cc2ed908f]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[c431125988ed1f11]::run_compiler::{closure#0}>::{closure#0}, core[16c6da236be526b4]::result::Result<(), rustc_span[f008fc136599d052]::ErrorGuaranteed>>::{closure#0}, core[16c6da236be526b4]::result::Result<(), rustc_span[f008fc136599d052]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[16c6da236be526b4]::result::Result<(), rustc_span[f008fc136599d052]::ErrorGuaranteed>> 90: 0x7f822df7e680 - <::spawn_unchecked_, rustc_driver_impl[c431125988ed1f11]::run_compiler::{closure#0}>::{closure#0}, core[16c6da236be526b4]::result::Result<(), rustc_span[f008fc136599d052]::ErrorGuaranteed>>::{closure#0}, core[16c6da236be526b4]::result::Result<(), rustc_span[f008fc136599d052]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[16c6da236be526b4]::result::Result<(), rustc_span[f008fc136599d052]::ErrorGuaranteed>>::{closure#1} as core[16c6da236be526b4]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 91: 0x7f8228f99425 - as core::ops::function::FnOnce>::call_once::hf2f3f78227db386b at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/alloc/src/boxed.rs:2016:9 92: 0x7f8228f99425 - as core::ops::function::FnOnce>::call_once::hfde7215efc7d46f6 at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/alloc/src/boxed.rs:2016:9 93: 0x7f8228f99425 - std::sys::pal::unix::thread::Thread::new::thread_start::hca4f71b4c325cea0 at /rustc/a84bb95a1f65bfe25038f188763a18e096a86ab2/library/std/src/sys/pal/unix/thread.rs:108:17 94: 0x7f8228d819eb - 95: 0x7f8228e057cc - 96: 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: rustc 1.78.0-nightly (a84bb95a1 2024-02-13) running on x86_64-unknown-linux-gnu query stack during panic: #0 [codegen_select_candidate] computing candidate for `>` #1 [resolve_instance] resolving instance `>::NUM_ELEMS` #2 [eval_to_allocation_raw] const-evaluating + checking `::{constant#1}` #3 [eval_to_valtree] evaluating type-level constant #4 [specialization_graph_of] building specialization graph of trait `core::ops::arith::Mul` #5 [coherent_trait] coherence checking all impls of trait `core::ops::arith::Mul` #6 [analysis] running analysis passes on this crate end of query stack error: aborting due to 8 previous errors; 1 warning emitted Some errors have detailed explanations: E0207, E0576, E0601. For more information about an error, try `rustc --explain E0207`. ```

matthiaskrgr commented 7 months ago

This bisects to https://github.com/rust-lang/rust/pull/120836 cc @lcnr :thinking:

lcnr commented 7 months ago

the new solver ends up calling into the old one via const evaluation :sweat_smile: the old solver cannot handle placeholder consts :thinking: :shrug:

i think this can impact -Znext-solver=coherence by itself, cc @compiler-errors

lcnr commented 7 months ago

though, given that it relies on gce this seems alright to delay until after the stabilization