- Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
In the page on Drop (https://doc.rust-lang.org/rust-by-example/trait/drop.html ), the TempFile example includes the following:
// When TempFile is dropped: // 1. First, the File will be automatically closed (Drop for File) // 2. Then our drop implementation will remove the file impl Drop for TempFile { fn drop(&mut self) { // Note: File is already closed at this point if let Err(e) = std::fs::remove_file(&self.path) {
I believe the comments are incorrect. I believe TempFile::drop
is called before File::drop
, so the file is still open when std::fs::remove_file
is called.
As an additional issue, removing the file while it's still open is fine on Unix-like operating systems, but may cause problems on Windows or other operating systems that block removing opened files.
dhouck and cjee21
Metadata
Metadata
Assignees
Labels
No labels