Why a method marked `where Self: Sized` on a trait should not be considered during object safety checks

Pls explain it with a little example

If you have a bound on the method of a trait, and an implementer of the trait does not meet that bound, the method does not exist for that type. But the trait can still be implemented: playground example.

dyn Trait aka trait objects are dynamically sized types (DSTs). This means that they don't implement the Sized trait (which is why they are generally behind some kind of pointer like &dyn Trait or Box<dyn Trait>).

Since the method doesn't exist for types that are not Sized, and this includes dyn Trait, the method need note be considered as part of the object safety checks.

Corollary: You can't use those methods from your dyn Trait, though.

1 Like