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 of N 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 of N in [T; N]
$ rustc --version
rustc 1.53.0-nightly (392ba2ba1 2021-04-17)
Ideally,
rustcshould guide the user towards producing const generics code, even if they forget theconst, the type, or both.Given the following code:
(All examples are in https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4a11f9dad9f8069e70f2aea6cb4084ad )
The current output is:
Ideally the output should look like:
: Typeusizetype, because that's the type ofNin[T; N]Similarly:
Produces:
Ideally the output should look like:
constwith a hintAnd:
Produces:
Ideally the output should look like:
const N: Typeusizetype, because that's the type ofNin[T; N]