From 2c85db8eb6bac4a9106e7373840c0b3d209188a6 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 26 Nov 2020 16:56:22 +0100 Subject: Implement `Display` for macro expansion errors --- crates/tt/src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'crates/tt') diff --git a/crates/tt/src/lib.rs b/crates/tt/src/lib.rs index 20c3f5eab..7c796f564 100644 --- a/crates/tt/src/lib.rs +++ b/crates/tt/src/lib.rs @@ -240,6 +240,17 @@ pub enum ExpansionError { ExpansionError(String), } +impl fmt::Display for ExpansionError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ExpansionError::IOError(e) => write!(f, "I/O error: {}", e), + ExpansionError::JsonError(e) => write!(f, "JSON decoding error: {}", e), + ExpansionError::Unknown(e) => write!(f, "{}", e), + ExpansionError::ExpansionError(e) => write!(f, "proc macro returned error: {}", e), + } + } +} + pub trait TokenExpander: Debug + Send + Sync + RefUnwindSafe { fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>) -> Result; -- cgit v1.2.3