Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cc_bindings_from_rs/test/enums/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ rust_library(
name = "option",
testonly = 1,
srcs = ["option.rs"],
aspect_hints = ["//features:always_specialize_generics_in_cpp_api_from_rust"],
proc_macro_deps = [
"//support:crubit_annotate",
],
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,13 @@ unsafe extern "C" fn __crubit_thunk_IntoIterator_uinto_uiter_uinto_uiterator_uru
#[unsafe(no_mangle)]
unsafe extern "C" fn __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMoveOnlyIterator(
__self: &'static mut ::into_iterator_rust_golden::MoveOnlyIterator,
__ret_ptr: *mut core::ffi::c_uchar,
__ret_ptr: *mut core::ffi::c_void,
) -> () {
unsafe {
let __rs_return_value =
<::into_iterator_rust_golden::MoveOnlyIterator as ::core::iter::Iterator>::next(__self);
unsafe {
::bridge_rust::internal::encode(
::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::<
::into_iterator_rust_golden::MoveOnlyPayload,
>()),
__ret_ptr as *mut core::ffi::c_uchar,
__rs_return_value,
);
}
(__ret_ptr as *mut ::core::option::Option<::into_iterator_rust_golden::MoveOnlyPayload>)
.write(__rs_return_value);
}
}
#[unsafe(no_mangle)]
Expand All @@ -219,89 +212,59 @@ unsafe extern "C" fn __crubit_thunk_IntoIterator_uinto_uiter_uinto_uiterator_uru
#[unsafe(no_mangle)]
unsafe extern "C" fn __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMyContainerIntoIter(
__self: &'static mut ::into_iterator_rust_golden::MyContainerIntoIter,
__ret_ptr: *mut core::ffi::c_uchar,
__ret_ptr: *mut core::ffi::c_void,
) -> () {
unsafe {
let __rs_return_value =
<::into_iterator_rust_golden::MyContainerIntoIter as ::core::iter::Iterator>::next(
__self,
);
unsafe {
::bridge_rust::internal::encode(
::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::<i32>()),
__ret_ptr as *mut core::ffi::c_uchar,
__rs_return_value,
);
}
(__ret_ptr as *mut ::core::option::Option<i32>).write(__rs_return_value);
}
}
#[unsafe(no_mangle)]
unsafe extern "C" fn __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMyContainerIter_x0000003c_x00000027a_x0000003e(
__self: &'static mut ::into_iterator_rust_golden::MyContainerIter<'static>,
__ret_ptr: *mut core::ffi::c_uchar,
__ret_ptr: *mut core::ffi::c_void,
) -> () {
unsafe {
let __rs_return_value =
<::into_iterator_rust_golden::MyContainerIter as ::core::iter::Iterator>::next(__self);
unsafe {
::bridge_rust::internal::encode(
::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::<&'static i32>()),
__ret_ptr as *mut core::ffi::c_uchar,
__rs_return_value,
);
}
(__ret_ptr as *mut ::core::option::Option<&'static i32>).write(__rs_return_value);
}
}
#[unsafe(no_mangle)]
unsafe extern "C" fn __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMyContainerIterMut_x0000003c_x00000027a_x0000003e(
__self: &'static mut ::into_iterator_rust_golden::MyContainerIterMut<'static>,
__ret_ptr: *mut core::ffi::c_uchar,
__ret_ptr: *mut core::ffi::c_void,
) -> () {
unsafe {
let __rs_return_value =
<::into_iterator_rust_golden::MyContainerIterMut as ::core::iter::Iterator>::next(
__self,
);
unsafe {
::bridge_rust::internal::encode(
::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::<&'static mut i32>()),
__ret_ptr as *mut core::ffi::c_uchar,
__rs_return_value,
);
}
(__ret_ptr as *mut ::core::option::Option<&'static mut i32>).write(__rs_return_value);
}
}
#[unsafe(no_mangle)]
unsafe extern "C" fn __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMyIterator(
__self: &'static mut ::into_iterator_rust_golden::MyIterator,
__ret_ptr: *mut core::ffi::c_uchar,
__ret_ptr: *mut core::ffi::c_void,
) -> () {
unsafe {
let __rs_return_value =
<::into_iterator_rust_golden::MyIterator as ::core::iter::Iterator>::next(__self);
unsafe {
::bridge_rust::internal::encode(
::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::<i32>()),
__ret_ptr as *mut core::ffi::c_uchar,
__rs_return_value,
);
}
(__ret_ptr as *mut ::core::option::Option<i32>).write(__rs_return_value);
}
}
#[unsafe(no_mangle)]
unsafe extern "C" fn __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aSimpleIntoIter(
__self: &'static mut ::into_iterator_rust_golden::SimpleIntoIter,
__ret_ptr: *mut core::ffi::c_uchar,
__ret_ptr: *mut core::ffi::c_void,
) -> () {
unsafe {
let __rs_return_value =
<::into_iterator_rust_golden::SimpleIntoIter as ::core::iter::Iterator>::next(__self);
unsafe {
::bridge_rust::internal::encode(
::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::<i32>()),
__ret_ptr as *mut core::ffi::c_uchar,
__rs_return_value,
);
}
(__ret_ptr as *mut ::core::option::Option<i32>).write(__rs_return_value);
}
}
156 changes: 145 additions & 11 deletions cc_bindings_from_rs/test/structs/const_field/const_field_cc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#pragma clang diagnostic ignored "-Wunused-private-field"
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#pragma clang diagnostic ignored "-Wignored-attributes"
#include "support/bridge.h"
#include "support/internal/slot.h"
#include "support/rs_std/option.h"
#include "support/rs_std/result.h"

