Skip to content

Delete C++ move operations for non-copyable Clone types#758

Open
copybara-service[bot] wants to merge 1 commit intomainfrom
test_889377273
Open

Delete C++ move operations for non-copyable Clone types#758
copybara-service[bot] wants to merge 1 commit intomainfrom
test_889377273

Conversation

@copybara-service
Copy link
Copy Markdown

Delete C++ move operations for non-copyable Clone types

Previously, Crubit would generate C++ move constructors for Rust types that implemented Clone but not Copy by deferring them to MoveCtorStyle::Copy. This would silently invoke the C++ copy constructor (and underlying Rust Clone::clone) instead of performing an actual move. By itself, this is not harmful at all.

This caused severe memory leaks when crossing the FFI boundary within TansmuteAbi, however. For example, when crubit::TransmuteAbi decodes bytes into a C++ object, it takes the raw bytes from Rust and attempts to std::move them into ownership. Because the move constructors were falling back to deep copies, the new C++ object was a copied clone, and the original raw bytes (owning things like Box) were abandoned without Drop::drop ever being called.

This CL removes MoveCtorStyle::Copy so that C++ move operations are explicitly deleted (= delete) for non-trivially movable Clone types. This correctly turns silent deep-copy memory leaks into compile-time errors.

Previously, Crubit would generate C++ move constructors for Rust types that implemented `Clone` but not `Copy` by deferring them to `MoveCtorStyle::Copy`. This would silently invoke the C++ copy constructor (and underlying Rust `Clone::clone`) instead of performing an actual move. By itself, this is not harmful at all.

This caused severe memory leaks when crossing the FFI boundary within TansmuteAbi, however. For example, when `crubit::TransmuteAbi` decodes bytes into a C++ object, it takes the raw bytes from Rust and attempts to `std::move` them into ownership. Because the move constructors were falling back to deep copies, the new C++ object was a copied clone, and the original raw bytes (owning things like `Box`) were abandoned without `Drop::drop` ever being called.

This CL removes `MoveCtorStyle::Copy` so that C++ move operations are explicitly deleted (`= delete`) for non-trivially movable `Clone` types. This correctly turns silent deep-copy memory leaks into compile-time errors.

PiperOrigin-RevId: 889377273
@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 25, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants