Skip to content

Commit 0ee4c61

Browse files
cleanup: let-chain in style selection
1 parent f2bcf65 commit 0ee4c61

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/capture.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use crate::PrintFmt;
55
use crate::resolve;
66
use crate::{BacktraceFmt, Symbol, SymbolName, resolve_frame, trace};
77
use core::ffi::c_void;
8-
use std::fmt;
98
use std::path::{Path, PathBuf};
109
use std::prelude::v1::*;
10+
use std::{env, fmt};
1111

1212
#[cfg(feature = "serde")]
1313
use serde::{Deserialize, Serialize};
@@ -490,22 +490,21 @@ impl fmt::Debug for Backtrace {
490490
PrintFmt::Short
491491
};
492492

493-
// When printing paths we try to strip the cwd if it exists, otherwise
494-
// we just print the path as-is. Note that we also only do this for the
495493
// short format, because if it's full we presumably want to print
496494
// everything.
497-
let cwd = std::env::current_dir();
498495
let mut print_path =
499496
move |fmt: &mut fmt::Formatter<'_>, path: crate::BytesOrWideString<'_>| {
500497
let path = path.into_path_buf();
501-
if style != PrintFmt::Full {
502-
if let Ok(cwd) = &cwd {
503-
if let Ok(suffix) = path.strip_prefix(cwd) {
504-
return fmt::Display::fmt(&suffix.display(), fmt);
505-
}
506-
}
498+
// When printing paths we try to strip the cwd if it exists, otherwise
499+
// we just print the path as-is
500+
if style == PrintFmt::Short
501+
&& let Ok(cwd) = &env::current_dir()
502+
&& let Ok(suffix) = path.strip_prefix(cwd)
503+
{
504+
fmt::Display::fmt(&suffix.display(), fmt)
505+
} else {
506+
fmt::Display::fmt(&path.display(), fmt)
507507
}
508-
fmt::Display::fmt(&path.display(), fmt)
509508
};
510509

511510
let mut f = BacktraceFmt::new(fmt, style, &mut print_path);

0 commit comments

Comments
 (0)