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:
Brooks J Rady 2024-04-25 15:42:13 -07:00
parent b087000b7e
commit c4f643126f
1 changed files with 4 additions and 13 deletions

View File

@ -533,7 +533,8 @@ where
E: Diagnostic + Send + Sync + 'static,
{
// 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>.
@ -544,7 +545,8 @@ where
E: StdError + Send + Sync + 'static,
{
// 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>.
@ -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>
where
E: Debug,