Skip to content

Commit 6af11c1

Browse files
bors[bot]scottlamb
andauthored
Merge #1401
1401: cleanup: remove redundant unwrap in Dir::from_fd r=asomers a=scottlamb Co-authored-by: Scott Lamb <[email protected]>
2 parents 3f8a66d + 49ed986 commit 6af11c1

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/dir.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@ impl Dir {
5353

5454
/// Converts from a file descriptor, closing it on success or failure.
5555
pub fn from_fd(fd: RawFd) -> Result<Self> {
56-
let d = unsafe { libc::fdopendir(fd) };
57-
if d.is_null() {
56+
let d = ptr::NonNull::new(unsafe { libc::fdopendir(fd) }).ok_or_else(|| {
5857
let e = Error::last();
5958
unsafe { libc::close(fd) };
60-
return Err(e);
61-
};
62-
// Always guaranteed to be non-null by the previous check
63-
Ok(Dir(ptr::NonNull::new(d).unwrap()))
59+
e
60+
})?;
61+
Ok(Dir(d))
6462
}
6563

6664
/// Returns an iterator of `Result<Entry>` which rewinds when finished.

0 commit comments

Comments
 (0)