]> git.nega.tv - josh/narcissus/commitdiff
Fix clippy lints
authorJoshua Simmons <josh@nega.tv>
Mon, 17 Oct 2022 06:47:12 +0000 (08:47 +0200)
committerJoshua Simmons <josh@nega.tv>
Mon, 17 Oct 2022 06:47:12 +0000 (08:47 +0200)
narcissus-core/src/manual_arc.rs
narcissus-core/src/pool.rs
narcissus-core/src/virtual_mem.rs

index 3daa72b91c89f6fb5a7fc06eb31001c36c6911fe..1ab61b414f90ee594e49c92daac334474355809f 100644 (file)
@@ -129,10 +129,8 @@ impl<T> Clone for ManualArc<T> {
 
 impl<T> Drop for ManualArc<T> {
     fn drop(&mut self) {
-        if self.ptr.is_some() {
-            if !std::thread::panicking() {
-                panic!("must call `ManualArc::release` before value is dropped");
-            }
+        if self.ptr.is_some() && !std::thread::panicking() {
+            panic!("must call `ManualArc::release` before value is dropped");
         }
     }
 }
index b04381f9a2a84c9796b047ee0680d7c9906d030d..a1b86be3d4489e11b4bf5de49e81dcf40814d256 100644 (file)
@@ -244,7 +244,7 @@ impl FreeSlots {
 
         // This is slightly wrong, but our freelist doesn't need correct ordering on resize and this
         // avoids moving the values around.
-        if self.len() > 0 {
+        if !self.is_empty() {
             debug_assert!(self.is_full());
             self.tail = 0;
             self.head = self.cap;
index 3ad3b3af62a17b941aeab4672b56eebf8992e19f..ac72a46d216f2ebdb4d969a3c26dff931d7e3679 100644 (file)
@@ -1,5 +1,18 @@
 use crate::libc;
 
+#[derive(Clone, Copy, Debug)]
+pub enum MapError {
+    MapFailed,
+}
+
+impl std::fmt::Display for MapError {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        write!(f, "{:?}", self)
+    }
+}
+
+impl std::error::Error for MapError {}
+
 /// Reserve a virtual memory range.
 ///
 /// Size will be rounded up to align with the system's page size.
@@ -7,7 +20,7 @@ use crate::libc;
 /// The range is valid but inaccessible before calling `virtual_commit`.
 #[cold]
 #[inline(never)]
-pub fn virtual_reserve(size: usize) -> Result<*mut std::ffi::c_void, ()> {
+pub fn virtual_reserve(size: usize) -> Result<*mut std::ffi::c_void, MapError> {
     let ptr = unsafe {
         libc::mmap(
             std::ptr::null_mut(),
@@ -20,7 +33,7 @@ pub fn virtual_reserve(size: usize) -> Result<*mut std::ffi::c_void, ()> {
     };
 
     if ptr == libc::MAP_FAILED || ptr.is_null() {
-        Err(())
+        Err(MapError::MapFailed)
     } else {
         Ok(ptr)
     }
@@ -55,10 +68,10 @@ pub unsafe fn virtual_commit(ptr: *mut std::ffi::c_void, size: usize) {
 /// - `size` must be within range of that reservation.
 #[cold]
 #[inline(never)]
-pub unsafe fn virtual_free(ptr: *mut std::ffi::c_void, size: usize) -> Result<(), ()> {
+pub unsafe fn virtual_free(ptr: *mut std::ffi::c_void, size: usize) -> Result<(), MapError> {
     let result = libc::munmap(ptr, size);
     if result != 0 {
-        Err(())
+        Err(MapError::MapFailed)
     } else {
         Ok(())
     }