mv compiler to compiler/
This commit is contained in:
parent
db534b3ac2
commit
9e5f7d5631
1686 changed files with 941 additions and 1051 deletions
34
compiler/rustc_data_structures/src/temp_dir.rs
Normal file
34
compiler/rustc_data_structures/src/temp_dir.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
use std::mem::ManuallyDrop;
|
||||
use std::path::Path;
|
||||
use tempfile::TempDir;
|
||||
|
||||
/// This is used to avoid TempDir being dropped on error paths unintentionally.
|
||||
#[derive(Debug)]
|
||||
pub struct MaybeTempDir {
|
||||
dir: ManuallyDrop<TempDir>,
|
||||
// Whether the TempDir should be deleted on drop.
|
||||
keep: bool,
|
||||
}
|
||||
|
||||
impl Drop for MaybeTempDir {
|
||||
fn drop(&mut self) {
|
||||
// Safety: We are in the destructor, and no further access will
|
||||
// occur.
|
||||
let dir = unsafe { ManuallyDrop::take(&mut self.dir) };
|
||||
if self.keep {
|
||||
dir.into_path();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Path> for MaybeTempDir {
|
||||
fn as_ref(&self) -> &Path {
|
||||
self.dir.path()
|
||||
}
|
||||
}
|
||||
|
||||
impl MaybeTempDir {
|
||||
pub fn new(dir: TempDir, keep_on_drop: bool) -> MaybeTempDir {
|
||||
MaybeTempDir { dir: ManuallyDrop::new(dir), keep: keep_on_drop }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue