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: coherence: assertion failed: obligations.is_empty() / unexpected infer in QueryInput #125556

Closed
matthiaskrgr opened this issue May 25, 2024 · 2 comments · Fixed by #125958
Closed
Labels
C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` 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.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

#![feature(generic_const_exprs)]

mod v20 {

    pub type v11 = [[usize; v4]; v4];

    const v0: [[usize; v4]; v4] = v6(v8);
    pub struct v17<const v10: usize, const v7: v11> {
        _p: (),
    }

    impl v17<512, v0> {
        pub const fn v21() -> v18 {}
    }

    impl v17<v10, v2> {
        pub const fn v21() -> v18 {}
    }
}

original:

#![feature(generic_const_exprs)]

mod v20 {
    const v0: usize = 512;
    pub type v11 = [[usize; v4]; v4];
    const v2: v11 = [[256; v4]; v4];

    const v0: [[usize; v4]; v4] = v6(v8);
    pub struct v17<const v10: usize, const v7: v11> {
        _p: (),
    }

    impl v17<512, v0> {
        pub const fn v21() -> v18 {}
    }

    impl<const v10: usize> v17<v10, v2> {
        pub const fn v21() -> v18 {
            v18 { _p: () }
        }
    }
}
pub use v20::{v13, v17};
fn main() {}

Version information

rustc 1.80.0-nightly (48f00110d 2024-05-25)
binary: rustc
commit-hash: 48f00110d0dae38b3046a9ac05d20ea321fd6637
commit-date: 2024-05-25
host: x86_64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Znext-solver=coherence

Program output

error[E0425]: cannot find value `v4` in this scope
 --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:5:29
  |
5 |     pub type v11 = [[usize; v4]; v4];
  |                             ^^ help: a constant with a similar name exists: `v0`
6 |
7 |     const v0: [[usize; v4]; v4] = v6(v8);
  |     ------------------------------------- similarly named constant `v0` defined here

error[E0425]: cannot find value `v4` in this scope
 --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:5:34
  |
5 |     pub type v11 = [[usize; v4]; v4];
  |                                  ^^ help: a constant with a similar name exists: `v0`
6 |
7 |     const v0: [[usize; v4]; v4] = v6(v8);
  |     ------------------------------------- similarly named constant `v0` defined here

error[E0425]: cannot find value `v4` in this scope
 --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:7:24
  |
7 |     const v0: [[usize; v4]; v4] = v6(v8);
  |                        ^^ not found in this scope

error[E0425]: cannot find value `v4` in this scope
 --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:7:29
  |
7 |     const v0: [[usize; v4]; v4] = v6(v8);
  |                             ^^ not found in this scope

error[E0425]: cannot find value `v8` in this scope
 --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:7:38
  |
7 |     const v0: [[usize; v4]; v4] = v6(v8);
  |                                      ^^ not found in this scope

error[E0412]: cannot find type `v18` in this scope
  --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:13:31
   |
5  |     pub type v11 = [[usize; v4]; v4];
   |     --------------------------------- similarly named type alias `v11` defined here
...
13 |         pub const fn v21() -> v18 {}
   |                               ^^^ help: a type alias with a similar name exists: `v11`

error[E0412]: cannot find type `v10` in this scope
  --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:16:14
   |
5  |     pub type v11 = [[usize; v4]; v4];
   |     --------------------------------- similarly named type alias `v11` defined here
...
16 |     impl v17<v10, v2> {
   |              ^^^
   |
help: a type alias with a similar name exists
   |
16 |     impl v17<v11, v2> {
   |              ~~~
help: you might be missing a type parameter
   |
16 |     impl<v10> v17<v10, v2> {
   |         +++++

error[E0412]: cannot find type `v2` in this scope
  --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:16:19
   |
16 |     impl v17<v10, v2> {
   |                   ^^ not found in this scope
   |
help: you might be missing a type parameter
   |
16 |     impl<v2> v17<v10, v2> {
   |         ++++

error[E0412]: cannot find type `v18` in this scope
  --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:17:31
   |
5  |     pub type v11 = [[usize; v4]; v4];
   |     --------------------------------- similarly named type alias `v11` defined here
...
17 |         pub const fn v21() -> v18 {}
   |                               ^^^ help: a type alias with a similar name exists: `v11`

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:1:12
  |
1 | #![feature(generic_const_exprs)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: type `v11` should have an upper camel case name
 --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:5:14
  |
5 |     pub type v11 = [[usize; v4]; v4];
  |              ^^^ help: convert the identifier to upper camel case (notice the capitalization): `V11`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

warning: type `v17` should have an upper camel case name
 --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:8:16
  |
8 |     pub struct v17<const v10: usize, const v7: v11> {
  |                ^^^ help: convert the identifier to upper camel case (notice the capitalization): `V17`

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:19:2
   |
19 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs`

