Skip to content

Commit 750c593

Browse files
Lorak-mmkmuzarski
authored andcommitted
clippy: warn on FFI not using new traits
1 parent 5ed6199 commit 750c593

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

scylla-rust-wrapper/clippy.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
disallowed-methods = [
2+
"std::boxed::Box::from_raw",
3+
"std::boxed::Box::from_raw_in",
4+
"std::boxed::Box::into_raw",
5+
"std::boxed::Box::into_raw_with_allocator",
6+
7+
"std::sync::Arc::as_ptr",
8+
"std::sync::Arc::decrement_strong_count",
9+
"std::sync::Arc::from_raw",
10+
"std::sync::Arc::increment_strong_count",
11+
"std::sync::Arc::into_raw",
12+
13+
"std::rc::Rc::as_ptr",
14+
"std::rc::Rc::decrement_strong_count",
15+
"std::rc::Rc::from_raw",
16+
"std::rc::Rc::increment_strong_count",
17+
"std::rc::Rc::into_raw",
18+
19+
"const_ptr::as_ref",
20+
"mut_ptr::as_mut"
21+
]

scylla-rust-wrapper/src/argconv.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,23 @@ pub(crate) use make_c_str;
7878
/// the memory associated with the pointer using corresponding driver's API function.
7979
pub trait BoxFFI {
8080
fn into_ptr(self: Box<Self>) -> *mut Self {
81+
#[allow(clippy::disallowed_methods)]
8182
Box::into_raw(self)
8283
}
8384
unsafe fn from_ptr(ptr: *mut Self) -> Box<Self> {
85+
#[allow(clippy::disallowed_methods)]
8486
Box::from_raw(ptr)
8587
}
8688
unsafe fn maybe_as_ref<'a>(ptr: *const Self) -> Option<&'a Self> {
89+
#[allow(clippy::disallowed_methods)]
8790
ptr.as_ref()
8891
}
8992
unsafe fn as_ref<'a>(ptr: *const Self) -> &'a Self {
93+
#[allow(clippy::disallowed_methods)]
9094
ptr.as_ref().unwrap()
9195
}
9296
unsafe fn as_mut_ref<'a>(ptr: *mut Self) -> &'a mut Self {
97+
#[allow(clippy::disallowed_methods)]
9398
ptr.as_mut().unwrap()
9499
}
95100
unsafe fn free(ptr: *mut Self) {
@@ -105,22 +110,29 @@ pub trait BoxFFI {
105110
/// with the pointer using corresponding driver's API function.
106111
pub trait ArcFFI {
107112
fn as_ptr(self: &Arc<Self>) -> *const Self {
113+
#[allow(clippy::disallowed_methods)]
108114
Arc::as_ptr(self)
109115
}
110116
fn into_ptr(self: Arc<Self>) -> *const Self {
117+
#[allow(clippy::disallowed_methods)]
111118
Arc::into_raw(self)
112119
}
113120
unsafe fn from_ptr(ptr: *const Self) -> Arc<Self> {
121+
#[allow(clippy::disallowed_methods)]
114122
Arc::from_raw(ptr)
115123
}
116124
unsafe fn cloned_from_ptr(ptr: *const Self) -> Arc<Self> {
125+
#[allow(clippy::disallowed_methods)]
117126
Arc::increment_strong_count(ptr);
127+
#[allow(clippy::disallowed_methods)]
118128
Arc::from_raw(ptr)
119129
}
120130
unsafe fn maybe_as_ref<'a>(ptr: *const Self) -> Option<&'a Self> {
131+
#[allow(clippy::disallowed_methods)]
121132
ptr.as_ref()
122133
}
123134
unsafe fn as_ref<'a>(ptr: *const Self) -> &'a Self {
135+
#[allow(clippy::disallowed_methods)]
124136
ptr.as_ref().unwrap()
125137
}
126138
unsafe fn free(ptr: *const Self) {
@@ -141,6 +153,7 @@ pub trait RefFFI {
141153
self as *const Self
142154
}
143155
unsafe fn as_ref<'a>(ptr: *const Self) -> &'a Self {
156+
#[allow(clippy::disallowed_methods)]
144157
ptr.as_ref().unwrap()
145158
}
146159
}

scylla-rust-wrapper/src/future.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ mod tests {
489489
// the future, and execute its callback
490490
#[test]
491491
#[ntest::timeout(600)]
492+
#[allow(clippy::disallowed_methods)]
492493
fn test_cass_future_callback() {
493494
unsafe {
494495
const ERROR_MSG: &str = "NOBODY EXPECTED SPANISH INQUISITION";

0 commit comments

Comments
 (0)