aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-11-26 19:18:40 +0000
committerGitHub <[email protected]>2020-11-26 19:18:40 +0000
commit38d595c36fda9dc62c78c860421144999612e64c (patch)
treedb722333cb69519e4493546a41dc47e774b8b15c /crates
parentdeb3550fea718e52cd03e7d14fd964d14795a31d (diff)
parent3aca69751181944dd23ef65c1a0af5d5f3b7208f (diff)
Merge #6644
6644: Simplify error formatting r=lnicola a=lnicola CC jonas-schievink bors r+ Co-authored-by: LaurenČ›iu Nicola <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/mbe/src/lib.rs2
-rw-r--r--crates/tt/src/lib.rs11
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 {
52 ExpandError::BindingError(e) => f.write_str(e), 52 ExpandError::BindingError(e) => f.write_str(e),
53 ExpandError::ConversionError => f.write_str("could not convert tokens"), 53 ExpandError::ConversionError => f.write_str("could not convert tokens"),
54 ExpandError::InvalidRepeat => f.write_str("invalid repeat expression"), 54 ExpandError::InvalidRepeat => f.write_str("invalid repeat expression"),
55 ExpandError::ProcMacroError(e) => write!(f, "{}", e), 55 ExpandError::ProcMacroError(e) => e.fmt(f),
56 ExpandError::Other(e) => f.write_str(e), 56 ExpandError::Other(e) => f.write_str(e),
57 } 57 }
58 } 58 }
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 @@
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`.
4use std::{ 4use std::{fmt, panic::RefUnwindSafe};
5 fmt::{self, Debug},
6 panic::RefUnwindSafe,
7};
8 5
9use stdx::impl_from; 6use 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
142impl Debug for Subtree { 139impl 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 }
@@ -245,13 +242,13 @@ impl fmt::Display for ExpansionError {
245 match self { 242 match self {
246 ExpansionError::IOError(e) => write!(f, "I/O error: {}", e), 243 ExpansionError::IOError(e) => write!(f, "I/O error: {}", e),
247 ExpansionError::JsonError(e) => write!(f, "JSON decoding error: {}", e), 244 ExpansionError::JsonError(e) => write!(f, "JSON decoding error: {}", e),
248 ExpansionError::Unknown(e) => write!(f, "{}", e), 245 ExpansionError::Unknown(e) => e.fmt(f),
249 ExpansionError::ExpansionError(e) => write!(f, "proc macro returned error: {}", e), 246 ExpansionError::ExpansionError(e) => write!(f, "proc macro returned error: {}", e),
250 } 247 }
251 } 248 }
252} 249}
253 250
254pub trait TokenExpander: Debug + Send + Sync + RefUnwindSafe { 251pub trait TokenExpander: fmt::Debug + Send + Sync + RefUnwindSafe {
255 fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>) 252 fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>)
256 -> Result<Subtree, ExpansionError>; 253 -> Result<Subtree, ExpansionError>;
257} 254}