Skip to content

Cannot use associated const to specify static array length #52070

Closed
@diwic

Description

@diwic
pub trait Foo {
    const SIZE: usize;
    fn whatever() {
        // compiles fine
        let _x = [Self::SIZE, 3usize];
        // fails with error[E0599]: no associated item named `SIZE` found for type `Self` in the current scope
        let _y = [3usize; Self::SIZE];
    }
}

This looks like a bug to me - I believe both rows should compile just fine.
It exists in both stable and nightly.

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, ...)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions