diff options
Diffstat (limited to 'crates/tt/src/lib.rs')
-rw-r--r-- | crates/tt/src/lib.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/crates/tt/src/lib.rs b/crates/tt/src/lib.rs index 20c3f5eab..6c1bf8d09 100644 --- a/crates/tt/src/lib.rs +++ b/crates/tt/src/lib.rs | |||
@@ -1,10 +1,7 @@ | |||
1 | //! `tt` crate defines a `TokenTree` data structure: this is the interface (both | 1 | //! `tt` crate defines a `TokenTree` data structure: this is the interface (both |
2 | //! input and output) of macros. It closely mirrors `proc_macro` crate's | 2 | //! input and output) of macros. It closely mirrors `proc_macro` crate's |
3 | //! `TokenTree`. | 3 | //! `TokenTree`. |
4 | use std::{ | 4 | use std::{fmt, panic::RefUnwindSafe}; |
5 | fmt::{self, Debug}, | ||
6 | panic::RefUnwindSafe, | ||
7 | }; | ||
8 | 5 | ||
9 | use stdx::impl_from; | 6 | use stdx::impl_from; |
10 | 7 | ||
@@ -139,7 +136,7 @@ fn print_debug_token(f: &mut fmt::Formatter<'_>, tkn: &TokenTree, level: usize) | |||
139 | Ok(()) | 136 | Ok(()) |
140 | } | 137 | } |
141 | 138 | ||
142 | impl Debug for Subtree { | 139 | impl fmt::Debug for Subtree { |
143 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 140 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
144 | print_debug_subtree(f, self, 0) | 141 | print_debug_subtree(f, self, 0) |
145 | } | 142 | } |
@@ -240,7 +237,18 @@ pub enum ExpansionError { | |||
240 | ExpansionError(String), | 237 | ExpansionError(String), |
241 | } | 238 | } |
242 | 239 | ||
243 | pub trait TokenExpander: Debug + Send + Sync + RefUnwindSafe { | 240 | impl fmt::Display for ExpansionError { |
241 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
242 | match self { | ||
243 | ExpansionError::IOError(e) => write!(f, "I/O error: {}", e), | ||
244 | ExpansionError::JsonError(e) => write!(f, "JSON decoding error: {}", e), | ||
245 | ExpansionError::Unknown(e) => e.fmt(f), | ||
246 | ExpansionError::ExpansionError(e) => write!(f, "proc macro returned error: {}", e), | ||
247 | } | ||
248 | } | ||
249 | } | ||
250 | |||
251 | pub trait TokenExpander: fmt::Debug + Send + Sync + RefUnwindSafe { | ||
244 | fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>) | 252 | fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>) |
245 | -> Result<Subtree, ExpansionError>; | 253 | -> Result<Subtree, ExpansionError>; |
246 | } | 254 | } |