Closed
Description
Code:
// This fails to compile:
// trait Foo: Sized {
// This compiles successfully
trait Foo where Option<Self>: Sized {
fn some_fn(&self);
}
trait Foo2 where Box<Self>: Sized {
fn some_fn2(&self);
}
struct Bar;
impl Foo for Bar {
fn some_fn(&self) {}
}
impl Foo2 for Bar {
fn some_fn2(&self) {}
}
fn option_sized<T: ?Sized>() where Option<T>: Sized {}
fn box_sized<T: ?Sized>() where Box<T>: Sized {}
fn main() {
let x: Box<Bar> = Box::new(Bar);
let y: Box<Foo> = x;
// This fails to compile
// y.some_fn();
let x2: Box<Bar> = Box::new(Bar);
let y2: Box<Foo2> = x2;
// But this compiles successfully
y2.some_fn2();
// This also fails to compile
// option_sized::<Foo>();
// But this compiles successfully
box_sized::<Foo>();
}
I'm not sure which line is the compiler wrong, but this combination of compile successes/failures is very inconsistent.