mirror of https://github.com/zkat/miette.git
fix(report): conversion into `Box<dyn Diagnostic>`
Diagnostic impls are no longer reset to default when converting a `Report` into a `Box<dyn Diagnostic>`. Also prevented `Report` vtables and handlers from being kept around on the heap after conversion.
This commit is contained in:
parent
b087000b7e
commit
c4f643126f
|
|
@ -533,7 +533,8 @@ where
|
||||||
E: Diagnostic + Send + Sync + 'static,
|
E: Diagnostic + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
// Attach ErrorImpl<E>'s native StdError vtable. The StdError impl is below.
|
// Attach ErrorImpl<E>'s native StdError vtable. The StdError impl is below.
|
||||||
e.cast::<ErrorImpl<E>>().boxed()
|
let unerased = e.cast::<ErrorImpl<E>>().boxed();
|
||||||
|
Box::new(unerased._object)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Safety: requires layout of *e to match ErrorImpl<E>.
|
// Safety: requires layout of *e to match ErrorImpl<E>.
|
||||||
|
|
@ -544,7 +545,8 @@ where
|
||||||
E: StdError + Send + Sync + 'static,
|
E: StdError + Send + Sync + 'static,
|
||||||
{
|
{
|
||||||
// Attach ErrorImpl<E>'s native StdError vtable. The StdError impl is below.
|
// Attach ErrorImpl<E>'s native StdError vtable. The StdError impl is below.
|
||||||
e.cast::<ErrorImpl<E>>().boxed()
|
let unerased = e.cast::<ErrorImpl<E>>().boxed();
|
||||||
|
Box::new(unerased._object)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Safety: requires layout of *e to match ErrorImpl<E>.
|
// Safety: requires layout of *e to match ErrorImpl<E>.
|
||||||
|
|
@ -716,17 +718,6 @@ impl ErasedErrorImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E> StdError for ErrorImpl<E>
|
|
||||||
where
|
|
||||||
E: StdError,
|
|
||||||
{
|
|
||||||
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
|
||||||
unsafe { ErrorImpl::diagnostic(self.erase()).source() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E> Diagnostic for ErrorImpl<E> where E: Diagnostic {}
|
|
||||||
|
|
||||||
impl<E> Debug for ErrorImpl<E>
|
impl<E> Debug for ErrorImpl<E>
|
||||||
where
|
where
|
||||||
E: Debug,
|
E: Debug,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue