Omit missing spans from Debug output

This commit is contained in:
David Tolnay 2019-01-19 19:23:59 -08:00
parent 02b42d4ce6
commit fd8cdc8a88
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
3 changed files with 17 additions and 4 deletions

View File

@ -414,6 +414,12 @@ impl fmt::Debug for Span {
}
}
pub fn debug_span_field_if_nontrivial(debug: &mut fmt::DebugStruct, span: Span) {
if cfg!(procmacro2_semver_exempt) {
debug.field("span", &span);
}
}
#[derive(Clone)]
pub struct Group {
delimiter: Delimiter,

View File

@ -495,8 +495,7 @@ impl fmt::Debug for TokenTree {
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());
imp::debug_span_field_if_nontrivial(&mut debug, t.span().inner);
debug.finish()
}
TokenTree::Punct(ref t) => t.fmt(f),
@ -705,8 +704,7 @@ impl fmt::Debug for Punct {
let mut debug = fmt.debug_struct("Punct");
debug.field("op", &self.op);
debug.field("spacing", &self.spacing);
#[cfg(procmacro2_semver_exempt)]
debug.field("span", &self.span);
imp::debug_span_field_if_nontrivial(&mut debug, self.span.inner);
debug.finish()
}
}

View File

@ -551,6 +551,15 @@ impl fmt::Debug for Span {
}
}
pub fn debug_span_field_if_nontrivial(debug: &mut fmt::DebugStruct, span: Span) {
match span {
Span::Compiler(s) => {
debug.field("span", &s);
}
Span::Fallback(s) => fallback::debug_span_field_if_nontrivial(debug, s),
}
}
#[derive(Clone)]
pub enum Group {
Compiler(proc_macro::Group),