]> git.lizzy.rs Git - rust.git/commitdiff
Merge #6644
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>
Thu, 26 Nov 2020 19:18:40 +0000 (19:18 +0000)
committerGitHub <noreply@github.com>
Thu, 26 Nov 2020 19:18:40 +0000 (19:18 +0000)
6644: Simplify error formatting r=lnicola a=lnicola

CC jonas-schievink

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
crates/mbe/src/lib.rs
crates/tt/src/lib.rs

index 844e5a117e3da27eb7d9fc01cfb069b472aa41e9..2d0763c4710d9eb21a9bcd843fcb1253a6b9f07d 100644 (file)
@@ -52,7 +52,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
             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),
         }
     }
index 7c796f5645dc6531fb201852c0f3d60c68a891eb..6c1bf8d092765dff65c7852eb64eb981c234a621 100644 (file)
@@ -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 @@ 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::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<Subtree, ExpansionError>;
 }