diff rust/pyo3-sharedref/src/lib.rs @ 52856:189491cea922

pyo3-sharedref: add static assertions that we never implement Deref* Unfortunately, the `static_assertions` crate has never been updated past its 1.1.0 release, meaning we don't get the (now 5+ years old) change that allows us to use generic parameters, so we use `static_assertions_next`.
author Rapha?l Gom?s <rgomes@octobus.net>
date Tue, 07 Jan 2025 12:51:52 +0100
parents 78b2894cd58c
children 8f6d25439bdc
line wrap: on
line diff
--- a/rust/pyo3-sharedref/src/lib.rs	Mon Jan 06 17:29:25 2025 +0100
+++ b/rust/pyo3-sharedref/src/lib.rs	Tue Jan 07 12:51:52 2025 +0100
@@ -482,9 +482,16 @@
     data: T,
 }
 
-// DO NOT implement Deref for SharedByPyObject<T>! Dereferencing
+// DO NOT implement Deref or DerefMut for SharedByPyObject<T>! Dereferencing
 // SharedByPyObject without taking Python GIL wouldn't be safe. Also, the
 // underling reference is invalid if generation != state.generation.
+static_assertions_next::assert_impl!(
+    for(T) SharedByPyObject<T>: !Deref
+);
+
+static_assertions_next::assert_impl!(
+    for(T) SharedByPyObject<T>: !DerefMut
+);
 
 impl<T: ?Sized> SharedByPyObject<T> {
     // No panicking version of borrow() and borrow_mut() are implemented