From bbd71146b4b8f7a14f6ac131b981d76f3dae5a5e Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 8 Dec 2018 12:55:31 -0700 Subject: [PATCH] fix(error): Simplify by removing cloning Most people don't support cloning, so eh. BREAKING CHANGE: Error is now not cloneable --- liquid-error/src/clone.rs | 40 --------------------------------------- liquid-error/src/error.rs | 12 ++++++------ liquid-error/src/lib.rs | 2 -- liquid-value/src/ser.rs | 2 +- 4 files changed, 7 insertions(+), 49 deletions(-) delete mode 100644 liquid-error/src/clone.rs diff --git a/liquid-error/src/clone.rs b/liquid-error/src/clone.rs deleted file mode 100644 index c786b698e..000000000 --- a/liquid-error/src/clone.rs +++ /dev/null @@ -1,40 +0,0 @@ -use std::error; -use std::fmt; - -#[derive(Debug)] -pub(crate) enum ClonableError { - Original(BoxedError), - Missing, -} - -pub(crate) type BoxedError = Box; - -impl ClonableError { - pub(crate) fn new(error: BoxedError) -> Self { - ClonableError::Original(error) - } - - pub(crate) fn cause(&self) -> Option<&error::Error> { - match *self { - ClonableError::Original(ref e) => Some(e.as_ref()), - _ => None, - } - } -} - -impl Clone for ClonableError { - fn clone(&self) -> Self { - match *self { - ClonableError::Original(_) | ClonableError::Missing => ClonableError::Missing, - } - } -} - -impl fmt::Display for ClonableError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - ClonableError::Original(ref e) => fmt::Display::fmt(e, f), - ClonableError::Missing => write!(f, "Unknown error"), - } - } -} diff --git a/liquid-error/src/error.rs b/liquid-error/src/error.rs index a1e59dc7c..d1cbeeab7 100644 --- a/liquid-error/src/error.rs +++ b/liquid-error/src/error.rs @@ -3,15 +3,15 @@ use std::error; use std::fmt; use std::result; -use super::ClonableError; -use super::BoxedError; use super::Trace; /// Convenience type alias for Liquid compiler errors pub type Result = result::Result; +type BoxedError = Box; + /// Compiler error -#[derive(Clone, Debug)] +#[derive(Debug)] pub struct Error { inner: Box, } @@ -20,11 +20,11 @@ pub struct Error { // `Result` in the success case and spilling over from register-based returns to stack-based // returns. There are already enough memory allocations below, one more // shouldn't hurt. -#[derive(Clone, Debug)] +#[derive(Debug)] struct InnerError { msg: borrow::Cow<'static, str>, user_backtrace: Vec, - cause: Option, + cause: Option, } impl Error { @@ -89,7 +89,7 @@ impl Error { } fn cause_error(mut self, cause: BoxedError) -> Self { - let cause = Some(ClonableError::new(cause)); + let cause = Some(cause); self.inner.cause = cause; self } diff --git a/liquid-error/src/lib.rs b/liquid-error/src/lib.rs index e2cdf0d23..4ccf1ae8c 100644 --- a/liquid-error/src/lib.rs +++ b/liquid-error/src/lib.rs @@ -4,12 +4,10 @@ #![warn(missing_debug_implementations)] #![warn(unused_extern_crates)] -mod clone; mod error; mod trace; mod result_ext; pub use error::*; pub use result_ext::*; -use clone::*; use trace::*; diff --git a/liquid-value/src/ser.rs b/liquid-value/src/ser.rs index 9e77991a9..06ea07322 100644 --- a/liquid-value/src/ser.rs +++ b/liquid-value/src/ser.rs @@ -24,7 +24,7 @@ where value.serialize(Serializer).map_err(|e| e.0) } -#[derive(Clone, Debug)] +#[derive(Debug)] struct SerError(error::Error); impl fmt::Display for SerError {