1.56 nightly change in const_evaluatable_checked?

having a struct field depending on an a const expression (field: [T; N * 2]) using const_evaluatable_checked and a corresponding where [T; N * 2]: Sized. Think this was working before 1.56 nightly.. Getting called Option::unwrap() on a None value, compiler/rustc_metadata/src/rmeta/decoder.rs:914:54 when importing lib.rs, but, everything works when that same lib is in main.rs. Also any suggestions for using const_evaluatable_checked

Could you make an example of broken code in the playground? This should be reported as bug, but it's impossible to do anything without reproduction.

Thanks for the response! Is there a way to do a lib there? The single file does pass run

Can paste a playground where it works, but, it is just as above: a struct field depending on an a const expression (field: [T; N * 2]) using const_evaluatable_checked and a corresponding where [T; N * 2]: Sized.

Well, not through ordinary ways, but there is a trick.

1 Like

This does not work. Is there perhaps other way with importing an external module?

To clarify, importing works, but it does not help provide example for your inquiry

Can you provide a minimal reproducible example?

Const generics aren't related to modules or the file system, so you should be able to copy just the bits that are relevant into the playground.

Perhaps providing the above as follows may help:

pub struct S<T: Copy + Default, const N: usize>
where
    [T; N*2: Sized,
{
    s: [T;N*2],
}

The following runs, including in playground:

#![feature(const_generics)]
#![feature(const_evaluatable_checked)]

pub struct S<T: Copy + Default, const N: usize>
where
    [T; N*2]: Sized,
{
    pub s: [T; N * 2],
}

impl<T: Default + Copy, const N: usize> S<T, N>
where
    [T; N * 2]: Sized,
{
    pub fn test() -> Self {
        S {
            s: [T::default(); N * 2],
        }
    }
}

When importing and running though

const N: usize = 2;
let x: S<u8, N> = S::test();

then as described.

Is there perhaps a better place to ask this?

It might be useful to file a bug report on the Rust repository.

1 Like

Okay

2 Likes

encode `generics_of` for fields and ty params by BoxyUwU · Pull Request #87815 · rust-lang/rust · GitHub! Before closing does anyone know how to try this (how does PR get into nightly or should compile from src)?

This will be in nightly in the next day or so.

Sounds good, thank you!