Implement `!Unpin` move constructors.
This very nearly is as simple as just adding && to the IR. The other necessary change was to
use `std::forward` to propagate rvalue references in thunks. (Thanks sbenza@ for giving me the exact form that
would also work for non-reference types! I was about to write my own forward function...)
(The remaining changes are just goldens/tests.)
However, a followup CL is needed to make move constructors actually usable for `Unpin` types -- they can't just call `From<RvalueReference>` because they can't create an `RvalueReference`.
Similarly, while this creates bindings for functions that take or return rvalue reference parameters, they aren't as useful as they could be.
PiperOrigin-RevId: 437970361
diff --git a/rs_bindings_from_cc/importer.cc b/rs_bindings_from_cc/importer.cc
index 7933fa7..89ec891 100644
--- a/rs_bindings_from_cc/importer.cc
+++ b/rs_bindings_from_cc/importer.cc
@@ -916,7 +916,8 @@
if (auto maybe_mapped_type = MapKnownCcTypeToRsType(type_string);
maybe_mapped_type.has_value()) {
return MappedType::Simple(std::string(*maybe_mapped_type), type_string);
- } else if (type->isPointerType() || type->isLValueReferenceType()) {
+ } else if (type->isPointerType() || type->isLValueReferenceType() ||
+ type->isRValueReferenceType()) {
clang::QualType pointee_type = type->getPointeeType();
std::optional<LifetimeId> lifetime;
if (lifetimes.has_value()) {
@@ -967,10 +968,17 @@
if (type->isPointerType()) {
return MappedType::PointerTo(std::move(mapped_pointee_type), lifetime,
nullable);
- } else {
- CRUBIT_CHECK(type->isLValueReferenceType());
+ } else if (type->isLValueReferenceType()) {
return MappedType::LValueReferenceTo(std::move(mapped_pointee_type),
lifetime);
+ } else {
+ CRUBIT_CHECK(type->isRValueReferenceType());
+ if (!lifetime.has_value()) {
+ return absl::UnimplementedError(
+ "Unsupported type: && without lifetime");
+ }
+ return MappedType::RValueReferenceTo(std::move(mapped_pointee_type),
+ *lifetime);
}
} else if (const auto* builtin_type =
// Use getAsAdjusted instead of getAs so we don't desugar