Stream: general

Topic: PhantomConst


Jake Goulding (Jun 03 2019 at 21:36, on Zulip):

Will there be a PhantomData equivalent for const generics?

centril (Jun 03 2019 at 21:45, on Zulip):

The current plan is that it won't be required

centril (Jun 03 2019 at 21:45, on Zulip):

since there's no variance etc. to deal with

Jake Goulding (Jun 04 2019 at 11:57, on Zulip):

I wanted to make a

struct FakeArray<T, const N: usize>(T);

What would be the way to do so?

yodal (Jun 04 2019 at 12:02, on Zulip):

That there should work

Jake Goulding (Jun 04 2019 at 12:03, on Zulip):

hm; did I not even try it?

Jake Goulding (Jun 04 2019 at 12:03, on Zulip):

:face_palm:

Jake Goulding (Jun 04 2019 at 12:04, on Zulip):

Thank you @yodal

Jake Goulding (Jun 04 2019 at 12:04, on Zulip):

I'm just so used to needing to make use of the parameters

Jake Goulding (Jun 04 2019 at 12:09, on Zulip):

@yodal should I file this?

#![feature(const_generics)]

struct FakeArray<T, const N: usize>(T);

impl<T, const N: usize> FakeArray<T, { N }> {
    fn len(&self) -> usize {
        N
    }
}

fn main() {
    let fa = FakeArray::<{ 32 }>(1);
    println!("{}", fa.len());
}
error: internal compiler error: src/librustc/infer/canonical/canonicalizer.rs:553: failed to lift `QueryResponse { var_values: CanonicalVarValues { var_values: [^0, Const { ty: _, val: Infer(Canonical(DebruijnIndex(0), 1)) }] }, region_constraints: [], certainty: Proven, value: FakeArray<^0, _: _> }`, canonicalized from `QueryResponse { var_values: CanonicalVarValues { var_values: [{integer}, Const { ty: _, val: Infer(Var(_#0c)) }] }, region_constraints: [], certainty: Proven, value: FakeArray<{integer}, _: _> }`

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:637:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to previous error

I found https://github.com/rust-lang/rust/issues/60879 but it's been closed and this still repros

yodal (Jun 04 2019 at 12:16, on Zulip):

Interesting, I tested that one myself and @varkor added a regression test so it shouldn't repro on the latest

yodal (Jun 04 2019 at 12:22, on Zulip):

Could you submit an issue? Yours creates an error while the code in that issue doesn't.

Jake Goulding (Jun 04 2019 at 12:22, on Zulip):

Sure can!

yodal (Jun 04 2019 at 12:22, on Zulip):

At any rate, if not for that ICE, that code should work just fine

yodal (Jun 04 2019 at 12:27, on Zulip):

Ah, I see what is triggering it. Your code has an explicit const param in the initializer while there code infers it

Last update: Nov 21 2019 at 23:45UTC