Closed
Description
Because trait objects are never Sized
, a method marked where Self: Sized
does not have to be implemented on an unsized type (although that’s not currently the case in manual impls due to #20021), so the automatic impl Trait for Trait
should also not have to implement the method (and thus should be ignored during object safety checks).
Example:
trait Foo {
fn foo(&self);
fn bar<T>(self, x: T) where Self: Sized;
}
impl Foo for () {
fn foo(&self) {}
fn bar<T>(self, x: T) {}
}
fn main() {
let x = &() as &Foo; // error: cannot convert to a trait object because trait `Foo` is
// not object-safe
// Because the automatic impl of `Foo` for `Foo` should not have to implement `bar`,
// `bar` should not be considered during object safety checks
}
I’m not very sure if a change like this would require an amendment to the object safety RFC or not, and thus whether this issue belongs in rust-lang/rfcs or here. I’m treating this as a bug because it seems to me that trait Foo
is in fact object safe, whereas the compiler says otherwise.