Move Error
trait into core #3
Description
EDIT: Current Status Update
Building upon these prior issues:
- Tracking issue for RFC 2504, "Fix the Error trait" rust#53487
- Stabilize the backtrace feature. rust#72981
From this comment Backtrace
stabilization is currently blocked on prototyping one or more of the suggested solutions for moving the std::error::Error
trait into core
That comment suggests three possible solutions.
1. Remove `backtrace` from `Error` and instead provide it via some generic context mechanism (RFC 2895). 2. Define a `Backtrace` trait in core and have an implementation of that trait in libstd. `Error::backtrace` would then return a `&dyn Backtrace`. 3. Define `Backtrace` in core but have it dispatch via an internal vtable. This is effectively the same as 2 but the trait is hidden. The `capture` method will have to be moved to a free function in libstd.
Option one is already known to work, and so it does not need to be prototyped. In addition to these backtrace related issues a prototype of the error trait in core
will need to find a way to work around pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn Error>>
since Box
won't be available in core
. The top level comment in @withoutboats's stabilization PR goes into more detail on this second issue and outlines how a new core::error::Error
implementation could use hooks that are defined in std
, similar to panic hooks, to work solve the issues around Box
.
Boats has already raised issues about option two in this comment so I think the best way forward is to start working on a core::error::Error
trait and core::backtrace::Backtrace
type that both rely on hooks / manual vtables to maintain backwards compatibility with the existing error trait.