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:

#![allow(unused)] #![feature(coerce_unsized)] fn main() { use std::ops::CoerceUnsized; struct Foo<T: ?Sized> { a: i32, } // error: Struct `Foo` has no unsized fields that need to be coerced. impl<T, U> CoerceUnsized<Foo<U>> for Foo<T> where T: CoerceUnsized<U> {} }

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.