Skip to content

associated-constants can not be used in constant expressions #34344

Closed
@MaikKlein

Description

@MaikKlein

https://doc.rust-lang.org/book/associated-constants.html

#![feature(associated_consts)]

trait Foo {
    const ID: usize;
}

impl Foo for i32 {
    const ID: usize = 1;
}
fn main() {
    let arr: [i32; i32::ID];
}

https://is.gd/L4Fg4k

array length constant evaluation error: non-constant path in constant expression

I had a quick look at the rfc but I couldn't find out if it should be legal to use associated-constants in constant expressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions