Trait bounds in const fn?

I'm getting an error regarding trait bounds when attempting to create a Vec in a const fn, and don't understand the error. Playground link

struct V(Vec<Box<dyn std::any::Any>>);

const fn newv() -> V {

Any idea why this is happening? I'm pretty sure Vec::new is a const function, and I don't see why the type it is holding should make a difference.

This seems like a bug, I would definitely expect this to compile (or at the very least, give an error message that makes sense). Please file an issue if you can.

error[E0723]: trait bounds other than Sized on const fn parameters are unstable

I believe this is due to the desugaring of Box<dyn std::any::Any>, but I may be wrong. You can get around this on nightly by enabling #![feature(const_fn)].

Playground link

Same error with Rc. I think that the Trait in dyn Trait is the bound in question.

const fn newv() -> &'static dyn std::any::Any {


1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.