@@ -5,9 +5,9 @@ use crate::PrintFmt;
5
5
use crate :: resolve;
6
6
use crate :: { BacktraceFmt , Symbol , SymbolName , resolve_frame, trace} ;
7
7
use core:: ffi:: c_void;
8
- use std:: fmt;
9
8
use std:: path:: { Path , PathBuf } ;
10
9
use std:: prelude:: v1:: * ;
10
+ use std:: { env, fmt} ;
11
11
12
12
#[ cfg( feature = "serde" ) ]
13
13
use serde:: { Deserialize , Serialize } ;
@@ -490,22 +490,21 @@ impl fmt::Debug for Backtrace {
490
490
PrintFmt :: Short
491
491
} ;
492
492
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
495
493
// short format, because if it's full we presumably want to print
496
494
// everything.
497
- let cwd = std:: env:: current_dir ( ) ;
498
495
let mut print_path =
499
496
move |fmt : & mut fmt:: Formatter < ' _ > , path : crate :: BytesOrWideString < ' _ > | {
500
497
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)
507
507
}
508
- fmt:: Display :: fmt ( & path. display ( ) , fmt)
509
508
} ;
510
509
511
510
let mut f = BacktraceFmt :: new ( fmt, style, & mut print_path) ;
0 commit comments