Mercurial > public > mercurial-scm > hg
changeset 52843: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 | d85a3a5545ab |
children | dabec69bd6fc |
files | rust/Cargo.lock rust/pyo3-sharedref/Cargo.toml rust/pyo3-sharedref/src/lib.rs |
diffstat | 3 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/Cargo.lock Mon Jan 06 17:29:25 2025 +0100 +++ b/rust/Cargo.lock Tue Jan 07 12:51:52 2025 +0100 @@ -1144,6 +1144,7 @@ dependencies = [ "pyo3", "stable_deref_trait", + "static_assertions_next", ] [[package]] @@ -1508,6 +1509,12 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] +name = "static_assertions_next" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7beae5182595e9a8b683fa98c4317f956c9a2dec3b9716990d20023cc60c766" + +[[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index"
--- a/rust/pyo3-sharedref/Cargo.toml Mon Jan 06 17:29:25 2025 +0100 +++ b/rust/pyo3-sharedref/Cargo.toml Tue Jan 07 12:51:52 2025 +0100 @@ -9,3 +9,4 @@ [dependencies] pyo3 = { version = "0.23.1" } stable_deref_trait = "1.2.0" +static_assertions_next = "1.1.2" \ No newline at end of file
--- 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