Include default move constructor in the generated C++ bindings.
In the past we decided to hold off with generating C++ assignment
operators to keep our options open for dealing with various memory
safety concerns. At this point we've decided to accept the risks
and want to enable the assignment operators.
PiperOrigin-RevId: 538198331
diff --git a/cc_bindings_from_rs/bindings.rs b/cc_bindings_from_rs/bindings.rs
index 0c4d07b..608c71b 100644
--- a/cc_bindings_from_rs/bindings.rs
+++ b/cc_bindings_from_rs/bindings.rs
@@ -1209,15 +1209,7 @@
// generated C++ move constructor might need to assign `Default::default()` to the
// moved-from object.
#cc_short_name(#cc_short_name&&) = default;
-
- // TODO(b/258235219): Providing assignment operators enables mutation which
- // may negatively interact with support for references. Therefore until we
- // have more confidence in our reference-handling-plans, we are deleting the
- // assignment operators.
- //
- // (Move assignment operator has another set of concerns and constraints - see the
- // comment for the move constructor above).
- #cc_short_name& operator=(#cc_short_name&&) = delete;
+ #cc_short_name& operator=(#cc_short_name&&) = default;
// TODO(b/258251148): Support custom `Drop` impls and drop glue.
~#cc_short_name() = default;
@@ -3646,9 +3638,7 @@
// All Rust types are trivially-movable.
SomeStruct(SomeStruct&&) = default;
-
- // Assignment operators are disabled for now.
- SomeStruct& operator=(SomeStruct&&) = delete;
+ SomeStruct& operator=(SomeStruct&&) = default;
// In this test there is no custom `Drop`, so C++ can also
// just use the `default` destructor.
@@ -3711,9 +3701,7 @@
// All Rust types are trivially-movable.
TupleStruct(TupleStruct&&) = default;
-
- // Assignment operators are disabled for now.
- TupleStruct& operator=(TupleStruct&&) = delete;
+ TupleStruct& operator=(TupleStruct&&) = default;
// In this test there is no custom `Drop`, so C++ can also
// just use the `default` destructor.
@@ -4582,9 +4570,7 @@
// All Rust types are trivially-movable.
SomeEnum(SomeEnum&&) = default;
-
- // Assignment operators are disabled for now.
- SomeEnum& operator=(SomeEnum&&) = delete;
+ SomeEnum& operator=(SomeEnum&&) = default;
// In this test there is no custom `Drop`, so C++ can also
// just use the `default` destructor.
@@ -4648,9 +4634,7 @@
// All Rust types are trivially-movable.
Point(Point&&) = default;
-
- // Assignment operators are disabled for now.
- Point& operator=(Point&&) = delete;
+ Point& operator=(Point&&) = default;
// In this test there is no custom `Drop`, so C++ can also
// just use the `default` destructor.
@@ -4727,9 +4711,7 @@
// All Rust types are trivially-movable.
SomeUnion(SomeUnion&&) = default;
-
- // Assignment operators are disabled for now.
- SomeUnion& operator=(SomeUnion&&) = delete;
+ SomeUnion& operator=(SomeUnion&&) = default;
// In this test there is no custom `Drop`, so C++ can also
// just use the `default` destructor.
diff --git a/docs/bindings/reference/pointers_and_references.md b/docs/bindings/reference/pointers_and_references.md
index 0fc7989..9bb8c02 100644
--- a/docs/bindings/reference/pointers_and_references.md
+++ b/docs/bindings/reference/pointers_and_references.md
@@ -96,7 +96,7 @@
Examples of C++ features that may mutate a value that Rust holds a reference to:
-* Using copy assignment operator of C++ value that Rust has a
+* Using copy or move assignment operator of C++ value that Rust has a
reference to.
* Mutating public fields of a C++ struct that Rust has a reference to.