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] "cannot relate constants of different types" with feature(adt_const_params, generic_const_exprs) #97007

Closed
hlb8122 opened this issue May 13, 2022 · 0 comments · Fixed by #97709
Assignees
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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

@hlb8122
Copy link

hlb8122 commented May 13, 2022

Code

#![feature(adt_const_params, generic_const_exprs)]
#![allow(incomplete_features)]

mod lib {
    const N_ISLANDS: usize = 4;
    const N_BRIDGES: usize = 7;
    const BRIDGES: [(usize, usize); 7] = [(0, 1), (0, 1), (0, 2), (0, 3), (0, 3), (1, 2), (2, 3)];

    pub type Matrix = [[usize; N_ISLANDS]; N_ISLANDS];

    const EMPTY_MATRIX: Matrix = [[0; N_ISLANDS]; N_ISLANDS];

    const fn build(mut matrix: Matrix, (to, from): (usize, usize)) -> Matrix {
        matrix[to][from] += 1;
        matrix[from][to] += 1;
        matrix
    }

    pub const fn walk(mut matrix: Matrix, from: usize, to: usize) -> Matrix {
        matrix[from][to] -= 1;
        matrix[to][from] -= 1;
        matrix
    }

    const fn to_matrix(bridges: [(usize, usize); N_BRIDGES]) -> Matrix {
        let matrix = EMPTY_MATRIX;

        let matrix = build(matrix, bridges[0]);
        let matrix = build(matrix, bridges[1]);
        let matrix = build(matrix, bridges[2]);
        let matrix = build(matrix, bridges[3]);
        let matrix = build(matrix, bridges[4]);
        let matrix = build(matrix, bridges[5]);
        let matrix = build(matrix, bridges[6]);

        matrix
    }

    const BRIDGE_MATRIX: [[usize; N_ISLANDS]; N_ISLANDS] = to_matrix(BRIDGES);

    pub struct Walk<const CURRENT: usize, const REMAINING: Matrix> {
        _p: (),
    }

    impl Walk<0, BRIDGE_MATRIX> {
        pub const fn new() -> Self {
            Self { _p: () }
        }
    }

    impl<const CURRENT: usize, const REMAINING: Matrix> Walk<CURRENT, REMAINING> {
        pub fn proceed_to<const NEXT: usize>(
            self,
        ) -> Walk<NEXT, { walk(REMAINING, CURRENT, NEXT) }> {
            Walk { _p: () }
        }
    }

    pub struct Trophy {
        _p: (),
    }

    impl<const CURRENT: usize> Walk<CURRENT, EMPTY_MATRIX> {
        pub fn collect_prize(self) -> Trophy {
            Trophy { _p: () }
        }
    }
}

pub use lib::{Trophy, Walk};

fn main() {
    // Example, taking the first step
    let _ = Walk::new().proceed_to::<1>();

    // Don't be so eager to collect the trophy
    // let trophy = Walk::new()
    //     .proceed_to::<1>()
    //     .proceed_to::<0>()
    //     .collect_prize();

    // Can't just make a Trophy out of thin air, you must earn it
    // let trophy: Trophy = Trophy { _p: () };

    // Can you collect the Trophy?
}

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=cec002cde4e6ea9c5ab12ee9c93b1a33

Note that this does not occur if you replace N_ISLAND with hard-coded values
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=448c65a5c73a76d832c510cfe8e269bc

Meta

rustc --version --verbose:

rustc 1.62.0-nightly (a5ad0d29a 2022-05-12)
binary: rustc
commit-hash: a5ad0d29a401007b51715852cc702e441ac2248c
commit-date: 2022-05-12
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1

