Skip to content

Commit 38d595c

Browse files
bors[bot]lnicola
andauthored
Merge #6644
6644: Simplify error formatting r=lnicola a=lnicola CC jonas-schievink bors r+ Co-authored-by: Laurențiu Nicola <[email protected]>
2 parents deb3550 + 3aca697 commit 38d595c

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

crates/mbe/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl fmt::Display for ExpandError {
5252
ExpandError::BindingError(e) => f.write_str(e),
5353
ExpandError::ConversionError => f.write_str("could not convert tokens"),
5454
ExpandError::InvalidRepeat => f.write_str("invalid repeat expression"),
55-
ExpandError::ProcMacroError(e) => write!(f, "{}", e),
55+
ExpandError::ProcMacroError(e) => e.fmt(f),
5656
ExpandError::Other(e) => f.write_str(e),
5757
}
5858
}

crates/tt/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
//! `tt` crate defines a `TokenTree` data structure: this is the interface (both
22
//! input and output) of macros. It closely mirrors `proc_macro` crate's
33
//! `TokenTree`.
4-
use std::{
5-
fmt::{self, Debug},
6-
panic::RefUnwindSafe,
7-
};
4+
use std::{fmt, panic::RefUnwindSafe};
85

96
use stdx::impl_from;
107

@@ -139,7 +136,7 @@ fn print_debug_token(f: &mut fmt::Formatter<'_>, tkn: &TokenTree, level: usize)
139136
Ok(())
140137
}
141138

142-
impl Debug for Subtree {
139+
impl fmt::Debug for Subtree {
143140
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
144141
print_debug_subtree(f, self, 0)
145142
}
@@ -245,13 +242,13 @@ impl fmt::Display for ExpansionError {
245242
match self {
246243
ExpansionError::IOError(e) => write!(f, "I/O error: {}", e),
247244
ExpansionError::JsonError(e) => write!(f, "JSON decoding error: {}", e),
248-
ExpansionError::Unknown(e) => write!(f, "{}", e),
245+
ExpansionError::Unknown(e) => e.fmt(f),
249246
ExpansionError::ExpansionError(e) => write!(f, "proc macro returned error: {}", e),
250247
}
251248
}
252249
}
253250

254-
pub trait TokenExpander: Debug + Send + Sync + RefUnwindSafe {
251+
pub trait TokenExpander: fmt::Debug + Send + Sync + RefUnwindSafe {
255252
fn expand(&self, subtree: &Subtree, attrs: Option<&Subtree>)
256253
-> Result<Subtree, ExpansionError>;
257254
}

0 commit comments

Comments
 (0)