Skip to content

Commit c0ba79e

Browse files
committed
less noisy format
1 parent 4920456 commit c0ba79e

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

src/libstd/backtrace.rs

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ use backtrace_rs as backtrace;
106106
/// previous point in time. In some instances the `Backtrace` type may
107107
/// internally be empty due to configuration. For more information see
108108
/// `Backtrace::capture`.
109-
#[derive(Debug)]
110109
pub struct Backtrace {
111110
inner: Inner,
112111
}
@@ -146,7 +145,6 @@ fn _assert_send_sync() {
146145
_assert::<Backtrace>();
147146
}
148147

149-
#[derive(Debug)]
150148
struct BacktraceFrame {
151149
frame: backtrace::Frame,
152150
symbols: Vec<BacktraceSymbol>,
@@ -163,13 +161,45 @@ enum BytesOrWide {
163161
Wide(Vec<u16>),
164162
}
165163

164+
impl fmt::Debug for Backtrace {
165+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
166+
let mut capture = match &self.inner {
167+
Inner::Unsupported => return fmt.write_str("unsupported backtrace"),
168+
Inner::Disabled => return fmt.write_str("disabled backtrace"),
169+
Inner::Captured(c) => c.lock().unwrap(),
170+
};
171+
capture.resolve();
172+
173+
let mut dbg = fmt.debug_list();
174+
175+
for frame in &capture.frames {
176+
dbg.entries(&frame.symbols);
177+
}
178+
179+
dbg.finish()
180+
}
181+
}
182+
183+
impl fmt::Debug for BacktraceFrame {
184+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
185+
fmt.debug_list().entries(&self.symbols).finish()
186+
}
187+
}
188+
166189
impl fmt::Debug for BacktraceSymbol {
167190
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
168-
fmt.debug_struct("BacktraceSymbol")
169-
.field("name", &self.name.as_ref().map(|b| backtrace::SymbolName::new(b)))
170-
.field("filename", &self.filename)
171-
.field("lineno", &self.lineno)
172-
.finish()
191+
let mut dbg = fmt.debug_struct("");
192+
dbg.field("fn", &self.name.as_ref().map(|b| backtrace::SymbolName::new(b)));
193+
194+
if let Some(fname) = self.filename.as_ref() {
195+
dbg.field("file", fname);
196+
}
197+
198+
if let Some(line) = self.lineno.as_ref() {
199+
dbg.field("line", &self.lineno);
200+
}
201+
202+
dbg.finish()
173203
}
174204
}
175205

0 commit comments

Comments
 (0)