Error output

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: cannot relate constants of different types: [[usize; 4]; 4] != [[usize; _]; _]
  |
  = note: delayed at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/compiler/rustc_middle/src/ty/relate.rs:586:29

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1369:13
stack backtrace:
   0:     0x7fc2d402ef4d - std::backtrace_rs::backtrace::libunwind::trace::h422c4077f8744b89
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7fc2d402ef4d - std::backtrace_rs::backtrace::trace_unsynchronized::hcccf40e0ba174c1f
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fc2d402ef4d - std::sys_common::backtrace::_print_fmt::h24f1d3a1e85b1a8c
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7fc2d402ef4d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3f1c8f1337fe72ac
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7fc2d408abdc - core::fmt::write::h983f1d8ba31b3bfc
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/core/src/fmt/mod.rs:1196:17
   5:     0x7fc2d40206d1 - std::io::Write::write_fmt::h8846f6583b6c4f19
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/std/src/io/mod.rs:1654:15
   6:     0x7fc2d4031c65 - std::sys_common::backtrace::_print::h32315dd1001d90fe
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7fc2d4031c65 - std::sys_common::backtrace::print::heeb247c299d00082
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7fc2d4031c65 - std::panicking::default_hook::{{closure}}::h37d2e0f8d04e2807
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/std/src/panicking.rs:295:22
   9:     0x7fc2d40318d9 - std::panicking::default_hook::h7d44d6054314ffd4
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/std/src/panicking.rs:314:9
  10:     0x7fc2d47f5fc1 - rustc_driver[66b06878ed46bf5e]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7fc2d4032436 - std::panicking::rust_panic_with_hook::hbe27fc2544734249
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/std/src/panicking.rs:702:17
  12:     0x7fc2d5966731 - std[d36776c608d00fa8]::panicking::begin_panic::<rustc_errors[36b154f54aa4db46]::ExplicitBug>::{closure#0}
  13:     0x7fc2d5965526 - std[d36776c608d00fa8]::sys_common::backtrace::__rust_end_short_backtrace::<std[d36776c608d00fa8]::panicking::begin_panic<rustc_errors[36b154f54aa4db46]::ExplicitBug>::{closure#0}, !>
  14:     0x7fc2d59774a6 - std[d36776c608d00fa8]::panicking::begin_panic::<rustc_errors[36b154f54aa4db46]::ExplicitBug>
  15:     0x7fc2d597b576 - std[d36776c608d00fa8]::panic::panic_any::<rustc_errors[36b154f54aa4db46]::ExplicitBug>
  16:     0x7fc2d7133c31 - <rustc_errors[36b154f54aa4db46]::HandlerInner as core[243e706900b6a3ef]::ops::drop::Drop>::drop
  17:     0x7fc2d6886578 - core[243e706900b6a3ef]::ptr::drop_in_place::<rustc_session[47fb6eda20aa98eb]::parse::ParseSess>
  18:     0x7fc2d68887e3 - <alloc[adcee9b7ba6963a2]::rc::Rc<rustc_session[47fb6eda20aa98eb]::session::Session> as core[243e706900b6a3ef]::ops::drop::Drop>::drop
  19:     0x7fc2d68854ed - core[243e706900b6a3ef]::ptr::drop_in_place::<rustc_interface[6d9aef74e1383607]::interface::Compiler>
  20:     0x7fc2d6884de4 - rustc_span[f40da2bae013e884]::with_source_map::<core[243e706900b6a3ef]::result::Result<(), rustc_errors[36b154f54aa4db46]::ErrorGuaranteed>, rustc_interface[6d9aef74e1383607]::interface::create_compiler_and_run<core[243e706900b6a3ef]::result::Result<(), rustc_errors[36b154f54aa4db46]::ErrorGuaranteed>, rustc_driver[66b06878ed46bf5e]::run_compiler::{closure#1}>::{closure#1}>
  21:     0x7fc2d6870524 - rustc_interface[6d9aef74e1383607]::interface::create_compiler_and_run::<core[243e706900b6a3ef]::result::Result<(), rustc_errors[36b154f54aa4db46]::ErrorGuaranteed>, rustc_driver[66b06878ed46bf5e]::run_compiler::{closure#1}>
  22:     0x7fc2d685aab2 - <scoped_tls[13ae6aa9ead709d8]::ScopedKey<rustc_span[f40da2bae013e884]::SessionGlobals>>::set::<rustc_interface[6d9aef74e1383607]::interface::run_compiler<core[243e706900b6a3ef]::result::Result<(), rustc_errors[36b154f54aa4db46]::ErrorGuaranteed>, rustc_driver[66b06878ed46bf5e]::run_compiler::{closure#1}>::{closure#0}, core[243e706900b6a3ef]::result::Result<(), rustc_errors[36b154f54aa4db46]::ErrorGuaranteed>>
  23:     0x7fc2d6871bcf - std[d36776c608d00fa8]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[6d9aef74e1383607]::util::run_in_thread_pool_with_globals<rustc_interface[6d9aef74e1383607]::interface::run_compiler<core[243e706900b6a3ef]::result::Result<(), rustc_errors[36b154f54aa4db46]::ErrorGuaranteed>, rustc_driver[66b06878ed46bf5e]::run_compiler::{closure#1}>::{closure#0}, core[243e706900b6a3ef]::result::Result<(), rustc_errors[36b154f54aa4db46]::ErrorGuaranteed>>::{closure#0}, core[243e706900b6a3ef]::result::Result<(), rustc_errors[36b154f54aa4db46]::ErrorGuaranteed>>
  24:     0x7fc2d6871d09 - <<std[d36776c608d00fa8]::thread::Builder>::spawn_unchecked_<rustc_interface[6d9aef74e1383607]::util::run_in_thread_pool_with_globals<rustc_interface[6d9aef74e1383607]::interface::run_compiler<core[243e706900b6a3ef]::result::Result<(), rustc_errors[36b154f54aa4db46]::ErrorGuaranteed>, rustc_driver[66b06878ed46bf5e]::run_compiler::{closure#1}>::{closure#0}, core[243e706900b6a3ef]::result::Result<(), rustc_errors[36b154f54aa4db46]::ErrorGuaranteed>>::{closure#0}, core[243e706900b6a3ef]::result::Result<(), rustc_errors[36b154f54aa4db46]::ErrorGuaranteed>>::{closure#1} as core[243e706900b6a3ef]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x7fc2d403c353 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hca3fa30b248623a6
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/alloc/src/boxed.rs:1872:9
  26:     0x7fc2d403c353 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h4df27390e550c728
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/alloc/src/boxed.rs:1872:9
  27:     0x7fc2d403c353 - std::sys::unix::thread::Thread::new::thread_start::h02c78c50592aaddf
                               at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/library/std/src/sys/unix/thread.rs:108:17
  28:     0x7fc2d3f54609 - start_thread
                               at /build/glibc-sMfBJT/glibc-2.31/nptl/pthread_create.c:477:8
  29:     0x7fc2d3e6d163 - clone
                               at /build/glibc-sMfBJT/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  30:                0x0 - <unknown>

note: 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: rustc 1.62.0-nightly (a5ad0d29a 2022-05-12) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
Backtrace

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: cannot relate constants of different types: [[usize; 4]; 4] != [[usize; _]; _]
  |
  = note: delayed at /rustc/a5ad0d29a401007b51715852cc702e441ac2248c/compiler/rustc_middle/src/ty/relate.rs:586:29

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1369:13
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   3: core::ptr::drop_in_place::<rustc_session::parse::ParseSess>
   4: <alloc::rc::Rc<rustc_session::session::Session> as core::ops::drop::Drop>::drop
   5: core::ptr::drop_in_place::<rustc_interface::interface::Compiler>
   6: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
   7: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
   8: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: 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: rustc 1.62.0-nightly (a5ad0d29a 2022-05-12) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack

@hlb8122 hlb8122 added C-bug Category: This is a bug. 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. labels May 13, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label May 21, 2022
@compiler-errors compiler-errors self-assigned this Jun 3, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 13, 2022
…am-ty, r=oli-obk

Normalize consts' tys when relating with `adt_const_params`

Fixes rust-lang#97007
@bors bors closed this as completed in e13eeed Jun 13, 2022
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. glacier ICE tracked in rust-lang/glacier. 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