Skip to content

[ER] Suboptimal error message in a case of min_const_generics inference failure #79557

Closed
@leonardo-m

Description

@leonardo-m

This code:

#![feature(min_const_generics)]
fn foo<const N: usize, const K: usize>(data: [u32; N]) -> [u32; K] {
    [0; K]
}
fn main() {
    let a = foo::<_, 2>([0, 1, 2]);
}

Gives (with rustc 1.50.0-nightly 349b3b3 2020-11-29):

error[E0747]: type provided when a constant was expected
 --> ...\test.rs:6:19
  |
6 |     let a = foo::<_, 2>([0, 1, 2]);
  |                   ^

Two problems:

  1. In the code I've used the underscore hoping rustc to infer the value of N, but for some reason it failed.
  2. Beside the type inference failure, the error message is not the best possible. I didn't provide a type. A better error message could say "unable to infer the const argument N, please specify".

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions