From 82dfe263343dd6a901b92c83a53c5a8cd970c9e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Bary=C5=82a?= Date: Fri, 6 Jan 2023 12:14:50 +0100 Subject: [PATCH] clippy: warn on FFI not using new traits --- scylla-rust-wrapper/clippy.toml | 21 +++++++++++++++++++++ scylla-rust-wrapper/src/argconv.rs | 14 ++++++++++++++ scylla-rust-wrapper/src/future.rs | 1 + 3 files changed, 36 insertions(+) create mode 100644 scylla-rust-wrapper/clippy.toml diff --git a/scylla-rust-wrapper/clippy.toml b/scylla-rust-wrapper/clippy.toml new file mode 100644 index 00000000..7256d6f6 --- /dev/null +++ b/scylla-rust-wrapper/clippy.toml @@ -0,0 +1,21 @@ +disallowed-methods = [ + "std::boxed::Box::from_raw", + "std::boxed::Box::from_raw_in", + "std::boxed::Box::into_raw", + "std::boxed::Box::into_raw_with_allocator", + + "std::sync::Arc::as_ptr", + "std::sync::Arc::decrement_strong_count", + "std::sync::Arc::from_raw", + "std::sync::Arc::increment_strong_count", + "std::sync::Arc::into_raw", + + "std::rc::Rc::as_ptr", + "std::rc::Rc::decrement_strong_count", + "std::rc::Rc::from_raw", + "std::rc::Rc::increment_strong_count", + "std::rc::Rc::into_raw", + + "const_ptr::as_ref", + "mut_ptr::as_mut" +] diff --git a/scylla-rust-wrapper/src/argconv.rs b/scylla-rust-wrapper/src/argconv.rs index 33203e7a..6730eb5e 100644 --- a/scylla-rust-wrapper/src/argconv.rs +++ b/scylla-rust-wrapper/src/argconv.rs @@ -78,18 +78,23 @@ pub(crate) use make_c_str; /// the memory associated with the pointer using corresponding driver's API function. pub trait BoxFFI { fn into_ptr(self: Box) -> *mut Self { + #[allow(clippy::disallowed_methods)] Box::into_raw(self) } unsafe fn from_ptr(ptr: *mut Self) -> Box { + #[allow(clippy::disallowed_methods)] Box::from_raw(ptr) } unsafe fn maybe_as_ref<'a>(ptr: *const Self) -> Option<&'a Self> { + #[allow(clippy::disallowed_methods)] ptr.as_ref() } unsafe fn as_ref<'a>(ptr: *const Self) -> &'a Self { + #[allow(clippy::disallowed_methods)] ptr.as_ref().unwrap() } unsafe fn as_mut_ref<'a>(ptr: *mut Self) -> &'a mut Self { + #[allow(clippy::disallowed_methods)] ptr.as_mut().unwrap() } unsafe fn free(ptr: *mut Self) { @@ -107,22 +112,29 @@ pub trait BoxFFI { /// This trait does not support interior mutability. For this, see [`MutArcFFI`]. pub trait ArcFFI { fn as_ptr(self: &Arc) -> *const Self { + #[allow(clippy::disallowed_methods)] Arc::as_ptr(self) } fn into_ptr(self: Arc) -> *const Self { + #[allow(clippy::disallowed_methods)] Arc::into_raw(self) } unsafe fn from_ptr(ptr: *const Self) -> Arc { + #[allow(clippy::disallowed_methods)] Arc::from_raw(ptr) } unsafe fn cloned_from_ptr(ptr: *const Self) -> Arc { + #[allow(clippy::disallowed_methods)] Arc::increment_strong_count(ptr); + #[allow(clippy::disallowed_methods)] Arc::from_raw(ptr) } unsafe fn maybe_as_ref<'a>(ptr: *const Self) -> Option<&'a Self> { + #[allow(clippy::disallowed_methods)] ptr.as_ref() } unsafe fn as_ref<'a>(ptr: *const Self) -> &'a Self { + #[allow(clippy::disallowed_methods)] ptr.as_ref().unwrap() } unsafe fn free(ptr: *const Self) { @@ -133,6 +145,7 @@ pub trait ArcFFI { /// An API extension for shared data that require interior mutability. pub trait MutArcFFI: ArcFFI { unsafe fn as_mut_ref<'a>(ptr: *mut Self) -> &'a mut Self { + #[allow(clippy::disallowed_methods)] ptr.as_mut().unwrap() } } @@ -150,6 +163,7 @@ pub trait RefFFI { self as *const Self } unsafe fn as_ref<'a>(ptr: *const Self) -> &'a Self { + #[allow(clippy::disallowed_methods)] ptr.as_ref().unwrap() } } diff --git a/scylla-rust-wrapper/src/future.rs b/scylla-rust-wrapper/src/future.rs index 79c6d0d0..8b5bb987 100644 --- a/scylla-rust-wrapper/src/future.rs +++ b/scylla-rust-wrapper/src/future.rs @@ -488,6 +488,7 @@ mod tests { // the future, and execute its callback #[test] #[ntest::timeout(600)] + #[allow(clippy::disallowed_methods)] fn test_cass_future_callback() { unsafe { const ERROR_MSG: &str = "NOBODY EXPECTED SPANISH INQUISITION";