Skip to content

ICE: eval_const_to_op: Unexpected ConstKind #74634

Closed
@steffahn

Description

#![feature(const_generics)]
#![allow(incomplete_features)]

trait If<const COND: bool> {}
impl If<true> for () {}

trait IsZero<const N: u8> {
    type Answer;
}

struct True;
struct False;

impl<const N: u8> IsZero<N> for ()
where (): If<{N == 0}> {
    type Answer = True;
}

trait Foobar<const N: u8> {}

impl<const N: u8> Foobar<N> for ()
where (): IsZero<N, Answer = True> {}

impl<const N: u8> Foobar<N> for ()
where (): IsZero<N, Answer = False> {}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: internal compiler error: src/librustc_mir/interpret/operand.rs:569:17: eval_const_to_op: Unexpected ConstKind Const { ty: u8, val: Bound(DebruijnIndex(0), 0) }
  --> src/lib.rs:15:15
   |
15 | where (): If<{N == 0}> {
   |               ^^^^^^

thread 'rustc' panicked at 'Box<Any>', /rustc/f9a3086363f214f2b56bef30f0ac572e1a9127f1/src/libstd/macros.rs:13:23
note: run with `RUST_BACKTRACE=1` environment variable to display a 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.47.0-nightly (f9a308636 2020-07-20) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

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

error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

Probably related: #72819

Removing (at least) one of the impls for Foobar makes the panic go away, and the compiler correctly reports the error:

   Compiling playground v0.0.1 (/playground)
error: constant expression depends on a generic parameter
  --> src/lib.rs:15:11
   |
15 | where (): If<{N == 0}> {
   |           ^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

@rustbot modify labels: I-ICE, T-compiler, A-const-eval, A-const-generics, C-bug, F-const_generics, requires-nightly

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions