Closed
Description
edit: current minimal repro #82268 (comment)
Error Message
Compiling playground v0.0.1 (/playground)
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
--> src/main.rs:1:12
|
1 | #![feature(const_generics, const_evaluatable_checked)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
warning: the feature `const_evaluatable_checked` is incomplete and may not be safe to use and/or cause compiler crashes
--> src/main.rs:1:28
|
1 | #![feature(const_generics, const_evaluatable_checked)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
error: internal compiler error: compiler/rustc_middle/src/ty/subst.rs:568:17: const parameter `MASK/#2` (Const { ty: u32, val: Param(MASK/#2) }/2) out of range when substituting substs=[]
thread 'rustc' panicked at 'Box<Any>', /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/panic.rs:59:5
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.52.0-nightly (5fa22fe6f 2021-02-14) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [check_item_well_formed] checking that `<(H, T) as Collate<MASK>>` is well-formed
#1 [analysis] running analysis passes on this crate
end of query stack
thread 'rustc' panicked at 'Box<Any>', /rustc/5fa22fe6f821ac3801d05f624b123dda25fde32c/library/std/src/panic.rs:59:5
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.52.0-nightly (5fa22fe6f 2021-02-14) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `<(H, T) as Collate<MASK>>::{constant#0}`
#1 [eval_to_const_value_raw] simplifying constant for the type system `<(H, T) as Collate<MASK>>::{constant#0}`
end of query stack
error: aborting due to previous error; 2 warnings emitted
error: could not compile `playground`
To learn more, run the command again with --verbose.
Code
#![feature(const_generics, const_evaluatable_checked)]
struct True;
struct False;
trait ConstBool {
type Val;
}
struct TypeBool<const X: bool>;
impl ConstBool for TypeBool<true> {
type Val = True;
}
impl ConstBool for TypeBool<false> {
type Val = False;
}
trait Collate<const MASK: u32> {
type Pass;
type Fail;
fn collate(self) -> (Self::Pass, Self::Fail);
}
impl<const MASK: u32> Collate<MASK> for () {
type Pass = ();
type Fail = ();
fn collate(self) -> ((), ()) {
((), ())
}
}
trait CollateStep<X, Prev> {
type Pass;
type Fail;
fn collate_step(x: X, prev: Prev) -> (Self::Pass, Self::Fail);
}
impl<X, P, F> CollateStep<X, (P, F)> for TypeBool<true> {
type Pass = (X, P);
type Fail = F;
fn collate_step(x: X, (p, f): (P, F)) -> ((X, P), F) {
((x, p), f)
}
}
impl<X, P, F> CollateStep<X, (P, F)> for TypeBool<false> {
type Pass = P;
type Fail = (X, F);
fn collate_step(x: X, (p, f): (P, F)) -> (P, (X, F)) {
(p, (x, f))
}
}
impl<H, T: Collate<{ MASK >> 1 }>, const MASK: u32> Collate<MASK> for (H, T)
where
TypeBool<{ 1 == MASK & 1 }>: CollateStep<H, (T::Pass, T::Fail)>,
{
type Pass =
<TypeBool<{ 1 == MASK & 1 }> as CollateStep<H, (T::Pass, T::Fail)>>::Pass;
type Fail =
<TypeBool<{ 1 == MASK & 1 }> as CollateStep<H, (T::Pass, T::Fail)>>::Fail;
fn collate(self) -> (Self::Pass, Self::Fail) {
<TypeBool<{ 1 == MASK & 1 }>
as CollateStep<H, (T::Pass, T::Fail)>>
::collate_step(self.0, self.1.collate())
}
}
fn collate<X,const MASK:u32>(x:X)->(X::Pass, X::Fail)
where X:Collate<MASK> {
x.collate()
}
fn main() {
dbg!(collate::<_,3>((4, ('!',()))));
}
Metadata
Metadata
Assignees
Labels
Category: This is a bug.Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example`#![feature(generic_const_exprs)]`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Relevant to the compiler team, which will review and decide on the PR/issue.ICE tracked in rust-lang/glacier.This issue requires a nightly compiler in some way.