Skip to content

Commit 8ff4d41

Browse files
committed
Don't attempt to get cwd when printing backtrace under Miri
This allows Miri to print backtraces in isolation mode
1 parent 4f25c91 commit 8ff4d41

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/libstd/sys_common/backtrace.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,14 @@ unsafe fn _print(w: &mut dyn Write, format: PrintFmt) -> io::Result<()> {
6666
}
6767

6868
unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::Result {
69-
let cwd = env::current_dir().ok();
69+
// Always 'fail' to get the cwd when running under Miri -
70+
// this allows Miri to display backtraces in isolation mode
71+
let cwd = if !cfg!(miri) {
72+
env::current_dir().ok()
73+
} else {
74+
None
75+
};
76+
7077
let mut print_path = move |fmt: &mut fmt::Formatter<'_>, bows: BytesOrWideString<'_>| {
7178
output_filename(fmt, bows, print_fmt, cwd.as_ref())
7279
};

0 commit comments

Comments
 (0)