diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-24 02:35:39 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-24 02:35:39 +0000 |
commit | 6af11c1e70b02e1af36fdc339238d3a117fd3a94 (patch) | |
tree | 1a9f8560addaa3d531cf5835e3b60d2262fc9dfb | |
parent | 3f8a66dc69ba3ae4df6a0f3eb879dc30020965bc (diff) | |
parent | 49ed986b79e530a1f5e424a04ce732e70077507f (diff) | |
download | nix-6af11c1e70b02e1af36fdc339238d3a117fd3a94.zip |
Merge #1401
1401: cleanup: remove redundant unwrap in Dir::from_fd r=asomers a=scottlamb
Co-authored-by: Scott Lamb <slamb@slamb.org>
-rw-r--r-- | src/dir.rs | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -53,14 +53,12 @@ impl Dir { /// Converts from a file descriptor, closing it on success or failure. pub fn from_fd(fd: RawFd) -> Result<Self> { - let d = unsafe { libc::fdopendir(fd) }; - if d.is_null() { + let d = ptr::NonNull::new(unsafe { libc::fdopendir(fd) }).ok_or_else(|| { let e = Error::last(); unsafe { libc::close(fd) }; - return Err(e); - }; - // Always guaranteed to be non-null by the previous check - Ok(Dir(ptr::NonNull::new(d).unwrap())) + e + })?; + Ok(Dir(d)) } /// Returns an iterator of `Result<Entry>` which rewinds when finished. |