Closed
Description
I have tried two level type inference from vector literal and got totally unhelpful E0308. While I would expect this to work, I file this report due to unhelpfulness of the error.
I expected vec2 alocation to succeed or complain about inability to to coerce types.
Actual error:
src\main.rs:14:25: 14:26 error: mismatched types [E0308]
src\main.rs:14 let vec2 = Baz(vec![1, 2, 3]);
^
src\main.rs:14:20: 14:33 note: in this expansion of vec! (defined in <std macros>)
src\main.rs:14:25: 14:26 help: run `rustc --explain E0308` to see a detailed explanation
src\main.rs:14:25: 14:26 note: expected type `_`
src\main.rs:14:25: 14:26 note: found type `_`
<std macros>:3:25: 3:46 error: mismatched types [E0308]
<std macros>:3 < [ _ ] > :: into_vec ( box [ $ ( $ x ) , * ] ) ) ; ( $ ( $ x : expr , ) * )
^~~~~~~~~~~~~~~~~~~~~
src\main.rs:14:20: 14:33 note: in this expansion of vec! (defined in <std macros>)
<std macros>:3:25: 3:46 help: run `rustc --explain E0308` to see a detailed explanation
<std macros>:3:25: 3:46 note: expected type `Box<[Foo]>`
<std macros>:3:25: 3:46 note: found type `Box<[_; 3]>`
error: aborting due to 2 previous errors
error: Could not compile `s1c1`.
To learn more, run the command again with --verbose.
"cargo build" completed with code 101
It took approximately 0.379 seconds
Code sample
#[derive(Debug)]
struct Foo(u8);
#[derive(Debug)]
struct Bar(Vec<u8>);
#[derive(Debug)]
struct Baz(Vec<Foo>);
fn main() {
let vec1 = Bar(vec!(1, 2, 3));
println!("{:?}", vec1);
let vec2 = Baz(vec!(1, 2, 3)); // Offending line
println!("{:?}", vec2);
let vec3 = Baz(vec!(Foo(1), Foo(2), Foo(3)));
println!("{:?}", vec3);
}
Meta
rustc --version --verbose
rustc 1.11.0 (9b21dcd 2016-08-15)
binary: rustc
commit-hash: 9b21dcd
commit-date: 2016-08-15
host: x86_64-pc-windows-gnu
release: 1.11.0