Error code E0375

CoerceUnsized or DispatchFromDyn was implemented on a struct which contains more than one field that is being unsized.

Erroneous code example:

#![allow(unused)] #![feature(coerce_unsized)] fn main() { use std::ops::CoerceUnsized; struct Foo<T: ?Sized, U: ?Sized> { a: i32, b: T, c: U, } // error: Struct `Foo` has more than one unsized field. impl<T, U> CoerceUnsized<Foo<U, T>> for Foo<T, 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 has multiple fields that must be unsized, then the compiler has no way to generate a valid implementation of CoerceUnsized or DispatchFromDyn.

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.