mirror of
https://gitee.com/openharmony/third_party_rust_proc-macro2
synced 2024-11-30 02:51:05 +00:00
Omit missing spans from Debug output
This commit is contained in:
parent
02b42d4ce6
commit
fd8cdc8a88
@ -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,
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user