Simplify Debug representation of Ident
diff --git a/src/lib.rs b/src/lib.rs
index 4e5577d..9092569 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -439,7 +439,13 @@
// so don't bother with an extra layer of indirection
match *self {
TokenTree::Group(ref t) => t.fmt(f),
- TokenTree::Ident(ref t) => t.fmt(f),
+ TokenTree::Ident(ref t) => {
+ let mut debug = f.debug_struct("Ident");
+ debug.field("sym", &format_args!("{}", t));
+ #[cfg(any(feature = "nightly", procmacro2_semver_exempt))]
+ debug.field("span", &t.span());
+ debug.finish()
+ }
TokenTree::Punct(ref t) => t.fmt(f),
TokenTree::Literal(ref t) => t.fmt(f),
}
diff --git a/src/stable.rs b/src/stable.rs
index 62dc670..8091415 100644
--- a/src/stable.rs
+++ b/src/stable.rs
@@ -515,12 +515,23 @@
}
impl fmt::Debug for Ident {
+ // Ident(proc_macro), Ident(r#union)
+ #[cfg(not(procmacro2_semver_exempt))]
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let mut debug = f.debug_tuple("Ident");
+ debug.field(&format_args!("{}", self));
+ debug.finish()
+ }
+
+ // Ident {
+ // sym: proc_macro,
+ // span: bytes(128..138)
+ // }
+ #[cfg(procmacro2_semver_exempt)]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut debug = f.debug_struct("Ident");
- debug.field("sym", &format_args!("{}", self.as_str()));
- #[cfg(procmacro2_semver_exempt)]
+ debug.field("sym", &format_args!("{}", self));
debug.field("span", &self.span);
- debug.field("raw", &self.raw);
debug.finish()
}
}
diff --git a/tests/test.rs b/tests/test.rs
index 629213d..7acd6c3 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -316,7 +316,20 @@
}
#[test]
-fn test_debug() {
+fn test_debug_ident() {
+ let ident = Ident::new("proc_macro", Span::call_site());
+
+ #[cfg(not(procmacro2_semver_exempt))]
+ let expected = "Ident(proc_macro)";
+
+ #[cfg(procmacro2_semver_exempt)]
+ let expected = "Ident { sym: proc_macro, span: bytes(0..0) }";
+
+ assert_eq!(expected, format!("{:?}", ident));
+}
+
+#[test]
+fn test_debug_tokenstream() {
let tts = TokenStream::from_str("[a + 1]").unwrap();
#[cfg(not(procmacro2_semver_exempt))]
@@ -326,8 +339,7 @@
delimiter: Bracket,
stream: TokenStream [
Ident {
- sym: a,
- raw: false
+ sym: a
},
Punct {
op: '+',
@@ -349,8 +361,7 @@
stream: TokenStream [
Ident {
sym: a,
- span: bytes(2..3),
- raw: false
+ span: bytes(2..3)
},
Punct {
op: '+',