From c4f643126fbea7cc0d320b3d26695f03e01eaf46 Mon Sep 17 00:00:00 2001 From: Brooks J Rady Date: Thu, 25 Apr 2024 15:42:13 -0700 Subject: [PATCH] fix(report): conversion into `Box` Diagnostic impls are no longer reset to default when converting a `Report` into a `Box`. Also prevented `Report` vtables and handlers from being kept around on the heap after conversion. --- src/eyreish/error.rs | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/eyreish/error.rs b/src/eyreish/error.rs index 677f368..8a5a355 100644 --- a/src/eyreish/error.rs +++ b/src/eyreish/error.rs @@ -533,7 +533,8 @@ where E: Diagnostic + Send + Sync + 'static, { // Attach ErrorImpl's native StdError vtable. The StdError impl is below. - e.cast::>().boxed() + let unerased = e.cast::>().boxed(); + Box::new(unerased._object) } // Safety: requires layout of *e to match ErrorImpl. @@ -544,7 +545,8 @@ where E: StdError + Send + Sync + 'static, { // Attach ErrorImpl's native StdError vtable. The StdError impl is below. - e.cast::>().boxed() + let unerased = e.cast::>().boxed(); + Box::new(unerased._object) } // Safety: requires layout of *e to match ErrorImpl. @@ -716,17 +718,6 @@ impl ErasedErrorImpl { } } -impl StdError for ErrorImpl -where - E: StdError, -{ - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - unsafe { ErrorImpl::diagnostic(self.erase()).source() } - } -} - -impl Diagnostic for ErrorImpl where E: Diagnostic {} - impl Debug for ErrorImpl where E: Debug,