Improve Debug representations
diff --git a/src/stable.rs b/src/stable.rs
index ad9870c..1ca48a5 100644
--- a/src/stable.rs
+++ b/src/stable.rs
@@ -16,7 +16,7 @@
use {Delimiter, Group, Op, Spacing, TokenTree};
-#[derive(Clone, Debug)]
+#[derive(Clone)]
pub struct TokenStream {
inner: Vec<TokenTree>,
}
@@ -111,6 +111,13 @@
}
}
+impl fmt::Debug for TokenStream {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ f.write_str("TokenStream ")?;
+ f.debug_list().entries(self.clone()).finish()
+ }
+}
+
#[cfg(feature = "proc-macro")]
impl From<::proc_macro::TokenStream> for TokenStream {
fn from(inner: ::proc_macro::TokenStream) -> TokenStream {
@@ -314,7 +321,7 @@
}
}
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+#[derive(Clone, Copy, PartialEq, Eq)]
pub struct Span {
#[cfg(procmacro2_semver_exempt)]
lo: u32,
@@ -393,6 +400,16 @@
}
}
+impl fmt::Debug for Span {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ #[cfg(procmacro2_semver_exempt)]
+ return write!(f, "bytes({}..{})", self.lo, self.hi);
+
+ #[cfg(not(procmacro2_semver_exempt))]
+ write!(f, "Span")
+ }
+}
+
#[derive(Copy, Clone)]
pub struct Term {
intern: usize,
@@ -466,7 +483,11 @@
impl fmt::Debug for Term {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- f.debug_tuple("Term").field(&self.as_str()).finish()
+ let mut debug = f.debug_struct("Term");
+ debug.field("sym", &format_args!("{}", self.as_str()));
+ #[cfg(procmacro2_semver_exempt)]
+ debug.field("span", &self.span);
+ debug.finish()
}
}
@@ -508,7 +529,7 @@
}
}
-#[derive(Clone, Debug)]
+#[derive(Clone)]
pub struct Literal {
text: String,
span: Span,
@@ -629,6 +650,16 @@
}
}
+impl fmt::Debug for Literal {
+ fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
+ let mut debug = fmt.debug_struct("Literal");
+ debug.field("lit", &format_args!("{}", self.text));
+ #[cfg(procmacro2_semver_exempt)]
+ debug.field("span", &self.span);
+ debug.finish()
+ }
+}
+
fn token_stream(mut input: Cursor) -> PResult<::TokenStream> {
let mut trees = Vec::new();
loop {