Skip to content

error using Vec::<dyn Any>::new() in a const fn #84170

Open
@droundy

Description

@droundy

I tried this code:

const fn newv() -> Vec<Box<dyn std::any::Any>> {
    Vec::new()
}

(Playground link)

I expected this to compile, since Vec::new() is a const function, and no dyn anything needs to be created.

Instead, this happened:

Compiling playground v0.0.1 (/playground)
error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable
 --> src/lib.rs:1:20
  |
1 | const fn newv() -> Vec<Box<dyn std::any::Any>> {
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
  = help: add `#![feature(const_fn)]` to the crate attributes to enable

Meta

rustc --version --verbose:

1.51.0 on the playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions