mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-05-14 14:46:43 +02:00
Remove unnecessary null check in FFI exercise (#2432)
We only assign `self.dir` once and we only assign it if the pointer is non-null. We can therefore simplify the drop implementation a little.
This commit is contained in:
parent
28b5b559b3
commit
1c3e4648e4
@ -123,11 +123,9 @@ impl Drop for DirectoryIterator {
|
|||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
// Call closedir as needed.
|
// Call closedir as needed.
|
||||||
// ANCHOR_END: Drop
|
// ANCHOR_END: Drop
|
||||||
if !self.dir.is_null() {
|
// SAFETY: self.dir is never NULL.
|
||||||
// SAFETY: self.dir is not NULL.
|
if unsafe { ffi::closedir(self.dir) } != 0 {
|
||||||
if unsafe { ffi::closedir(self.dir) } != 0 {
|
panic!("Could not close {:?}", self.path);
|
||||||
panic!("Could not close {:?}", self.path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user