Confusing error message with boxed unsized types
struct Foo<Sized? T>;
impl<Sized? T> Foo<T> {
fn frob(self, bar: Box<T>) {}
}
fn main() {
let foo: Foo<Num> = Foo;
foo.frob(box 1i as Box<Num>);
}
yields the error
dstbug.rs:9:14: 9:32 error: mismatched types: expected `Box<core::num::Num>`, found `Box<core::num::Num>` (expected box, found box)
dstbug.rs:9 foo.frob(box 1i as Box<Num>);
^~~~~~~~~~~~~~~~~~
error: aborting due to previous error
cc @nick29581
Hmm, this shouldn't be an error at all, let alone a confusing one. I expect this is due to us not unifying unsized types with an inference variable. I would expect a trait to unify to itself though. I'll have a poke around with this.
Nick Cameron at 2014-09-09 21:11:32
See also #16918 which has a related problem with unifying unsized type variables
Nick Cameron at 2014-09-09 22:34:35
Hmm. #17178 has been closed, but this still isn’t fixed, so perhaps it’s not related to unifying unsized types in type inference. An interesting thing is that the error message (
expected box, found box) seems to suggest that it’s not the traits that differ, but the box: replacingas Box<Num>withas Box<Float>gives a message that correctly states that the traits differ.Rewi Haar at 2014-10-28 06:31:34
The example builds for me with the latest master.
Brian Koropoff at 2014-10-28 07:38:13
Ah, it does too. It looks like the playpen is running a very outdated version of rustc…
I guess this is fixed, then! Closing.
Rewi Haar at 2014-10-28 07:50:31