error[E0425]: cannot find function `v6` in this scope
 --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:7:35
  |
7 |     const v0: [[usize; v4]; v4] = v6(v8);
  |                                   ^^ not found in this scope

error: `[[usize; v4]; v4]` is forbidden as the type of a const generic parameter
 --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:8:48
  |
8 |     pub struct v17<const v10: usize, const v7: v11> {
  |                                                ^^^
  |
  = note: the only supported types are integers, `bool` and `char`
help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types
  |
3 + #![feature(adt_const_params)]
  |

error[E0747]: unresolved item provided when a constant was expected
  --> /tmp/icemaker_global_tempdir.iEGYn0XYvA4f/rustc_testrunner_tmpdir_reporting.rHVhnk0l6xFH/mvce.rs:16:14
   |
16 |     impl v17<v10, v2> {
   |              ^^^
   |
help: if this generic argument was intended as a const parameter, surround it with braces
   |
16 |     impl v17<{ v10 }, v2> {
   |              +     +

thread 'rustc' panicked at compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs:354:13:
assertion failed: obligations.is_empty()
stack backtrace:
   0:     0x786ef26b3075 - std::backtrace_rs::backtrace::libunwind::trace::h42aea1e7bd0a8d0f
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x786ef26b3075 - std::backtrace_rs::backtrace::trace_unsynchronized::hf3ac14f94797a8ff
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x786ef26b3075 - std::sys_common::backtrace::_print_fmt::hfdeb6f5ed3f5afaa
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x786ef26b3075 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3a3bab3a7e07f684
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x786ef270218b - core::fmt::rt::Argument::fmt::h827eaf91b0235e22
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/core/src/fmt/rt.rs:165:63
   5:     0x786ef270218b - core::fmt::write::h3c9de6e4b056660b
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/core/src/fmt/mod.rs:1172:21
   6:     0x786ef26a7dcf - std::io::Write::write_fmt::h4989c38cc46ac4a9
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/io/mod.rs:1835:15
   7:     0x786ef26b2e4e - std::sys_common::backtrace::_print::hf88b29e9f4397d20
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x786ef26b2e4e - std::sys_common::backtrace::print::ha9d7657d2fccb9ae
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x786ef26b5879 - std::panicking::default_hook::{{closure}}::hc05689f1cbee5d27
  10:     0x786ef26b561a - std::panicking::default_hook::hd873922dd239ed0b
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/panicking.rs:298:9
  11:     0x786eef0f9eef - std[f497e4f3b89fc98e]::panicking::update_hook::<alloc[98811ad6430038c6]::boxed::Box<rustc_driver_impl[54b05657baa3450f]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x786ef26b5fab - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hf701087af7d36f49
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/alloc/src/boxed.rs:2077:9
  13:     0x786ef26b5fab - std::panicking::rust_panic_with_hook::haff0763df51daf39
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/panicking.rs:799:13
  14:     0x786ef26b5ceb - std::panicking::begin_panic_handler::{{closure}}::hc16ab47bd0d35526
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/panicking.rs:656:13
  15:     0x786ef26b3539 - std::sys_common::backtrace::__rust_end_short_backtrace::h65417fe81de7a832
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x786ef26b5a57 - rust_begin_unwind
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/panicking.rs:652:5
  17:     0x786ef26fe753 - core::panicking::panic_fmt::h94f1edd420c4d371
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/core/src/panicking.rs:72:14
  18:     0x786ef26fe7fc - core::panicking::panic::h3e16a54ff7079537
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/core/src/panicking.rs:146:5
  19:     0x786ef08bcc27 - <rustc_trait_selection[63ce0d138858f6da]::solve::eval_ctxt::EvalCtxt<rustc_infer[4c65ead5c75e00e7]::infer::InferCtxt, rustc_middle[8d1200f20c5736b5]::ty::context::TyCtxt>>::unify_query_var_values
  20:     0x786ef10acf5e - <rustc_trait_selection[63ce0d138858f6da]::solve::eval_ctxt::EvalCtxt<rustc_infer[4c65ead5c75e00e7]::infer::InferCtxt, rustc_middle[8d1200f20c5736b5]::ty::context::TyCtxt>>::evaluate_goal_raw
  21:     0x786ef10b17c0 - <rustc_trait_selection[63ce0d138858f6da]::solve::eval_ctxt::EvalCtxt<rustc_infer[4c65ead5c75e00e7]::infer::InferCtxt, rustc_middle[8d1200f20c5736b5]::ty::context::TyCtxt>>::try_evaluate_added_goals
  22:     0x786ef10b9f43 - <rustc_trait_selection[63ce0d138858f6da]::solve::search_graph::SearchGraph<rustc_middle[8d1200f20c5736b5]::ty::context::TyCtxt>>::with_new_goal::<<rustc_trait_selection[63ce0d138858f6da]::solve::eval_ctxt::EvalCtxt<rustc_infer[4c65ead5c75e00e7]::infer::InferCtxt, rustc_middle[8d1200f20c5736b5]::ty::context::TyCtxt>>::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}>::{closure#2}
  23:     0x786ef10b2f46 - <rustc_trait_selection[63ce0d138858f6da]::solve::search_graph::SearchGraph<rustc_middle[8d1200f20c5736b5]::ty::context::TyCtxt>>::with_new_goal::<<rustc_trait_selection[63ce0d138858f6da]::solve::eval_ctxt::EvalCtxt<rustc_infer[4c65ead5c75e00e7]::infer::InferCtxt, rustc_middle[8d1200f20c5736b5]::ty::context::TyCtxt>>::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}>
  24:     0x786ef10ac904 - <rustc_trait_selection[63ce0d138858f6da]::solve::eval_ctxt::EvalCtxt<rustc_infer[4c65ead5c75e00e7]::infer::InferCtxt, rustc_middle[8d1200f20c5736b5]::ty::context::TyCtxt>>::evaluate_goal_raw
  25:     0x786ef10abc11 - <rustc_infer[4c65ead5c75e00e7]::infer::InferCtxt as rustc_trait_selection[63ce0d138858f6da]::solve::eval_ctxt::InferCtxtEvalExt>::evaluate_root_goal
  26:     0x786ef10ab560 - <rustc_trait_selection[63ce0d138858f6da]::solve::fulfill::FulfillmentCtxt as rustc_infer[4c65ead5c75e00e7]::traits::engine::TraitEngine>::select_where_possible
  27:     0x786ef06d5a7a - <rustc_trait_selection[63ce0d138858f6da]::traits::engine::ObligationCtxt>::select_all_or_error
  28:     0x786ef08be83d - rustc_trait_selection[63ce0d138858f6da]::traits::coherence::overlap
  29:     0x786ef13cd078 - rustc_trait_selection[63ce0d138858f6da]::traits::coherence::overlapping_impls
  30:     0x786ef13cc479 - <rustc_hir_analysis[773f5f9066629b08]::coherence::inherent_impls_overlap::InherentOverlapChecker>::check_for_overlapping_inherent_impls
  31:     0x786ef0a66c1b - rustc_hir_analysis[773f5f9066629b08]::coherence::inherent_impls_overlap::crate_inherent_impls_overlap_check
  32:     0x786ef0a664e7 - rustc_query_impl[f809864b4f0d0f3d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f809864b4f0d0f3d]::query_impl::crate_inherent_impls_overlap_check::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d1200f20c5736b5]::query::erase::Erased<[u8; 1usize]>>
  33:     0x786ef11553a5 - rustc_query_system[7155d4f1ed1184a2]::query::plumbing::try_execute_query::<rustc_query_impl[f809864b4f0d0f3d]::DynamicConfig<rustc_query_system[7155d4f1ed1184a2]::query::caches::SingleCache<rustc_middle[8d1200f20c5736b5]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[f809864b4f0d0f3d]::plumbing::QueryCtxt, false>
  34:     0x786ef115518f - rustc_query_impl[f809864b4f0d0f3d]::query_impl::crate_inherent_impls_overlap_check::get_query_non_incr::__rust_end_short_backtrace
  35:     0x786ef07acbb7 - rustc_hir_analysis[773f5f9066629b08]::check_crate
  36:     0x786ef078d07e - rustc_interface[58067e46342fbaaa]::passes::analysis
  37:     0x786ef078cbd5 - rustc_query_impl[f809864b4f0d0f3d]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f809864b4f0d0f3d]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8d1200f20c5736b5]::query::erase::Erased<[u8; 1usize]>>
  38:     0x786ef11553a5 - rustc_query_system[7155d4f1ed1184a2]::query::plumbing::try_execute_query::<rustc_query_impl[f809864b4f0d0f3d]::DynamicConfig<rustc_query_system[7155d4f1ed1184a2]::query::caches::SingleCache<rustc_middle[8d1200f20c5736b5]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[f809864b4f0d0f3d]::plumbing::QueryCtxt, false>
  39:     0x786ef115510f - rustc_query_impl[f809864b4f0d0f3d]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  40:     0x786ef0fcac5c - rustc_interface[58067e46342fbaaa]::interface::run_compiler::<core[e093d3f8342b0aab]::result::Result<(), rustc_span[f743e6227e8610a7]::ErrorGuaranteed>, rustc_driver_impl[54b05657baa3450f]::run_compiler::{closure#0}>::{closure#1}
  41:     0x786ef0fb6d09 - std[f497e4f3b89fc98e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[58067e46342fbaaa]::util::run_in_thread_with_globals<rustc_interface[58067e46342fbaaa]::util::run_in_thread_pool_with_globals<rustc_interface[58067e46342fbaaa]::interface::run_compiler<core[e093d3f8342b0aab]::result::Result<(), rustc_span[f743e6227e8610a7]::ErrorGuaranteed>, rustc_driver_impl[54b05657baa3450f]::run_compiler::{closure#0}>::{closure#1}, core[e093d3f8342b0aab]::result::Result<(), rustc_span[f743e6227e8610a7]::ErrorGuaranteed>>::{closure#0}, core[e093d3f8342b0aab]::result::Result<(), rustc_span[f743e6227e8610a7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e093d3f8342b0aab]::result::Result<(), rustc_span[f743e6227e8610a7]::ErrorGuaranteed>>
  42:     0x786ef0fb6ac8 - <<std[f497e4f3b89fc98e]::thread::Builder>::spawn_unchecked_<rustc_interface[58067e46342fbaaa]::util::run_in_thread_with_globals<rustc_interface[58067e46342fbaaa]::util::run_in_thread_pool_with_globals<rustc_interface[58067e46342fbaaa]::interface::run_compiler<core[e093d3f8342b0aab]::result::Result<(), rustc_span[f743e6227e8610a7]::ErrorGuaranteed>, rustc_driver_impl[54b05657baa3450f]::run_compiler::{closure#0}>::{closure#1}, core[e093d3f8342b0aab]::result::Result<(), rustc_span[f743e6227e8610a7]::ErrorGuaranteed>>::{closure#0}, core[e093d3f8342b0aab]::result::Result<(), rustc_span[f743e6227e8610a7]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e093d3f8342b0aab]::result::Result<(), rustc_span[f743e6227e8610a7]::ErrorGuaranteed>>::{closure#2} as core[e093d3f8342b0aab]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x786ef26bfd8b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h07c51d08fbe7b366
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/alloc/src/boxed.rs:2063:9
  44:     0x786ef26bfd8b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h59743c0df790be85
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/alloc/src/boxed.rs:2063:9
  45:     0x786ef26bfd8b - std::sys::pal::unix::thread::Thread::new::thread_start::h35133497d39238f8
                               at /rustc/48f00110d0dae38b3046a9ac05d20ea321fd6637/library/std/src/sys/pal/unix/thread.rs:108:17
  46:     0x786eebeaa1cf - <unknown>
  47:     0x786eebf2b6ec - <unknown>
  48:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

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 make sure that you have updated to the latest nightly

note: rustc 1.80.0-nightly (48f00110d 2024-05-25) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z next-solver=coherence -Z dump-mir-dir=dir

query stack during panic:
#0 [crate_inherent_impls_overlap_check] check for overlap between inherent impls defined in this crate
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 13 previous errors; 3 warnings emitted

Some errors have detailed explanations: E0412, E0425, E0601, E0747.
For more information about an error, try `rustc --explain E0412`.

@rustbot label +F-generic_const_exprs

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels May 25, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-generic_const_exprs `#![feature(generic_const_exprs)]` labels May 25, 2024
@matthiaskrgr
Copy link
Member Author

smaller:

#![feature(generic_const_exprs)]

pub struct A<const z: [usize; x]> {}

impl A<2> {
    pub const fn B() {}
}

impl A<2> {
    pub const fn B() {}
}

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 26, 2024
@matthiaskrgr
Copy link
Member Author

updated stacktrace:

thread 'rustc' panicked at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/compiler/rustc_next_trait_solver/src/canonicalizer.rs:67:9:
unexpected infer in QueryInput { goal: Goal { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, predicate: Binder { value: NormalizesTo(AliasTerm { args: [], def_id: DefId(0:7 ~ 125556[b46a]::{impl#0}::{constant#0}) }, Term::Const(^1_0: [usize; ?1c: usize])), bound_vars: [] } }, predefined_opaques_in_body: PredefinedOpaques(PredefinedOpaquesData { opaque_types: [] }) }
stack backtrace:
   0:     0x7dbe3d5ffae5 - std::backtrace_rs::backtrace::libunwind::trace::h8e3ec5065424d28b
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7dbe3d5ffae5 - std::backtrace_rs::backtrace::trace_unsynchronized::h882cf49e59475dbc
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7dbe3d5ffae5 - std::sys_common::backtrace::_print_fmt::h2c337a2c4b83dc01
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7dbe3d5ffae5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5fad958b7140a660
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7dbe3d6505db - core::fmt::rt::Argument::fmt::h9f1efa968e340ff7
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/core/src/fmt/rt.rs:165:63
   5:     0x7dbe3d6505db - core::fmt::write::hc4341e028d4aa04e
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/core/src/fmt/mod.rs:1168:21
   6:     0x7dbe3d5f486f - std::io::Write::write_fmt::hf3dd4197197b5730
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/io/mod.rs:1835:15
   7:     0x7dbe3d5ff8be - std::sys_common::backtrace::_print::hee589e8f95e333af
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7dbe3d5ff8be - std::sys_common::backtrace::print::hc6a85e053c1c7334
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7dbe3d6022e9 - std::panicking::default_hook::{{closure}}::he62a1676f96fee54
  10:     0x7dbe3d60208a - std::panicking::default_hook::h2ceb904f12dea8be
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/panicking.rs:298:9
  11:     0x7dbe39f8e6a0 - std[d6c1f98fb4e95ff7]::panicking::update_hook::<alloc[78b6f7e6bd40c475]::boxed::Box<rustc_driver_impl[c511ea10b869fcf7]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7dbe3d602a1b - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hc5b72f85a4688529
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/alloc/src/boxed.rs:2077:9
  13:     0x7dbe3d602a1b - std::panicking::rust_panic_with_hook::h0a690364d46daaac
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/panicking.rs:799:13
  14:     0x7dbe3d602794 - std::panicking::begin_panic_handler::{{closure}}::h9c10c03249dd0030
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/panicking.rs:664:13
  15:     0x7dbe3d5fffa9 - std::sys_common::backtrace::__rust_end_short_backtrace::h599802efea5774a9
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7dbe3d6024c7 - rust_begin_unwind
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/panicking.rs:652:5
  17:     0x7dbe3d64cb73 - core::panicking::panic_fmt::h16f8f3f4aae78ff5
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/core/src/panicking.rs:72:14
  18:     0x7dbe3c11a183 - <rustc_trait_selection[48403c12d20ee1be]::solve::eval_ctxt::EvalCtxt<rustc_infer[49f51fa3600332dc]::infer::InferCtxt, rustc_middle[b8101328ceeb956a]::ty::context::TyCtxt>>::evaluate_goal_raw
  19:     0x7dbe3c11e1b3 - <rustc_trait_selection[48403c12d20ee1be]::solve::eval_ctxt::EvalCtxt<rustc_infer[49f51fa3600332dc]::infer::InferCtxt, rustc_middle[b8101328ceeb956a]::ty::context::TyCtxt>>::try_evaluate_added_goals
  20:     0x7dbe3c124082 - <rustc_trait_selection[48403c12d20ee1be]::solve::search_graph::SearchGraph<rustc_middle[b8101328ceeb956a]::ty::context::TyCtxt>>::with_new_goal::<<rustc_trait_selection[48403c12d20ee1be]::solve::eval_ctxt::EvalCtxt<rustc_infer[49f51fa3600332dc]::infer::InferCtxt, rustc_middle[b8101328ceeb956a]::ty::context::TyCtxt>>::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}>::{closure#2}
  21:     0x7dbe3c11fec6 - <rustc_trait_selection[48403c12d20ee1be]::solve::search_graph::SearchGraph<rustc_middle[b8101328ceeb956a]::ty::context::TyCtxt>>::with_new_goal::<<rustc_trait_selection[48403c12d20ee1be]::solve::eval_ctxt::EvalCtxt<rustc_infer[49f51fa3600332dc]::infer::InferCtxt, rustc_middle[b8101328ceeb956a]::ty::context::TyCtxt>>::evaluate_canonical_goal::{closure#0}::{closure#0}::{closure#0}>
  22:     0x7dbe3c119084 - <rustc_trait_selection[48403c12d20ee1be]::solve::eval_ctxt::EvalCtxt<rustc_infer[49f51fa3600332dc]::infer::InferCtxt, rustc_middle[b8101328ceeb956a]::ty::context::TyCtxt>>::evaluate_goal_raw
  23:     0x7dbe3c118391 - <rustc_infer[49f51fa3600332dc]::infer::InferCtxt as rustc_trait_selection[48403c12d20ee1be]::solve::eval_ctxt::InferCtxtEvalExt>::evaluate_root_goal
  24:     0x7dbe3c117ce0 - <rustc_trait_selection[48403c12d20ee1be]::solve::fulfill::FulfillmentCtxt as rustc_infer[49f51fa3600332dc]::traits::engine::TraitEngine>::select_where_possible
  25:     0x7dbe3b6d8976 - <rustc_trait_selection[48403c12d20ee1be]::traits::engine::ObligationCtxt>::select_all_or_error
  26:     0x7dbe3b7f8007 - rustc_trait_selection[48403c12d20ee1be]::traits::coherence::overlap
  27:     0x7dbe3c4223f8 - rustc_trait_selection[48403c12d20ee1be]::traits::coherence::overlapping_impls
  28:     0x7dbe3c4217f9 - <rustc_hir_analysis[4a9f7cb3dd37a3dc]::coherence::inherent_impls_overlap::InherentOverlapChecker>::check_for_overlapping_inherent_impls
  29:     0x7dbe3ba302b5 - rustc_hir_analysis[4a9f7cb3dd37a3dc]::coherence::inherent_impls_overlap::crate_inherent_impls_overlap_check
  30:     0x7dbe3ba2fb97 - rustc_query_impl[a43b8a3fae63a645]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a43b8a3fae63a645]::query_impl::crate_inherent_impls_overlap_check::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b8101328ceeb956a]::query::erase::Erased<[u8; 1usize]>>
  31:     0x7dbe3c19c225 - rustc_query_system[ef4de90281b6d444]::query::plumbing::try_execute_query::<rustc_query_impl[a43b8a3fae63a645]::DynamicConfig<rustc_query_system[ef4de90281b6d444]::query::caches::SingleCache<rustc_middle[b8101328ceeb956a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a43b8a3fae63a645]::plumbing::QueryCtxt, false>
  32:     0x7dbe3c19c00f - rustc_query_impl[a43b8a3fae63a645]::query_impl::crate_inherent_impls_overlap_check::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7dbe3b5bf07b - rustc_hir_analysis[4a9f7cb3dd37a3dc]::check_crate
  34:     0x7dbe3bd683fe - rustc_interface[3320d9bec8b3433a]::passes::analysis
  35:     0x7dbe3bd67f5b - rustc_query_impl[a43b8a3fae63a645]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a43b8a3fae63a645]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b8101328ceeb956a]::query::erase::Erased<[u8; 1usize]>>
  36:     0x7dbe3c19c225 - rustc_query_system[ef4de90281b6d444]::query::plumbing::try_execute_query::<rustc_query_impl[a43b8a3fae63a645]::DynamicConfig<rustc_query_system[ef4de90281b6d444]::query::caches::SingleCache<rustc_middle[b8101328ceeb956a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a43b8a3fae63a645]::plumbing::QueryCtxt, false>
  37:     0x7dbe3c19bf8f - rustc_query_impl[a43b8a3fae63a645]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7dbe3bff9f5c - rustc_interface[3320d9bec8b3433a]::interface::run_compiler::<core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>, rustc_driver_impl[c511ea10b869fcf7]::run_compiler::{closure#0}>::{closure#1}
  39:     0x7dbe3bfc0609 - std[d6c1f98fb4e95ff7]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[3320d9bec8b3433a]::util::run_in_thread_with_globals<rustc_interface[3320d9bec8b3433a]::util::run_in_thread_pool_with_globals<rustc_interface[3320d9bec8b3433a]::interface::run_compiler<core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>, rustc_driver_impl[c511ea10b869fcf7]::run_compiler::{closure#0}>::{closure#1}, core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>>::{closure#0}, core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>>
  40:     0x7dbe3bfc03b2 - <<std[d6c1f98fb4e95ff7]::thread::Builder>::spawn_unchecked_<rustc_interface[3320d9bec8b3433a]::util::run_in_thread_with_globals<rustc_interface[3320d9bec8b3433a]::util::run_in_thread_pool_with_globals<rustc_interface[3320d9bec8b3433a]::interface::run_compiler<core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>, rustc_driver_impl[c511ea10b869fcf7]::run_compiler::{closure#0}>::{closure#1}, core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>>::{closure#0}, core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5e8023d66ded8339]::result::Result<(), rustc_span[8ae10af61471f323]::ErrorGuaranteed>>::{closure#2} as core[5e8023d66ded8339]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7dbe3d60c9eb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha3f12f701ab217ba
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/alloc/src/boxed.rs:2063:9
  42:     0x7dbe3d60c9eb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hbabc732018734ba3
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/alloc/src/boxed.rs:2063:9
  43:     0x7dbe3d60c9eb - std::sys::pal::unix::thread::Thread::new::thread_start::h25b845304e0b166b
                               at /rustc/7717a306b2678ba9ece19b723c76a6b3a89ba931/library/std/src/sys/pal/unix/thread.rs:108:17
  44:     0x7dbe36a94ac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  45:     0x7dbe36b26850 - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  46:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

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 make sure that you have updated to the latest nightly

note: please attach the file at `/home/gh-matthiaskrgr/vcs/github/rust_icemaker/rustc-ice-2024-05-28T16_58_51-2140353.txt` to your bug report

note: compiler flags: -Z next-solver=coherence

query stack during panic:
#0 [crate_inherent_impls_overlap_check] check for overlap between inherent impls defined in this crate
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 5 previous errors; 1 warning emitted

Some errors have detailed explanations: E0308, E0425, E0601.
For more information about an error, try `rustc --explain E0308`.

@matthiaskrgr matthiaskrgr changed the title ICE: coherence: assertion failed: obligations.is_empty() ICE: coherence: assertion failed: obligations.is_empty() / unexpected infer in QueryInput May 28, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2024
Remove the `ty` field from type system `Const`s

Fixes rust-lang#125556
Fixes rust-lang#122908

Part of the work on `adt_const_params`/`generic_const_param_types`/`min_generic_const_exprs`/generally making the compiler nicer. cc rust-lang/project-const-generics#44

Please review commit-by-commit otherwise I wasted a lot of time not just squashing this into a giant mess (and also it'll be SO much nicer because theres a lot of fluff changes mixed in with other more careful changes if looking via File Changes

---

Why do this?
- The `ty` field keeps causing ICEs and weird behaviour due to it either being treated as "part of the const" or it being forgotten about leading to ICEs.
- As we move forward with `adt_const_params` and a potential `min_generic_const_exprs` it's going to become more complex to actually lower the correct `Ty<'tcx>`
- It muddles the idea behind how we check `Const` arguments have the correct type. By having the `ty` field it may seem like we ought to be relating it when we relate two types, or that its generally important information about the `Const`.
- Brings the compiler more in line with `a-mir-formality` as that also tracks the type of type system `Const`s via `ConstArgHasType` bounds in the env instead of on the `Const` itself.
- A lot of stuff is a lot nicer when you dont have to pass around the type of a const lol. Everywhere we construct `Const` is now significantly nicer 😅

See rust-lang#125671's description for some more information about the `ty` field

---

General summary of changes in this PR:

- Add `Ty` to `ConstKind::Value` as otherwise there is no way to implement `ConstArgHasType` to ensure that const arguments are correctly typed for the parameter when we stop creating anon consts for all const args. It's also just incredibly difficult/annoying to thread the correct `Ty` around to a bunch of ctfe functions otherwise.
-  Fully implement `ConstArgHasType` in both the old and new solver. Since it now has no reliance on the `ty` field it serves its originally intended purpose of being able to act as a double check that trait vs impls have correctly typed const parameters. It also will now be able to be responsible for checking types of const arguments to parameters under `min_generic_const_exprs`.
- Add `Ty` to `mir::Const::Ty`. I dont have a great understanding of why mir constants are setup like this to be honest. Regardless they need to be able to determine the type of the const and the easiest way to make this happen was to simply store the `Ty` along side the `ty::Const`. Maybe we can do better here in the future but I'd have to spend way more time looking at everywhere we use `mir::Const`.
- rustdoc has its own `Const` which also has a `ty` field. It was relatively easy to remove this.

---

r? `@lcnr` `@compiler-errors`
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 6, 2024
Remove the `ty` field from type system `Const`s

Fixes rust-lang#125556
Fixes rust-lang#122908

Part of the work on `adt_const_params`/`generic_const_param_types`/`min_generic_const_exprs`/generally making the compiler nicer. cc rust-lang/project-const-generics#44

Please review commit-by-commit otherwise I wasted a lot of time not just squashing this into a giant mess (and also it'll be SO much nicer because theres a lot of fluff changes mixed in with other more careful changes if looking via File Changes

---

Why do this?
- The `ty` field keeps causing ICEs and weird behaviour due to it either being treated as "part of the const" or it being forgotten about leading to ICEs.
- As we move forward with `adt_const_params` and a potential `min_generic_const_exprs` it's going to become more complex to actually lower the correct `Ty<'tcx>`
- It muddles the idea behind how we check `Const` arguments have the correct type. By having the `ty` field it may seem like we ought to be relating it when we relate two types, or that its generally important information about the `Const`.
- Brings the compiler more in line with `a-mir-formality` as that also tracks the type of type system `Const`s via `ConstArgHasType` bounds in the env instead of on the `Const` itself.
- A lot of stuff is a lot nicer when you dont have to pass around the type of a const lol. Everywhere we construct `Const` is now significantly nicer 😅

See rust-lang#125671's description for some more information about the `ty` field

---

General summary of changes in this PR:

- Add `Ty` to `ConstKind::Value` as otherwise there is no way to implement `ConstArgHasType` to ensure that const arguments are correctly typed for the parameter when we stop creating anon consts for all const args. It's also just incredibly difficult/annoying to thread the correct `Ty` around to a bunch of ctfe functions otherwise.
-  Fully implement `ConstArgHasType` in both the old and new solver. Since it now has no reliance on the `ty` field it serves its originally intended purpose of being able to act as a double check that trait vs impls have correctly typed const parameters. It also will now be able to be responsible for checking types of const arguments to parameters under `min_generic_const_exprs`.
- Add `Ty` to `mir::Const::Ty`. I dont have a great understanding of why mir constants are setup like this to be honest. Regardless they need to be able to determine the type of the const and the easiest way to make this happen was to simply store the `Ty` along side the `ty::Const`. Maybe we can do better here in the future but I'd have to spend way more time looking at everywhere we use `mir::Const`.
- rustdoc has its own `Const` which also has a `ty` field. It was relatively easy to remove this.

---

r? `@lcnr` `@compiler-errors`
@bors bors closed this as completed in 003a902 Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants