Error code E0374
CoerceUnsized
or DispatchFromDyn
was implemented on a struct which does not
contain a field that is being unsized.
Example of erroneous code:
ⓘ
CoerceUnsized
is used to coerce structs that have a field that can be unsized,
like a custom MyBox<T>
being unsized to MyBox<dyn Trait>
. DispatchFromDyn
is used to dispatch from MyBox<dyn Trait>
to MyBox<Self>
in a dyn-compatible
trait.
If the struct doesn't have any fields of unsized types then there is no
meaningful way to implement CoerceUnsized
or DispatchFromDyn
, since
there is no coercion taking place.
Note that CoerceUnsized
and DispatchFromDyn
is mainly used by smart pointers
like Box
, Rc
and Arc
to be able to mark that they can coerce unsized types
that they are pointing at.