Open
Description
Ideally, rustc
should guide the user towards producing const generics code, even if they forget the const
, the type, or both.
Given the following code:
// forgot type
impl<T, const N> From<[T; N]> for VecWrapper<T>
where
T: Clone,
{
fn from(slice: [T; N]) -> Self {
VecWrapper(slice.to_vec())
}
}
(All examples are in https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4a11f9dad9f8069e70f2aea6cb4084ad )
The current output is:
error: expected `:`, found `>`
--> src/lib.rs:25:16
|
25 | impl<T, const N> From<[T; N]> for VecWrapper<T>
| ^ expected `:`
Ideally the output should look like:
- expected
: Type
- maybe a hint for the
usize
type, because that's the type ofN
in[T; N]
Similarly:
// Forgot const
impl<T, N: usize> From<[T; N]> for VecWrapper<T>
where
T: Clone,
{
fn from(slice: [T; N]) -> Self {
VecWrapper(slice.to_vec())
}
}
Produces:
error[E0423]: expected value, found type parameter `N`
--> src/lib.rs:15:28
|
15 | impl<T, N: usize> From<[T; N]> for VecWrapper<T>
| ^ not a value
error[E0404]: expected trait, found builtin type `usize`
--> src/lib.rs:15:12
|
15 | impl<T, N: usize> From<[T; N]> for VecWrapper<T>
| ^^^^^ not a trait
error[E0423]: expected value, found type parameter `N`
--> src/lib.rs:19:24
|
19 | fn from(slice: [T; N]) -> Self {
| ^ not a value
Ideally the output should look like:
- expected
const
with a hint
And:
// forgot const and type
impl<T, N> From<[T; N]> for VecWrapper<T>
where
T: Clone,
{
fn from(slice: [T; N]) -> Self {
VecWrapper(slice.to_vec())
}
}
Produces:
error[E0423]: expected value, found type parameter `N`
--> src/lib.rs:25:21
|
25 | impl<T, N> From<[T; N]> for VecWrapper<T>
| ^ not a value
error[E0423]: expected value, found type parameter `N`
--> src/lib.rs:29:24
|
29 | fn from(slice: [T; N]) -> Self {
| ^ not a value
Ideally the output should look like:
- expected
const N: Type
- maybe a hint for the
usize
type, because that's the type ofN
in[T; N]
$ rustc --version
rustc 1.53.0-nightly (392ba2ba1 2021-04-17)
Metadata
Metadata
Assignees
Labels
Area: const generics (parameters and arguments)Area: Messages for errors, warnings, and lintsArea: The lexing & parsing of Rust source code to an ASTDiagnostics: Confusing error or lint; hard to understand for new users.Relevant to the compiler team, which will review and decide on the PR/issue.An error is correctly emitted, but is confusing, for `min_const_generics`.