Closed
Description
rustc gives confusing error, suggesting that I give b an explicit type when b already has an explicit type.
Replacing 0u16.foo(b)
with <u16 as Foo<[(); 3]>>::foo(0u16, b)
fixes it.
This may be a duplicate of #69123
Source
pub trait Element<S> {
type Array;
}
impl<T> Element<()> for T {
type Array = T;
}
impl<T: Element<S>, S> Element<[S; 3]> for T {
type Array = [T::Array; 3];
}
trait Foo<I>
where
u8: Element<I>,
{
fn foo(self, x: <u8 as Element<I>>::Array);
}
impl<I> Foo<I> for u16
where
u8: Element<I>,
{
fn foo(self, _: <u8 as Element<I>>::Array) {}
}
fn main() {
let b: [u8; 3] = [0u8; 3];
0u16.foo(b);
//<u16 as Foo<[(); 3]>>::foo(0u16, b);
}
Log
$ rustc src/bin/type_param_demo.rs
error[E0284]: type annotations needed for `[u8; 3]`
--> src/bin/type_param_demo.rs:30:10
|
28 | let b: [u8; 3] = [0u8; 3];
| - consider giving `b` the explicit type `[u8; 3]`, where the type parameter `u8` is specified
29 |
30 | 0u16.foo(b);
| ^^^ cannot infer type for type `u8`
|
= note: cannot resolve `<u8 as Element<_>>::Array == [u8; 3]`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0284`.
Meta
Same issue occurs in both latest and nightly and stable.
$ rustc --version --verbose
rustc 1.43.0-nightly (18c275b42 2020-03-02)
binary: rustc
commit-hash: 18c275b423f9f13c0e404ae3804967d2ab66337c
commit-date: 2020-03-02
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0
$ rustc --version --verbose
rustc 1.41.1 (f3e1a954d 2020-02-24)
binary: rustc
commit-hash: f3e1a954d2ead4e2fc197c7da7d71e6c61bad196
commit-date: 2020-02-24
host: x86_64-unknown-linux-gnu
release: 1.41.1
LLVM version: 9.0
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsCategory: An issue proposing an enhancement or a PR with one.Diagnostics: Confusing error or lint that should be reworked.Diagnostics: A structured suggestion resulting in incorrect code.Relevant to the compiler team, which will review and decide on the PR/issue.