From 8833260fc1442fc29a8441a13f6f1a4a3a74f901 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 3 Dec 2025 12:36:57 -0800 Subject: [PATCH] DNS PiperOrigin-RevId: 839869481 --- .../generate_bindings/database/code_snippet.rs | 7 +++++++ rs_bindings_from_cc/test/annotations/owned_ptr_rs_api.rs | 6 ++++++ .../test/annotations/owned_ptr_rust_thing.rs | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) 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 1128a26e6..73933bfb2 100644 --- a/rs_bindings_from_cc/generate_bindings/database/code_snippet.rs +++ b/rs_bindings_from_cc/generate_bindings/database/code_snippet.rs @@ -604,6 +604,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 b1fffe8b2..bab57e57e 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 @@ -39,6 +39,12 @@ unsafe impl ::cxx::ExternType for 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()); }