From 3aca69751181944dd23ef65c1a0af5d5f3b7208f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Thu, 26 Nov 2020 20:56:38 +0200 Subject: Simplify error formatting --- crates/mbe/src/lib.rs | 2 +- crates/tt/src/lib.rs | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs index 844e5a117..2d0763c47 100644 --- a/crates/mbe/src/lib.rs +++ b/crates/mbe/src/lib.rs @@ -52,7 +52,7 @@ impl fmt::Display for ExpandError { ExpandError::BindingError(e) => f.write_str(e), ExpandError::ConversionError => f.write_str("could not convert tokens"), ExpandError::InvalidRepeat => f.write_str("invalid repeat expression"), - ExpandError::ProcMacroError(e) => write!(f, "{}", e), + ExpandError::ProcMacroError(e) => e.fmt(f), ExpandError::Other(e) => f.write_str(e), } } diff --git a/crates/tt/src/lib.rs b/crates/tt/src/lib.rs index 7c796f564..6c1bf8d09 100644 --- a/crates/tt/src/lib.rs +++ b/crates/tt/src/lib.rs @@ -1,10 +1,7 @@ //! `tt` crate defines a `TokenTree` data structure: this is the interface (both //! input and output) of macros. It closely mirrors `proc_macro` crate's //! `TokenTree`. -use std::{ - fmt::{self, Debug}, - panic::RefUnwindSafe, -}; +use std::{fmt, panic::RefUnwindSafe}; use stdx::impl_from; @@ -139,7 +136,7 @@ fn print_debug_token(f: &mut fmt::Formatter<'_>, tkn: &TokenTree, level: usize) Ok(()) } -impl Debug for Subtree { +impl fmt::Debug for Subtree { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { print_debug_subtree(f, self, 0) } @@ -245,13 +242,13 @@ impl fmt::Display for ExpansionError { 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::Unknown(e) => e.fmt(f), ExpansionError::ExpansionError(e) => write!(f, "proc macro returned error: {}", e), } } } -pub trait TokenExpander: Debug + Send + Sync + RefUnwindSafe { +pub trait TokenExpander: fmt::Debug + Send + Sync + RefUnwindSafe { fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>) -> Result; } -- cgit v1.2.3