#include <bit>
Expand All @@ -30,7 +30,7 @@
namespace const_field {

// CRUBIT_ANNOTATE: must_bind=
::std::optional<::struct_with_const_field>
rs_std::Option<::struct_with_const_field>
return_struct_with_const_field_by_value_in_option();

// CRUBIT_ANNOTATE: must_bind=
Expand All @@ -39,6 +39,68 @@ return_struct_with_const_field_by_value_in_result();

} // namespace const_field

#ifndef _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020struct_uwith_uconst_ufield_x00000020_x0000003e
#define _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020struct_uwith_uconst_ufield_x00000020_x0000003e
template <>
struct alignas(8) CRUBIT_INTERNAL_RUST_TYPE(
"std :: option :: Option < :: cc_struct :: struct_with_const_field >")
rs_std::Option<::struct_with_const_field>
: public rs_std::OptionBase<rs_std::Option<::struct_with_const_field>,
::struct_with_const_field> {
public:
// Rust types that are `Copy` get trivial, `default` C++ copy constructor and
// assignment operator.
Option(const Option&) = default;
Option& operator=(const Option&) = default;
Option(Option&&) = default;
Option& operator=(Option&&) = default;

Option(::crubit::UnsafeRelocateTag, Option&& value);
using base_type =
rs_std::OptionBase<rs_std::Option<::struct_with_const_field>,
::struct_with_const_field>;
constexpr Option() = default;
constexpr Option(::std::nullopt_t) noexcept;
constexpr Option& operator=(::std::nullopt_t) noexcept;
template <typename U>
requires(rs_std::OptionForwardConstructible<Option,
::struct_with_const_field, U>)
Option(U&& value) noexcept;
template <typename U>
requires(rs_std::OptionForwardConstructible<Option,
::struct_with_const_field, U>)
Option& operator=(U&& value) noexcept;
template <typename Opt>
requires(rs_std::OptionFromStdOptional<::struct_with_const_field, Opt>)
Option(Opt&& value) noexcept;
template <typename Opt>
requires(rs_std::OptionFromStdOptional<::struct_with_const_field, Opt>)
Option& operator=(Opt&& value) noexcept;
template <typename... Args>
explicit Option(::std::in_place_t ip, Args&&... args) noexcept;
~Option() noexcept = default;

private:
friend base_type;
using tag_type = ::std::uint64_t;
static constexpr tag_type kNoneVal = 0;
::struct_with_const_field* some_ptr() noexcept {
return reinterpret_cast<::struct_with_const_field*>(storage_ + 8);
}
::struct_with_const_field const* some_const_ptr() const noexcept {
return reinterpret_cast<::struct_with_const_field const*>(storage_ + 8);
}
void set_some_tag() noexcept { set_tag(1); }
constexpr void set_none_tag() noexcept { set_tag(kNoneVal); }
constexpr bool is_none() const noexcept { return tag() == kNoneVal; }
constexpr ::std::uint64_t tag() const& noexcept;
constexpr void set_tag(::std::uint64_t tag) noexcept;

private:
unsigned char storage_[16];
};
#endif

#ifndef _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Result_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020struct_uwith_uconst_ufield_x00000020_x0000002c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020uint8_ut_x00000020_x0000003e
#define _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Result_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020struct_uwith_uconst_ufield_x00000020_x0000002c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020uint8_ut_x00000020_x0000003e
template <>
Expand Down Expand Up @@ -112,20 +174,17 @@ namespace const_field {
namespace __crubit_internal {
extern "C" void
__crubit_thunk_return_ustruct_uwith_uconst_ufield_uby_uvalue_uin_uoption(
unsigned char* __ret_ptr);
rs_std::Option<::struct_with_const_field>* __ret_ptr);
}
inline ::std::optional<::struct_with_const_field>
inline rs_std::Option<::struct_with_const_field>
return_struct_with_const_field_by_value_in_option() {
unsigned char __return_value_storage[::crubit::OptionAbi<
::crubit::TransmuteAbi<struct_with_const_field>>::kSize];
crubit::Slot<rs_std::Option<::struct_with_const_field>>
__return_value_ret_val_holder;
auto* __return_value_storage = __return_value_ret_val_holder.Get();
__crubit_internal::
__crubit_thunk_return_ustruct_uwith_uconst_ufield_uby_uvalue_uin_uoption(
__return_value_storage);
return ::crubit::internal::Decode<
::crubit::OptionAbi<::crubit::TransmuteAbi<struct_with_const_field>>>(
::crubit::OptionAbi<::crubit::TransmuteAbi<struct_with_const_field>>(
::crubit::TransmuteAbi<struct_with_const_field>()),
__return_value_storage);
return ::std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue();
}

