diff --git a/rs_bindings_from_cc/generate_bindings/database/code_snippet.rs b/rs_bindings_from_cc/generate_bindings/database/code_snippet.rs index 002a928c4..4b26790aa 100644 --- a/rs_bindings_from_cc/generate_bindings/database/code_snippet.rs +++ b/rs_bindings_from_cc/generate_bindings/database/code_snippet.rs @@ -672,6 +672,13 @@ pub fn generated_items_to_tokens( __COMMENT__ "Generated due to CRUBIT_OWNED_POINTEE annotation." #[repr(transparent)] pub struct #owned_type_name(::core::ptr::NonNull<#ident>); + + impl Drop for #owned_type_name { + fn drop(&mut self) { + __COMMENT__ "The DropImpl method must be implemented in a user-written .rs file that's included using additional_rust_srcs" + self.DropImpl(); + } + } } }); diff --git a/rs_bindings_from_cc/test/annotations/owned_ptr_rs_api.rs b/rs_bindings_from_cc/test/annotations/owned_ptr_rs_api.rs index 2551722a5..a1038285b 100644 --- a/rs_bindings_from_cc/test/annotations/owned_ptr_rs_api.rs +++ b/rs_bindings_from_cc/test/annotations/owned_ptr_rs_api.rs @@ -50,6 +50,12 @@ impl RawThing { // Generated due to CRUBIT_OWNED_POINTEE annotation. #[repr(transparent)] pub struct OwnedThing(::core::ptr::NonNull); +impl Drop for OwnedThing { + fn drop(&mut self) { + // The DropImpl method must be implemented in a user-written .rs file that's included using additional_rust_srcs + self.DropImpl(); + } +} /// Generated from: rs_bindings_from_cc/test/annotations/owned_ptr.h;l=18 impl From for RawThing { diff --git a/rs_bindings_from_cc/test/annotations/owned_ptr_rust_thing.rs b/rs_bindings_from_cc/test/annotations/owned_ptr_rust_thing.rs index ad8da4467..6a0f7ff5d 100644 --- a/rs_bindings_from_cc/test/annotations/owned_ptr_rust_thing.rs +++ b/rs_bindings_from_cc/test/annotations/owned_ptr_rust_thing.rs @@ -2,8 +2,8 @@ // Exceptions. See /LICENSE for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -impl Drop for crate::OwnedThing { - fn drop(&mut self) { +impl crate::OwnedThing { + pub(crate) fn DropImpl(&mut self) { unsafe { crate::RawThing::Close(self.0.as_mut()); }