1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-05-15 07:06:52 +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:
Martin Geisler 2024-10-16 11:25:22 +02:00 committed by GitHub
parent 28b5b559b3
commit 1c3e4648e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -123,13 +123,11 @@ 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);
} }
} }
}
} }
// ANCHOR: main // ANCHOR: main