about summary refs log tree commit diff
path: root/library/std/src/sys/pal/windows/fs.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-02-10 11:38:45 +0000
committerbors <bors@rust-lang.org>2025-02-10 11:38:45 +0000
commit8c04e395952022a451138dc4dbead6dd6ae65203 (patch)
treead0062d7c194bb6841e3fa09c09fe6d28c08bdc0 /library/std/src/sys/pal/windows/fs.rs
parent80c091958f05e573433df974f8d2f2bc3a3eadfb (diff)
parentffa8a96040b8bb1ae8b856ae2a95159ffe1cb400 (diff)
downloadrust-8c04e395952022a451138dc4dbead6dd6ae65203.tar.gz
rust-8c04e395952022a451138dc4dbead6dd6ae65203.zip
Auto merge of #136809 - workingjubilee:rollup-jk0pew1, r=workingjubilee
Rollup of 12 pull requests

Successful merges:

 - #136053 (coverage: Defer part of counter-creation until codegen)
 - #136201 (Removed dependency on the field-offset crate, alternate approach)
 - #136228 (Simplify Rc::as_ptr docs + typo fix)
 - #136353 (fix(libtest): Enable Instant on Emscripten targets)
 - #136472 ([`compiletest`-related cleanups 2/7] Feed stage number to compiletest directly)
 - #136487 (ci: stop mysql before removing it)
 - #136552 (Use an `Option` for `FindNextFileHandle` in `ReadDir` instead of `INVALID_FILE_HANDLE` sentinel value)
 - #136705 (Some miscellaneous edition-related library tweaks)
 - #136707 (Bump `cc` to v1.2.13 for the compiler workspace)
 - #136790 (Git blame ignore recent formatting commit)
 - #136792 (Don't apply editorconfig to llvm)
 - #136805 (ignore win_delete_self test in Miri)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sys/pal/windows/fs.rs')
-rw-r--r--library/std/src/sys/pal/windows/fs.rs16
1 files changed, 6 insertions, 10 deletions
diff --git a/library/std/src/sys/pal/windows/fs.rs b/library/std/src/sys/pal/windows/fs.rs
index bdb55643bb1..b786c79004f 100644
--- a/library/std/src/sys/pal/windows/fs.rs
+++ b/library/std/src/sys/pal/windows/fs.rs
@@ -44,7 +44,7 @@ pub struct FileType {
 }
 
 pub struct ReadDir {
-    handle: FindNextFileHandle,
+    handle: Option<FindNextFileHandle>,
     root: Arc<PathBuf>,
     first: Option<c::WIN32_FIND_DATAW>,
 }
@@ -113,13 +113,13 @@ impl fmt::Debug for ReadDir {
 impl Iterator for ReadDir {
     type Item = io::Result<DirEntry>;
     fn next(&mut self) -> Option<io::Result<DirEntry>> {
-        if self.handle.0 == c::INVALID_HANDLE_VALUE {
+        let Some(handle) = self.handle.as_ref() else {
             // This iterator was initialized with an `INVALID_HANDLE_VALUE` as its handle.
             // Simply return `None` because this is only the case when `FindFirstFileExW` in
             // the construction of this iterator returns `ERROR_FILE_NOT_FOUND` which means
             // no matchhing files can be found.
             return None;
-        }
+        };
         if let Some(first) = self.first.take() {
             if let Some(e) = DirEntry::new(&self.root, &first) {
                 return Some(Ok(e));
@@ -128,7 +128,7 @@ impl Iterator for ReadDir {
         unsafe {
             let mut wfd = mem::zeroed();
             loop {
-                if c::FindNextFileW(self.handle.0, &mut wfd) == 0 {
+                if c::FindNextFileW(handle.0, &mut wfd) == 0 {
                     match api::get_last_error() {
                         WinError::NO_MORE_FILES => return None,
                         WinError { code } => {
@@ -1194,7 +1194,7 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
 
         if find_handle != c::INVALID_HANDLE_VALUE {
             Ok(ReadDir {
-                handle: FindNextFileHandle(find_handle),
+                handle: Some(FindNextFileHandle(find_handle)),
                 root: Arc::new(root),
                 first: Some(wfd),
             })
@@ -1212,11 +1212,7 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
             // See issue #120040: https://github.com/rust-lang/rust/issues/120040.
             let last_error = api::get_last_error();
             if last_error == WinError::FILE_NOT_FOUND {
-                return Ok(ReadDir {
-                    handle: FindNextFileHandle(find_handle),
-                    root: Arc::new(root),
-                    first: None,
-                });
+                return Ok(ReadDir { handle: None, root: Arc::new(root), first: None });
             }
 
             // Just return the error constructed from the raw OS error if the above is not the case.