namespace __crubit_internal {
Expand All @@ -146,6 +205,81 @@ return_struct_with_const_field_by_value_in_result() {

} // namespace const_field

#ifndef _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020struct_uwith_uconst_ufield_x00000020_x0000003e
#define _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020struct_uwith_uconst_ufield_x00000020_x0000003e
static_assert(::std::is_trivially_copy_constructible_v<
rs_std::Option<::struct_with_const_field>>);
static_assert(::std::is_trivially_copy_assignable_v<
rs_std::Option<::struct_with_const_field>>);
static_assert(::std::is_trivially_move_constructible_v<
rs_std::Option<::struct_with_const_field>>);
static_assert(::std::is_trivially_move_assignable_v<
rs_std::Option<::struct_with_const_field>>);
inline rs_std::Option<::struct_with_const_field>::Option(
::crubit::UnsafeRelocateTag, Option&& value) {
::std::memcpy(this, &value, sizeof(value));
}
static_assert(::std::is_trivially_destructible_v<
rs_std::Option<::struct_with_const_field>>);
inline constexpr ::std::uint64_t
rs_std::Option<::struct_with_const_field>::tag() const& noexcept {
::std::array<unsigned char, sizeof(::std::uint64_t)> __bytes = {};
for (::std::size_t i = 0; i < sizeof(::std::uint64_t); ++i) {
__bytes[i] = storage_[0 + i];
}
return ::std::bit_cast<::std::uint64_t>(__bytes);
}
inline constexpr void rs_std::Option<::struct_with_const_field>::set_tag(
::std::uint64_t tag) noexcept {
auto __bytes =
::std::bit_cast<::std::array<unsigned char, sizeof(::std::uint64_t)>>(
tag);
for (::std::size_t i = 0; i < sizeof(::std::uint64_t); ++i) {
storage_[0 + i] = __bytes[i];
}
}

inline constexpr rs_std::Option<::struct_with_const_field>::Option(
::std::nullopt_t) noexcept
: base_type(::std::nullopt) {}
inline constexpr rs_std::Option<::struct_with_const_field>& rs_std::Option<
::struct_with_const_field>::operator=(::std::nullopt_t) noexcept {
base_type::operator=(::std::nullopt);
return *this;
}
template <typename U>
requires(rs_std::OptionForwardConstructible<
rs_std::Option<::struct_with_const_field>, ::struct_with_const_field,
U>)
inline rs_std::Option<::struct_with_const_field>::Option(U&& value) noexcept
: base_type(::std::forward<U>(value)) {}
template <typename U>
requires(rs_std::OptionForwardConstructible<
rs_std::Option<::struct_with_const_field>, ::struct_with_const_field,
U>)
inline rs_std::Option<::struct_with_const_field>&
rs_std::Option<::struct_with_const_field>::operator=(U&& value) noexcept {
base_type::operator=(::std::forward<U>(value));
return *this;
}
template <typename Opt>
requires(rs_std::OptionFromStdOptional<::struct_with_const_field, Opt>)
inline rs_std::Option<::struct_with_const_field>::Option(Opt&& value) noexcept
: base_type(::std::forward<Opt>(value)) {}
template <typename Opt>
requires(rs_std::OptionFromStdOptional<::struct_with_const_field, Opt>)
inline rs_std::Option<::struct_with_const_field>&
rs_std::Option<::struct_with_const_field>::operator=(Opt&& value) noexcept {
base_type::operator=(::std::forward<Opt>(value));
return *this;
}
template <typename... Args>
inline rs_std::Option<::struct_with_const_field>::Option(
::std::in_place_t ip, Args&&... args) noexcept
: base_type(ip, ::std::forward<Args>(args)...) {}

#endif

#ifndef _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Result_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020struct_uwith_uconst_ufield_x00000020_x0000002c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020uint8_ut_x00000020_x0000003e
#define _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Result_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020struct_uwith_uconst_ufield_x00000020_x0000002c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020uint8_ut_x00000020_x0000003e
static_assert(::std::is_trivially_copy_constructible_v<
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@ extern crate alloc;
extern crate core;
#[unsafe(no_mangle)]
unsafe extern "C" fn __crubit_thunk_return_ustruct_uwith_uconst_ufield_uby_uvalue_uin_uoption(
__ret_ptr: *mut core::ffi::c_uchar,
__ret_ptr: *mut core::ffi::c_void,
) -> () {
unsafe {
let __rs_return_value =
::const_field_golden::return_struct_with_const_field_by_value_in_option();
unsafe {
::bridge_rust::internal::encode(
::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::<
::cc_struct::struct_with_const_field,
>()),
__ret_ptr as *mut core::ffi::c_uchar,
__rs_return_value,
);
}
(__ret_ptr as *mut ::core::option::Option<::cc_struct::struct_with_const_field>)
.write(__rs_return_value);
}
}
#[unsafe(no_mangle)]
Expand Down
Loading