Description
As for today the following blanket implementation exists:
rust/library/alloc/src/boxed.rs
Lines 2443 to 2458 in e702534
The problem with this is that T
is required to be Sized
, so, for example, Box<dyn Error>
doesn't implement Error
. It looks like a straightforward and intuitive assumption that Box<dyn Error>
should implement Error
trait, but it doesn't.
Going even further, there is an inconsistency between the blanket impls for Arc
as well, because there exists an analogous impl for Arc
that has relaxed Sized?
requirement:
rust/library/alloc/src/sync.rs
Lines 2769 to 2788 in e702534
Use Case
The use case where I stumbled with this problem is where I wanted to put Box<dyn Error>
as a source
error in thiserror
error enum, but I couldn't because that type doesn't implement Error trait.
Workarounds
The workaround for this problem is to use Arc<T>
instead of Box<T>
when an Error impl is required for Sized?
type. It's also possible to convert Box<dyn Error>
into an Arc<dyn Error>
via this From
impl.