Skip to content

Cannot use _ for const arguments #70754

Closed
@jonhoo

Description

@jonhoo

I tried this code:

#![feature(const_generics)]

struct Foo<const N: usize>([(); N]);

fn main() {
    let x: Foo<_> = Foo([]);
}

I only half-expected the code to compile, given where const generics is at (is inference of const generic arguments even intended to eventually work?), but the resulting error was pretty jarring:

error[E0107]: wrong number of const arguments: expected 1, found 0
 --> src/main.rs:6:12
  |
6 |     let x: Foo<_> = Foo([]);
  |            ^^^^^^ expected 1 const argument

error[E0107]: wrong number of type arguments: expected 0, found 1
 --> src/main.rs:6:16
  |
6 |     let x: Foo<_> = Foo([]);
  |                ^ unexpected type argument

Meta

rustc --version --verbose:

1.44.0-nightly (2020-04-02 537ccdf3ac44c8c7a8d3)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)A-inferenceArea: Type inferenceA-parserArea: The lexing & parsing of Rust source code to an ASTA-type-systemArea: Type systemC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language 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