-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Given the following code:
fn foo<const N: usize>(_: impl std::fmt::Display) -> [usize; N] {
[0; N]
}
fn main() {
let f = foo("foo");
}
The current output is:
error[E0282]: type annotations needed for `[usize; _]`
--> src/main.rs:6:13
|
6 | let f = foo("foo");
| - ^^^ cannot infer the value of const parameter `N` declared on the function `foo`
| |
| consider giving `f` the explicit type `[usize; _]`, where the type parameter `N` is specified
|
help: consider specifying the const argument
|
6 | let f = foo::<N>("foo");
| ^^^^^^^^
The first half is correct, but the problem is that final suggestion. If you try it:
fn foo<const N: usize>(_: impl std::fmt::Display) -> [usize; N] {
[0; N]
}
fn main() {
let f = foo::<2>("foo");
}
you get another error because the suggestion can't work because of the impl std::fmt::Display
:
error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position
--> src/main.rs:6:19
|
6 | let f = foo::<2>("foo");
| ^ explicit generic argument not allowed
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.