Skip to content

linker error with feature(generic_const_exprs) #82268

@e2-71828

Description

@e2-71828

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, ('!',()))));
}

(Playground)

Activity

added
C-bugCategory: This is a bug.
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.
on Feb 18, 2021
e2-71828

e2-71828 commented on Feb 19, 2021

@e2-71828
Author

This appears to be related to using a const generic as a trait parameter. A couple of variants I've tried:

  • Wrapping the parameter in a struct still errors: (Playground)
  • But extracting the const computations into a separate trait compiles: (Playground)
added a commit that references this issue on Feb 20, 2021
JohnTitor

JohnTitor commented on Apr 26, 2021

@JohnTitor
Member

Triage: The original ICE has been fixed in the latest nightly but the following examples (#82268 (comment)) return a linker error for me. cc #84299 and @lcnr

changed the title [-]ICE with `#![feature(const_evaluatable_checked)]`[/-] [+]linker error with `feature(generic_const_exprs)`[/+] on Jun 24, 2022
lcnr

lcnr commented on Jun 24, 2022

@lcnr
Contributor

we still get a linker error for

#![feature(generic_const_exprs)]

trait Collate<Op> {
    type Pass;
    type Fail;

    fn collate(self) -> (Self::Pass, Self::Fail);
}

impl<Op> Collate<Op> 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 () {
    type Pass = (X, P);
    type Fail = F;

    fn collate_step(x: X, (p, f): (P, F)) -> ((X, P), F) {
        ((x, p), f)
    }
}

struct CollateOpImpl<const MASK: u32>;
trait CollateOpStep {
    type NextOp;
    type Apply;
}

impl<const MASK: u32> CollateOpStep for CollateOpImpl<MASK>
where
    CollateOpImpl<{ MASK >> 1 }>: Sized,
{
    type NextOp = CollateOpImpl<{ MASK >> 1 }>;
    type Apply = ();
}

impl<H, T, Op: CollateOpStep> Collate<Op> for (H, T)
where
    T: Collate<Op::NextOp>,
    Op::Apply: CollateStep<H, (T::Pass, T::Fail)>,
{
    type Pass = <Op::Apply as CollateStep<H, (T::Pass, T::Fail)>>::Pass;
    type Fail = <Op::Apply as CollateStep<H, (T::Pass, T::Fail)>>::Fail;

    fn collate(self) -> (Self::Pass, Self::Fail) {
        <Op::Apply 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<CollateOpImpl<MASK>>,
{
    x.collate()
}

fn main() {
    dbg!(collate::<_, 5>(("Hello", (42, ('!', ())))));
}

Would be great to get a more minimal example for this.

added
E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
on Jun 24, 2022
added a commit that references this issue on Aug 11, 2022
aeb5067
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleF-generic_const_exprs`#![feature(generic_const_exprs)]`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

      Participants

      @jonas-schievink@JohnTitor@e2-71828@lcnr@rust-lang-glacier-bot

      Issue actions

        linker error with `feature(generic_const_exprs)` · Issue #82268 · rust-lang/rust