diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-01-28 15:20:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-28 15:20:25 +0100 |
| commit | 4f2e2ceeb7ee67e0645d68d89f20bc44340ad79d (patch) | |
| tree | d29654ca7c8bd9eb471c6fc39bb89a9d11b846b4 /library/std/src | |
| parent | ada77e94ab9244dfb1b535b5340ebe4eefd80d7d (diff) | |
| parent | 84c0c9d20dbe1d171e6aaf61b8e512d6dc78412f (diff) | |
| download | rust-4f2e2ceeb7ee67e0645d68d89f20bc44340ad79d.tar.gz rust-4f2e2ceeb7ee67e0645d68d89f20bc44340ad79d.zip | |
Rollup merge of #93295 - ChrisDenton:tempdir-double-panic, r=dtolnay
Avoid double panics when using `TempDir` in tests `TempDir` could panic on drop if `remove_dir_all` returns an error. If this happens while already panicking, the test process would abort and therefore not show the test results. This PR tries to avoid such double panics.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/sys_common/io.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/library/std/src/sys_common/io.rs b/library/std/src/sys_common/io.rs index ea9108f1713..d1e9fed41fc 100644 --- a/library/std/src/sys_common/io.rs +++ b/library/std/src/sys_common/io.rs @@ -8,6 +8,7 @@ pub mod test { use crate::env; use crate::fs; use crate::path::{Path, PathBuf}; + use crate::thread; use rand::RngCore; pub struct TempDir(PathBuf); @@ -29,7 +30,12 @@ pub mod test { // Gee, seeing how we're testing the fs module I sure hope that we // at least implement this correctly! let TempDir(ref p) = *self; - fs::remove_dir_all(p).unwrap(); + let result = fs::remove_dir_all(p); + // Avoid panicking while panicking as this causes the process to + // immediately abort, without displaying test results. + if !thread::panicking() { + result.unwrap(); + } } } |
