Skip to content

Support _ for const inference with const generics #80528

Open
@varkor

Description

@varkor

Currently, users may specify _ in place of a type: the compiler will then suggest the intended type. This ought to work for consts too, but currently does not (see #79557).

fn foo<const N: usize, const K: usize>(data: [u32; N]) -> [u32; K] {
    [0; K]
}

fn main() {
    let a = foo::<_, 2>([0, 1, 2]);
}

The difficulty is that the intended use of _ (as either a type or const) is ambiguous until type checking, so runs into the same problems as #66615 and #77773.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions