diff --git a/cc_bindings_from_rs/test/enums/BUILD b/cc_bindings_from_rs/test/enums/BUILD index cec3cb846..ee5db1e46 100644 --- a/cc_bindings_from_rs/test/enums/BUILD +++ b/cc_bindings_from_rs/test/enums/BUILD @@ -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", ], diff --git a/cc_bindings_from_rs/test/known_traits/into_iterator/into_iterator_cc_api.h b/cc_bindings_from_rs/test/known_traits/into_iterator/into_iterator_cc_api.h index ff5a443a9..759480b15 100644 --- a/cc_bindings_from_rs/test/known_traits/into_iterator/into_iterator_cc_api.h +++ b/cc_bindings_from_rs/test/known_traits/into_iterator/into_iterator_cc_api.h @@ -15,14 +15,15 @@ #pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wignored-attributes" #include "support/annotations_internal.h" -#include "support/bridge.h" #include "support/internal/slot.h" #include "support/lifetime_annotations.h" #include "support/rs_std/iterator_adapter.h" +#include "support/rs_std/option.h" #include "support/rs_std/slice_ref.h" #include "support/rs_std/traits.h" #include +#include #include #include #include @@ -389,7 +390,7 @@ struct rs_std::impl<::into_iterator_rust::MoveOnlyIterator, "::Item") = ::into_iterator_rust::MoveOnlyPayload; - static ::std::optional<::into_iterator_rust::MoveOnlyPayload> next( + static rs_std::Option<::into_iterator_rust::MoveOnlyPayload> next( ::into_iterator_rust::MoveOnlyIterator& self); }; @@ -416,7 +417,7 @@ struct rs_std::impl<::into_iterator_rust::MyContainerIntoIter, "::Item") = ::std::int32_t; - static ::std::optional<::std::int32_t> next( + static rs_std::Option<::std::int32_t> next( ::into_iterator_rust::MyContainerIntoIter& self); }; @@ -428,7 +429,7 @@ struct rs_std::impl<::into_iterator_rust::MyContainerIter, " as :: core :: iter :: " "Iterator>::Item") = ::std::int32_t const* $a crubit_nonnull; - static ::std::optional<::std::int32_t const * $a crubit_nonnull> next( + static rs_std::Option<::std::int32_t const * $static crubit_nonnull> next( ::into_iterator_rust::MyContainerIter& self); }; @@ -440,7 +441,7 @@ struct rs_std::impl<::into_iterator_rust::MyContainerIterMut, " as :: core :: iter " ":: Iterator>::Item") = ::std::int32_t* $a crubit_nonnull; - static ::std::optional<::std::int32_t* $a crubit_nonnull> next( + static rs_std::Option<::std::int32_t* $static crubit_nonnull> next( ::into_iterator_rust::MyContainerIterMut& self); }; @@ -492,7 +493,7 @@ struct rs_std::impl<::into_iterator_rust::MyIterator, "::Item") = ::std::int32_t; - static ::std::optional<::std::int32_t> next( + static rs_std::Option<::std::int32_t> next( ::into_iterator_rust::MyIterator& self); }; @@ -504,9 +505,266 @@ struct rs_std::impl<::into_iterator_rust::SimpleIntoIter, "::Item") = ::std::int32_t; - static ::std::optional<::std::int32_t> next( + static rs_std::Option<::std::int32_t> next( ::into_iterator_rust::SimpleIntoIter& self); }; +#ifndef _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020const_x00000020_x0000002a_x00000020_d_x00000020static_x00000020crubit_unonnull_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020const_x00000020_x0000002a_x00000020_d_x00000020static_x00000020crubit_unonnull_x00000020_x0000003e +template <> +struct alignas(8) + CRUBIT_INTERNAL_RUST_TYPE("std :: option :: Option < & 'static i32 >") + rs_std::Option<::std::int32_t const * $static crubit_nonnull> + : public rs_std::OptionBase< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>, + ::std::int32_t const * $static crubit_nonnull> { + 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<::std::int32_t const * $static crubit_nonnull>, + ::std::int32_t const * $static crubit_nonnull>; + constexpr Option() = default; + constexpr Option(::std::nullopt_t) noexcept; + constexpr Option& operator=(::std::nullopt_t) noexcept; + template + requires(rs_std::OptionForwardConstructible< + Option, ::std::int32_t const * $static crubit_nonnull, U>) + Option(U&& value) noexcept; + template + requires(rs_std::OptionForwardConstructible< + Option, ::std::int32_t const * $static crubit_nonnull, U>) + Option& operator=(U&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional< + ::std::int32_t const * $static crubit_nonnull, Opt>) + Option(Opt&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional< + ::std::int32_t const * $static crubit_nonnull, Opt>) + Option& operator=(Opt&& value) noexcept; + template + 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; + ::std::int32_t const* $static crubit_nonnull* some_ptr() noexcept { + return reinterpret_cast<::std::int32_t const * $static crubit_nonnull*>( + storage_); + } + ::std::int32_t const* $static crubit_nonnull const* some_const_ptr() + const noexcept { + return reinterpret_cast<::std::int32_t const * + $static crubit_nonnull const*>(storage_); + } + void set_some_tag() noexcept {} + 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_[8]; +}; +#endif + +#ifndef _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000002a_x00000020_d_x00000020static_x00000020crubit_unonnull_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000002a_x00000020_d_x00000020static_x00000020crubit_unonnull_x00000020_x0000003e +template <> +struct alignas(8) + CRUBIT_INTERNAL_RUST_TYPE("std :: option :: Option < & 'static mut i32 >") + rs_std::Option<::std::int32_t* $static crubit_nonnull> + : public rs_std::OptionBase< + rs_std::Option<::std::int32_t* $static crubit_nonnull>, + ::std::int32_t* $static crubit_nonnull> { + public: + // `core::option::Option` doesn't implement the `Clone` trait + Option(const Option&) = delete; + Option& operator=(const Option&) = delete; + Option(Option&&) = default; + Option& operator=(Option&&) = default; + + Option(::crubit::UnsafeRelocateTag, Option&& value); + using base_type = + rs_std::OptionBase, + ::std::int32_t* $static crubit_nonnull>; + constexpr Option() = default; + constexpr Option(::std::nullopt_t) noexcept; + constexpr Option& operator=(::std::nullopt_t) noexcept; + template + requires(rs_std::OptionForwardConstructible< + Option, ::std::int32_t * $static crubit_nonnull, U>) + Option(U&& value) noexcept; + template + requires(rs_std::OptionForwardConstructible< + Option, ::std::int32_t * $static crubit_nonnull, U>) + Option& operator=(U&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional< + ::std::int32_t * $static crubit_nonnull, Opt>) + Option(Opt&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional< + ::std::int32_t * $static crubit_nonnull, Opt>) + Option& operator=(Opt&& value) noexcept; + template + 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; + ::std::int32_t* $static crubit_nonnull* some_ptr() noexcept { + return reinterpret_cast<::std::int32_t* $static crubit_nonnull*>(storage_); + } + ::std::int32_t* $static crubit_nonnull const* some_const_ptr() + const noexcept { + return reinterpret_cast<::std::int32_t* $static crubit_nonnull const*>( + storage_); + } + void set_some_tag() noexcept {} + 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_[8]; +}; +#endif + +#ifndef _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000003e +template <> +struct alignas(4) CRUBIT_INTERNAL_RUST_TYPE( + "std :: option :: Option < i32 >") rs_std::Option<::std::int32_t> + : public rs_std::OptionBase, + ::std::int32_t> { + 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, ::std::int32_t>; + constexpr Option() = default; + constexpr Option(::std::nullopt_t) noexcept; + constexpr Option& operator=(::std::nullopt_t) noexcept; + template + requires(rs_std::OptionForwardConstructible) + Option(U&& value) noexcept; + template + requires(rs_std::OptionForwardConstructible) + Option& operator=(U&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional<::std::int32_t, Opt>) + Option(Opt&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional<::std::int32_t, Opt>) + Option& operator=(Opt&& value) noexcept; + template + explicit Option(::std::in_place_t ip, Args&&... args) noexcept; + ~Option() noexcept = default; + + private: + friend base_type; + using tag_type = ::std::uint32_t; + static constexpr tag_type kNoneVal = 0; + ::std::int32_t* some_ptr() noexcept { + return reinterpret_cast<::std::int32_t*>(storage_ + 4); + } + ::std::int32_t const* some_const_ptr() const noexcept { + return reinterpret_cast<::std::int32_t const*>(storage_ + 4); + } + 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::uint32_t tag() const& noexcept; + constexpr void set_tag(::std::uint32_t tag) noexcept; + + private: + unsigned char storage_[8]; +}; +#endif + +#ifndef _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020into_uiterator_urust_x00000020_x0000003a_x0000003a_x00000020MoveOnlyPayload_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020into_uiterator_urust_x00000020_x0000003a_x0000003a_x00000020MoveOnlyPayload_x00000020_x0000003e +template <> +struct alignas(4) CRUBIT_INTERNAL_RUST_TYPE( + "std :: option :: Option < :: into_iterator_rust_golden :: MoveOnlyPayload " + ">") rs_std::Option<::into_iterator_rust::MoveOnlyPayload> + : public rs_std::OptionBase< + rs_std::Option<::into_iterator_rust::MoveOnlyPayload>, + ::into_iterator_rust::MoveOnlyPayload> { + public: + // `core::option::Option` doesn't implement the `Clone` trait + Option(const Option&) = delete; + Option& operator=(const Option&) = delete; + Option(Option&&) = default; + Option& operator=(Option&&) = default; + + Option(::crubit::UnsafeRelocateTag, Option&& value); + using base_type = + rs_std::OptionBase, + ::into_iterator_rust::MoveOnlyPayload>; + constexpr Option() = default; + constexpr Option(::std::nullopt_t) noexcept; + constexpr Option& operator=(::std::nullopt_t) noexcept; + template + requires(rs_std::OptionForwardConstructible< + Option, ::into_iterator_rust::MoveOnlyPayload, U>) + Option(U&& value) noexcept; + template + requires(rs_std::OptionForwardConstructible< + Option, ::into_iterator_rust::MoveOnlyPayload, U>) + Option& operator=(U&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional< + ::into_iterator_rust::MoveOnlyPayload, Opt>) + Option(Opt&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional< + ::into_iterator_rust::MoveOnlyPayload, Opt>) + Option& operator=(Opt&& value) noexcept; + template + explicit Option(::std::in_place_t ip, Args&&... args) noexcept; + ~Option() noexcept = default; + + private: + friend base_type; + using tag_type = ::std::uint32_t; + static constexpr tag_type kNoneVal = 0; + ::into_iterator_rust::MoveOnlyPayload* some_ptr() noexcept { + return reinterpret_cast<::into_iterator_rust::MoveOnlyPayload*>(storage_ + + 4); + } + ::into_iterator_rust::MoveOnlyPayload const* some_const_ptr() const noexcept { + return reinterpret_cast<::into_iterator_rust::MoveOnlyPayload const*>( + storage_ + 4); + } + 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::uint32_t tag() const& noexcept; + constexpr void set_tag(::std::uint32_t tag) noexcept; + + private: + unsigned char storage_[8]; +}; +#endif namespace into_iterator_rust { @@ -897,24 +1155,21 @@ namespace into_iterator_rust { namespace __crubit_internal { extern "C" void __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMoveOnlyIterator( - ::into_iterator_rust::MoveOnlyIterator&, unsigned char* __ret_ptr); + ::into_iterator_rust::MoveOnlyIterator&, + rs_std::Option<::into_iterator_rust::MoveOnlyPayload>* __ret_ptr); } } // namespace into_iterator_rust -inline ::std::optional<::into_iterator_rust::MoveOnlyPayload> rs_std::impl< +inline rs_std::Option<::into_iterator_rust::MoveOnlyPayload> rs_std::impl< ::into_iterator_rust::MoveOnlyIterator, ::rs::core::iter::Iterator>::next(::into_iterator_rust::MoveOnlyIterator& self) { - unsigned char __return_value_storage[::crubit::OptionAbi< - ::crubit::TransmuteAbi<::into_iterator_rust::MoveOnlyPayload>>::kSize]; + crubit::Slot> + __return_value_ret_val_holder; + auto* __return_value_storage = __return_value_ret_val_holder.Get(); into_iterator_rust::__crubit_internal:: __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMoveOnlyIterator( self, __return_value_storage); - return ::crubit::internal::Decode<::crubit::OptionAbi< - ::crubit::TransmuteAbi<::into_iterator_rust::MoveOnlyPayload>>>( - ::crubit::OptionAbi< - ::crubit::TransmuteAbi<::into_iterator_rust::MoveOnlyPayload>>( - ::crubit::TransmuteAbi<::into_iterator_rust::MoveOnlyPayload>()), - __return_value_storage); + return ::std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); } namespace into_iterator_rust { @@ -942,118 +1197,415 @@ namespace into_iterator_rust { namespace __crubit_internal { extern "C" void __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMyContainerIntoIter( - ::into_iterator_rust::MyContainerIntoIter&, unsigned char* __ret_ptr); + ::into_iterator_rust::MyContainerIntoIter&, + rs_std::Option<::std::int32_t>* __ret_ptr); } } // namespace into_iterator_rust -inline ::std::optional<::std::int32_t> rs_std::impl< +inline rs_std::Option<::std::int32_t> rs_std::impl< ::into_iterator_rust::MyContainerIntoIter, ::rs::core::iter::Iterator>::next(::into_iterator_rust::MyContainerIntoIter& self) { - unsigned char __return_value_storage - [::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>::kSize]; + crubit::Slot> __return_value_ret_val_holder; + auto* __return_value_storage = __return_value_ret_val_holder.Get(); into_iterator_rust::__crubit_internal:: __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMyContainerIntoIter( self, __return_value_storage); - return ::crubit::internal::Decode< - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>>( - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>( - ::crubit::TransmuteAbi<::std::int32_t>()), - __return_value_storage); + return ::std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); } namespace into_iterator_rust { namespace __crubit_internal { extern "C" void __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMyContainerIter_x0000003c_x00000027a_x0000003e( - ::into_iterator_rust::MyContainerIter&, unsigned char* __ret_ptr); + ::into_iterator_rust::MyContainerIter&, + rs_std::Option<::std::int32_t const * $static crubit_nonnull>* __ret_ptr); } } // namespace into_iterator_rust -inline ::std::optional<::std::int32_t const * $a crubit_nonnull> rs_std::impl< - ::into_iterator_rust::MyContainerIter, - ::rs::core::iter::Iterator>::next(::into_iterator_rust::MyContainerIter& - self) { - unsigned char - __return_value_storage[::crubit::OptionAbi<::crubit::TransmuteAbi< - ::std::int32_t const * $static crubit_nonnull>>::kSize]; +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull> +rs_std::impl<::into_iterator_rust::MyContainerIter, + ::rs::core::iter::Iterator>:: + next(::into_iterator_rust::MyContainerIter& self) { + crubit::Slot> + __return_value_ret_val_holder; + auto* __return_value_storage = __return_value_ret_val_holder.Get(); into_iterator_rust::__crubit_internal:: __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMyContainerIter_x0000003c_x00000027a_x0000003e( self, __return_value_storage); - return ::crubit::internal::Decode<::crubit::OptionAbi< - ::crubit::TransmuteAbi<::std::int32_t const * $static crubit_nonnull>>>( - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t const * - $static crubit_nonnull>>( - ::crubit::TransmuteAbi<::std::int32_t const * - $static crubit_nonnull>()), - __return_value_storage); + return ::std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); } namespace into_iterator_rust { namespace __crubit_internal { extern "C" void __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMyContainerIterMut_x0000003c_x00000027a_x0000003e( - ::into_iterator_rust::MyContainerIterMut&, unsigned char* __ret_ptr); + ::into_iterator_rust::MyContainerIterMut&, + rs_std::Option<::std::int32_t* $static crubit_nonnull>* __ret_ptr); } } // namespace into_iterator_rust -inline ::std::optional<::std::int32_t* $a crubit_nonnull> rs_std::impl< +inline rs_std::Option<::std::int32_t* $static crubit_nonnull> rs_std::impl< ::into_iterator_rust::MyContainerIterMut, ::rs::core::iter::Iterator>::next(::into_iterator_rust::MyContainerIterMut& self) { - unsigned char __return_value_storage[::crubit::OptionAbi< - ::crubit::TransmuteAbi<::std::int32_t* $static crubit_nonnull>>::kSize]; + crubit::Slot> + __return_value_ret_val_holder; + auto* __return_value_storage = __return_value_ret_val_holder.Get(); into_iterator_rust::__crubit_internal:: __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMyContainerIterMut_x0000003c_x00000027a_x0000003e( self, __return_value_storage); - return ::crubit::internal::Decode<::crubit::OptionAbi< - ::crubit::TransmuteAbi<::std::int32_t* $static crubit_nonnull>>>( - ::crubit::OptionAbi< - ::crubit::TransmuteAbi<::std::int32_t* $static crubit_nonnull>>( - ::crubit::TransmuteAbi<::std::int32_t* $static crubit_nonnull>()), - __return_value_storage); + return ::std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); } namespace into_iterator_rust { namespace __crubit_internal { extern "C" void __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMyIterator( - ::into_iterator_rust::MyIterator&, unsigned char* __ret_ptr); + ::into_iterator_rust::MyIterator&, + rs_std::Option<::std::int32_t>* __ret_ptr); } } // namespace into_iterator_rust -inline ::std::optional<::std::int32_t> rs_std::impl< +inline rs_std::Option<::std::int32_t> rs_std::impl< ::into_iterator_rust::MyIterator, ::rs::core::iter::Iterator>::next(::into_iterator_rust::MyIterator& self) { - unsigned char __return_value_storage - [::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>::kSize]; + crubit::Slot> __return_value_ret_val_holder; + auto* __return_value_storage = __return_value_ret_val_holder.Get(); into_iterator_rust::__crubit_internal:: __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aMyIterator( self, __return_value_storage); - return ::crubit::internal::Decode< - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>>( - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>( - ::crubit::TransmuteAbi<::std::int32_t>()), - __return_value_storage); + return ::std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); } namespace into_iterator_rust { namespace __crubit_internal { extern "C" void __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aSimpleIntoIter( - ::into_iterator_rust::SimpleIntoIter&, unsigned char* __ret_ptr); + ::into_iterator_rust::SimpleIntoIter&, + rs_std::Option<::std::int32_t>* __ret_ptr); } } // namespace into_iterator_rust -inline ::std::optional<::std::int32_t> +inline rs_std::Option<::std::int32_t> rs_std::impl<::into_iterator_rust::SimpleIntoIter, ::rs::core::iter::Iterator>:: next(::into_iterator_rust::SimpleIntoIter& self) { - unsigned char __return_value_storage - [::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>::kSize]; + crubit::Slot> __return_value_ret_val_holder; + auto* __return_value_storage = __return_value_ret_val_holder.Get(); into_iterator_rust::__crubit_internal:: __crubit_thunk_Iterator_unext_uinto_uiterator_urust_ugolden_x0000003a_x0000003aSimpleIntoIter( self, __return_value_storage); - return ::crubit::internal::Decode< - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>>( - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>( - ::crubit::TransmuteAbi<::std::int32_t>()), - __return_value_storage); + return ::std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); +} + +#ifndef _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020const_x00000020_x0000002a_x00000020_d_x00000020static_x00000020crubit_unonnull_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020const_x00000020_x0000002a_x00000020_d_x00000020static_x00000020crubit_unonnull_x00000020_x0000003e +static_assert(::std::is_trivially_copy_constructible_v< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>>); +static_assert(::std::is_trivially_copy_assignable_v< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>>); +static_assert(::std::is_trivially_move_constructible_v< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>>); +static_assert(::std::is_trivially_move_assignable_v< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>>); +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull>::Option( + ::crubit::UnsafeRelocateTag, Option&& value) { + ::std::memcpy(this, &value, sizeof(value)); +} +static_assert(::std::is_trivially_destructible_v< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>>); +inline constexpr ::std::uint64_t rs_std::Option< + ::std::int32_t const * $static crubit_nonnull>::tag() const& noexcept { + ::std::array __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<::std::int32_t const * $static crubit_nonnull>::set_tag( + ::std::uint64_t tag) noexcept { + auto __bytes = + ::std::bit_cast<::std::array>( + tag); + for (::std::size_t i = 0; i < sizeof(::std::uint64_t); ++i) { + storage_[0 + i] = __bytes[i]; + } +} + +inline constexpr rs_std::Option<::std::int32_t const * $static crubit_nonnull>:: + Option(::std::nullopt_t) noexcept + : base_type(::std::nullopt) {} +inline constexpr rs_std::Option<::std::int32_t const * $static crubit_nonnull>& +rs_std::Option<::std::int32_t const * $static crubit_nonnull>::operator=( + ::std::nullopt_t) noexcept { + base_type::operator=(::std::nullopt); + return *this; +} +template + requires(rs_std::OptionForwardConstructible< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>, + ::std::int32_t const * $static crubit_nonnull, U>) +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull>::Option( + U&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionForwardConstructible< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>, + ::std::int32_t const * $static crubit_nonnull, U>) +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull>& +rs_std::Option<::std::int32_t const * $static crubit_nonnull>::operator=( + U&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template + requires(rs_std::OptionFromStdOptional< + ::std::int32_t const * $static crubit_nonnull, Opt>) +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull>::Option( + Opt&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionFromStdOptional< + ::std::int32_t const * $static crubit_nonnull, Opt>) +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull>& +rs_std::Option<::std::int32_t const * $static crubit_nonnull>::operator=( + Opt&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull>::Option( + ::std::in_place_t ip, Args&&... args) noexcept + : base_type(ip, ::std::forward(args)...) {} + +#endif + +#ifndef _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000002a_x00000020_d_x00000020static_x00000020crubit_unonnull_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000002a_x00000020_d_x00000020static_x00000020crubit_unonnull_x00000020_x0000003e +static_assert(::std::is_trivially_move_constructible_v< + rs_std::Option<::std::int32_t* $static crubit_nonnull>>); +static_assert(::std::is_trivially_move_assignable_v< + rs_std::Option<::std::int32_t* $static crubit_nonnull>>); +inline rs_std::Option<::std::int32_t* $static crubit_nonnull>::Option( + ::crubit::UnsafeRelocateTag, Option&& value) { + ::std::memcpy(this, &value, sizeof(value)); +} +static_assert(::std::is_trivially_destructible_v< + rs_std::Option<::std::int32_t* $static crubit_nonnull>>); +inline constexpr ::std::uint64_t +rs_std::Option<::std::int32_t* $static crubit_nonnull>::tag() const& noexcept { + ::std::array __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<::std::int32_t* $static crubit_nonnull>::set_tag( + ::std::uint64_t tag) noexcept { + auto __bytes = + ::std::bit_cast<::std::array>( + tag); + for (::std::size_t i = 0; i < sizeof(::std::uint64_t); ++i) { + storage_[0 + i] = __bytes[i]; + } +} + +inline constexpr rs_std::Option<::std::int32_t* $static crubit_nonnull>::Option( + ::std::nullopt_t) noexcept + : base_type(::std::nullopt) {} +inline constexpr rs_std::Option<::std::int32_t* $static crubit_nonnull>& +rs_std::Option<::std::int32_t* $static crubit_nonnull>::operator=( + ::std::nullopt_t) noexcept { + base_type::operator=(::std::nullopt); + return *this; +} +template + requires(rs_std::OptionForwardConstructible< + rs_std::Option<::std::int32_t * $static crubit_nonnull>, + ::std::int32_t * $static crubit_nonnull, U>) +inline rs_std::Option<::std::int32_t* $static crubit_nonnull>::Option( + U&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionForwardConstructible< + rs_std::Option<::std::int32_t * $static crubit_nonnull>, + ::std::int32_t * $static crubit_nonnull, U>) +inline rs_std::Option<::std::int32_t* $static crubit_nonnull>& +rs_std::Option<::std::int32_t* $static crubit_nonnull>::operator=( + U&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template + requires(rs_std::OptionFromStdOptional< + ::std::int32_t * $static crubit_nonnull, Opt>) +inline rs_std::Option<::std::int32_t* $static crubit_nonnull>::Option( + Opt&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionFromStdOptional< + ::std::int32_t * $static crubit_nonnull, Opt>) +inline rs_std::Option<::std::int32_t* $static crubit_nonnull>& +rs_std::Option<::std::int32_t* $static crubit_nonnull>::operator=( + Opt&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template +inline rs_std::Option<::std::int32_t* $static crubit_nonnull>::Option( + ::std::in_place_t ip, Args&&... args) noexcept + : base_type(ip, ::std::forward(args)...) {} + +#endif + +#ifndef _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000003e +static_assert( + ::std::is_trivially_copy_constructible_v>); +static_assert( + ::std::is_trivially_copy_assignable_v>); +static_assert( + ::std::is_trivially_move_constructible_v>); +static_assert( + ::std::is_trivially_move_assignable_v>); +inline rs_std::Option<::std::int32_t>::Option(::crubit::UnsafeRelocateTag, + Option&& value) { + ::std::memcpy(this, &value, sizeof(value)); +} +static_assert( + ::std::is_trivially_destructible_v>); +inline constexpr ::std::uint32_t rs_std::Option<::std::int32_t>::tag() + const& noexcept { + ::std::array __bytes = {}; + for (::std::size_t i = 0; i < sizeof(::std::uint32_t); ++i) { + __bytes[i] = storage_[0 + i]; + } + return ::std::bit_cast<::std::uint32_t>(__bytes); +} +inline constexpr void rs_std::Option<::std::int32_t>::set_tag( + ::std::uint32_t tag) noexcept { + auto __bytes = + ::std::bit_cast<::std::array>( + tag); + for (::std::size_t i = 0; i < sizeof(::std::uint32_t); ++i) { + storage_[0 + i] = __bytes[i]; + } +} + +inline constexpr rs_std::Option<::std::int32_t>::Option( + ::std::nullopt_t) noexcept + : base_type(::std::nullopt) {} +inline constexpr rs_std::Option<::std::int32_t>& +rs_std::Option<::std::int32_t>::operator=(::std::nullopt_t) noexcept { + base_type::operator=(::std::nullopt); + return *this; +} +template + requires(rs_std::OptionForwardConstructible, + ::std::int32_t, U>) +inline rs_std::Option<::std::int32_t>::Option(U&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionForwardConstructible, + ::std::int32_t, U>) +inline rs_std::Option<::std::int32_t>& +rs_std::Option<::std::int32_t>::operator=(U&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template + requires(rs_std::OptionFromStdOptional<::std::int32_t, Opt>) +inline rs_std::Option<::std::int32_t>::Option(Opt&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionFromStdOptional<::std::int32_t, Opt>) +inline rs_std::Option<::std::int32_t>& +rs_std::Option<::std::int32_t>::operator=(Opt&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; } +template +inline rs_std::Option<::std::int32_t>::Option(::std::in_place_t ip, + Args&&... args) noexcept + : base_type(ip, ::std::forward(args)...) {} + +#endif + +#ifndef _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020into_uiterator_urust_x00000020_x0000003a_x0000003a_x00000020MoveOnlyPayload_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020into_uiterator_urust_x00000020_x0000003a_x0000003a_x00000020MoveOnlyPayload_x00000020_x0000003e +static_assert(::std::is_trivially_move_constructible_v< + rs_std::Option<::into_iterator_rust::MoveOnlyPayload>>); +static_assert(::std::is_trivially_move_assignable_v< + rs_std::Option<::into_iterator_rust::MoveOnlyPayload>>); +inline rs_std::Option<::into_iterator_rust::MoveOnlyPayload>::Option( + ::crubit::UnsafeRelocateTag, Option&& value) { + ::std::memcpy(this, &value, sizeof(value)); +} +static_assert(::std::is_trivially_destructible_v< + rs_std::Option<::into_iterator_rust::MoveOnlyPayload>>); +inline constexpr ::std::uint32_t +rs_std::Option<::into_iterator_rust::MoveOnlyPayload>::tag() const& noexcept { + ::std::array __bytes = {}; + for (::std::size_t i = 0; i < sizeof(::std::uint32_t); ++i) { + __bytes[i] = storage_[0 + i]; + } + return ::std::bit_cast<::std::uint32_t>(__bytes); +} +inline constexpr void +rs_std::Option<::into_iterator_rust::MoveOnlyPayload>::set_tag( + ::std::uint32_t tag) noexcept { + auto __bytes = + ::std::bit_cast<::std::array>( + tag); + for (::std::size_t i = 0; i < sizeof(::std::uint32_t); ++i) { + storage_[0 + i] = __bytes[i]; + } +} + +inline constexpr rs_std::Option<::into_iterator_rust::MoveOnlyPayload>::Option( + ::std::nullopt_t) noexcept + : base_type(::std::nullopt) {} +inline constexpr rs_std::Option<::into_iterator_rust::MoveOnlyPayload>& +rs_std::Option<::into_iterator_rust::MoveOnlyPayload>::operator=( + ::std::nullopt_t) noexcept { + base_type::operator=(::std::nullopt); + return *this; +} +template + requires(rs_std::OptionForwardConstructible< + rs_std::Option<::into_iterator_rust::MoveOnlyPayload>, + ::into_iterator_rust::MoveOnlyPayload, U>) +inline rs_std::Option<::into_iterator_rust::MoveOnlyPayload>::Option( + U&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionForwardConstructible< + rs_std::Option<::into_iterator_rust::MoveOnlyPayload>, + ::into_iterator_rust::MoveOnlyPayload, U>) +inline rs_std::Option<::into_iterator_rust::MoveOnlyPayload>& +rs_std::Option<::into_iterator_rust::MoveOnlyPayload>::operator=( + U&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template + requires( + rs_std::OptionFromStdOptional<::into_iterator_rust::MoveOnlyPayload, Opt>) +inline rs_std::Option<::into_iterator_rust::MoveOnlyPayload>::Option( + Opt&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires( + rs_std::OptionFromStdOptional<::into_iterator_rust::MoveOnlyPayload, Opt>) +inline rs_std::Option<::into_iterator_rust::MoveOnlyPayload>& +rs_std::Option<::into_iterator_rust::MoveOnlyPayload>::operator=( + Opt&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template +inline rs_std::Option<::into_iterator_rust::MoveOnlyPayload>::Option( + ::std::in_place_t ip, Args&&... args) noexcept + : base_type(ip, ::std::forward(args)...) {} + +#endif #pragma clang diagnostic pop #endif // THIRD_PARTY_CRUBIT_CC_BINDINGS_FROM_RS_TEST_KNOWN_TRAITS_INTO_ITERATOR_INTO_ITERATOR_RUST_GOLDEN diff --git a/cc_bindings_from_rs/test/known_traits/into_iterator/into_iterator_cc_api_impl.rs b/cc_bindings_from_rs/test/known_traits/into_iterator/into_iterator_cc_api_impl.rs index 08ce861f5..b756ea6a2 100644 --- a/cc_bindings_from_rs/test/known_traits/into_iterator/into_iterator_cc_api_impl.rs +++ b/cc_bindings_from_rs/test/known_traits/into_iterator/into_iterator_cc_api_impl.rs @@ -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)] @@ -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::()), - __ret_ptr as *mut core::ffi::c_uchar, - __rs_return_value, - ); - } + (__ret_ptr as *mut ::core::option::Option).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::()), - __ret_ptr as *mut core::ffi::c_uchar, - __rs_return_value, - ); - } + (__ret_ptr as *mut ::core::option::Option).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::()), - __ret_ptr as *mut core::ffi::c_uchar, - __rs_return_value, - ); - } + (__ret_ptr as *mut ::core::option::Option).write(__rs_return_value); } } diff --git a/cc_bindings_from_rs/test/structs/const_field/const_field_cc_api.h b/cc_bindings_from_rs/test/structs/const_field/const_field_cc_api.h index 9e36edda2..12c0b49a6 100644 --- a/cc_bindings_from_rs/test/structs/const_field/const_field_cc_api.h +++ b/cc_bindings_from_rs/test/structs/const_field/const_field_cc_api.h @@ -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 @@ -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= @@ -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, + ::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, + ::struct_with_const_field>; + constexpr Option() = default; + constexpr Option(::std::nullopt_t) noexcept; + constexpr Option& operator=(::std::nullopt_t) noexcept; + template + requires(rs_std::OptionForwardConstructible) + Option(U&& value) noexcept; + template + requires(rs_std::OptionForwardConstructible) + Option& operator=(U&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional<::struct_with_const_field, Opt>) + Option(Opt&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional<::struct_with_const_field, Opt>) + Option& operator=(Opt&& value) noexcept; + template + 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 <> @@ -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>::kSize]; + crubit::Slot> + __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>>( - ::crubit::OptionAbi<::crubit::TransmuteAbi>( - ::crubit::TransmuteAbi()), - __return_value_storage); + return ::std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); } namespace __crubit_internal { @@ -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 __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>( + 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 + 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(value)) {} +template + 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(value)); + return *this; +} +template + 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(value)) {} +template + 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(value)); + return *this; +} +template +inline rs_std::Option<::struct_with_const_field>::Option( + ::std::in_place_t ip, Args&&... args) noexcept + : base_type(ip, ::std::forward(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< diff --git a/cc_bindings_from_rs/test/structs/const_field/const_field_cc_api_impl.rs b/cc_bindings_from_rs/test/structs/const_field/const_field_cc_api_impl.rs index 3499e76b3..f8c237a7a 100644 --- a/cc_bindings_from_rs/test/structs/const_field/const_field_cc_api_impl.rs +++ b/cc_bindings_from_rs/test/structs/const_field/const_field_cc_api_impl.rs @@ -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)] diff --git a/cc_bindings_from_rs/test/traits/stdlib/stdlib_cc_api.h b/cc_bindings_from_rs/test/traits/stdlib/stdlib_cc_api.h index 97deae256..f0c17df9c 100644 --- a/cc_bindings_from_rs/test/traits/stdlib/stdlib_cc_api.h +++ b/cc_bindings_from_rs/test/traits/stdlib/stdlib_cc_api.h @@ -15,14 +15,15 @@ #pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wignored-attributes" #include "support/annotations_internal.h" -#include "support/bridge.h" #include "support/internal/memswap.h" #include "support/internal/slot.h" #include "support/lifetime_annotations.h" #include "support/rs_std/iterator_adapter.h" +#include "support/rs_std/option.h" #include "support/rs_std/slice_ref.h" #include "support/rs_std/traits.h" +#include #include #include #include @@ -191,7 +192,7 @@ struct rs_std::impl<::stdlib::MyStruct, ::rs::core::iter::Iterator> { "::Item") = ::std::int32_t; - static ::std::optional<::std::int32_t> next(::stdlib::MyStruct& self); + static rs_std::Option<::std::int32_t> next(::stdlib::MyStruct& self); }; template <> @@ -209,7 +210,7 @@ struct rs_std::impl<::stdlib::NonCloneableIterator, "::Item") = ::stdlib::NonCloneableValue; - static ::std::optional<::stdlib::NonCloneableValue> next( + static rs_std::Option<::stdlib::NonCloneableValue> next( ::stdlib::NonCloneableIterator& self); }; @@ -220,9 +221,195 @@ struct rs_std::impl<::stdlib::RefIterator, ::rs::core::iter::Iterator> { " as :: core :: iter :: Iterator>::Item") = ::std::int32_t const* $a crubit_nonnull; - static ::std::optional<::std::int32_t const * $a crubit_nonnull> next( + static rs_std::Option<::std::int32_t const * $static crubit_nonnull> next( ::stdlib::RefIterator& self); }; +#ifndef _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020const_x00000020_x0000002a_x00000020_d_x00000020static_x00000020crubit_unonnull_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020const_x00000020_x0000002a_x00000020_d_x00000020static_x00000020crubit_unonnull_x00000020_x0000003e +template <> +struct alignas(8) + CRUBIT_INTERNAL_RUST_TYPE("std :: option :: Option < & 'static i32 >") + rs_std::Option<::std::int32_t const * $static crubit_nonnull> + : public rs_std::OptionBase< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>, + ::std::int32_t const * $static crubit_nonnull> { + 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<::std::int32_t const * $static crubit_nonnull>, + ::std::int32_t const * $static crubit_nonnull>; + constexpr Option() = default; + constexpr Option(::std::nullopt_t) noexcept; + constexpr Option& operator=(::std::nullopt_t) noexcept; + template + requires(rs_std::OptionForwardConstructible< + Option, ::std::int32_t const * $static crubit_nonnull, U>) + Option(U&& value) noexcept; + template + requires(rs_std::OptionForwardConstructible< + Option, ::std::int32_t const * $static crubit_nonnull, U>) + Option& operator=(U&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional< + ::std::int32_t const * $static crubit_nonnull, Opt>) + Option(Opt&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional< + ::std::int32_t const * $static crubit_nonnull, Opt>) + Option& operator=(Opt&& value) noexcept; + template + 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; + ::std::int32_t const* $static crubit_nonnull* some_ptr() noexcept { + return reinterpret_cast<::std::int32_t const * $static crubit_nonnull*>( + storage_); + } + ::std::int32_t const* $static crubit_nonnull const* some_const_ptr() + const noexcept { + return reinterpret_cast<::std::int32_t const * + $static crubit_nonnull const*>(storage_); + } + void set_some_tag() noexcept {} + 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_[8]; +}; +#endif + +#ifndef _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000003e +template <> +struct alignas(4) CRUBIT_INTERNAL_RUST_TYPE( + "std :: option :: Option < i32 >") rs_std::Option<::std::int32_t> + : public rs_std::OptionBase, + ::std::int32_t> { + 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, ::std::int32_t>; + constexpr Option() = default; + constexpr Option(::std::nullopt_t) noexcept; + constexpr Option& operator=(::std::nullopt_t) noexcept; + template + requires(rs_std::OptionForwardConstructible) + Option(U&& value) noexcept; + template + requires(rs_std::OptionForwardConstructible) + Option& operator=(U&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional<::std::int32_t, Opt>) + Option(Opt&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional<::std::int32_t, Opt>) + Option& operator=(Opt&& value) noexcept; + template + explicit Option(::std::in_place_t ip, Args&&... args) noexcept; + ~Option() noexcept = default; + + private: + friend base_type; + using tag_type = ::std::uint32_t; + static constexpr tag_type kNoneVal = 0; + ::std::int32_t* some_ptr() noexcept { + return reinterpret_cast<::std::int32_t*>(storage_ + 4); + } + ::std::int32_t const* some_const_ptr() const noexcept { + return reinterpret_cast<::std::int32_t const*>(storage_ + 4); + } + 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::uint32_t tag() const& noexcept; + constexpr void set_tag(::std::uint32_t tag) noexcept; + + private: + unsigned char storage_[8]; +}; +#endif + +#ifndef _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020stdlib_x00000020_x0000003a_x0000003a_x00000020NonCloneableValue_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020stdlib_x00000020_x0000003a_x0000003a_x00000020NonCloneableValue_x00000020_x0000003e +template <> +struct alignas(4) CRUBIT_INTERNAL_RUST_TYPE( + "std :: option :: Option < :: stdlib_golden :: NonCloneableValue >") + rs_std::Option<::stdlib::NonCloneableValue> + : public rs_std::OptionBase, + ::stdlib::NonCloneableValue> { + public: + // `core::option::Option` doesn't implement the `Clone` trait + Option(const Option&) = delete; + Option& operator=(const Option&) = delete; + Option(Option&&) = default; + Option& operator=(Option&&) = default; + + Option(::crubit::UnsafeRelocateTag, Option&& value); + using base_type = + rs_std::OptionBase, + ::stdlib::NonCloneableValue>; + constexpr Option() = default; + constexpr Option(::std::nullopt_t) noexcept; + constexpr Option& operator=(::std::nullopt_t) noexcept; + template + requires(rs_std::OptionForwardConstructible) + Option(U&& value) noexcept; + template + requires(rs_std::OptionForwardConstructible) + Option& operator=(U&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional<::stdlib::NonCloneableValue, Opt>) + Option(Opt&& value) noexcept; + template + requires(rs_std::OptionFromStdOptional<::stdlib::NonCloneableValue, Opt>) + Option& operator=(Opt&& value) noexcept; + template + explicit Option(::std::in_place_t ip, Args&&... args) noexcept; + ~Option() noexcept = default; + + private: + friend base_type; + using tag_type = ::std::uint32_t; + static constexpr tag_type kNoneVal = 0; + ::stdlib::NonCloneableValue* some_ptr() noexcept { + return reinterpret_cast<::stdlib::NonCloneableValue*>(storage_ + 4); + } + ::stdlib::NonCloneableValue const* some_const_ptr() const noexcept { + return reinterpret_cast<::stdlib::NonCloneableValue const*>(storage_ + 4); + } + 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::uint32_t tag() const& noexcept; + constexpr void set_tag(::std::uint32_t tag) noexcept; + + private: + unsigned char storage_[8]; +}; +#endif namespace stdlib { @@ -394,22 +581,18 @@ namespace stdlib { namespace __crubit_internal { extern "C" void __crubit_thunk_Iterator_unext_ustdlib_ugolden_x0000003a_x0000003aMyStruct( - ::stdlib::MyStruct&, unsigned char* __ret_ptr); + ::stdlib::MyStruct&, rs_std::Option<::std::int32_t>* __ret_ptr); } } // namespace stdlib -inline ::std::optional<::std::int32_t> +inline rs_std::Option<::std::int32_t> rs_std::impl<::stdlib::MyStruct, ::rs::core::iter::Iterator>::next( ::stdlib::MyStruct& self) { - unsigned char __return_value_storage - [::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>::kSize]; + crubit::Slot> __return_value_ret_val_holder; + auto* __return_value_storage = __return_value_ret_val_holder.Get(); stdlib::__crubit_internal:: __crubit_thunk_Iterator_unext_ustdlib_ugolden_x0000003a_x0000003aMyStruct( self, __return_value_storage); - return ::crubit::internal::Decode< - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>>( - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>( - ::crubit::TransmuteAbi<::std::int32_t>()), - __return_value_storage); + return ::std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); } namespace stdlib { @@ -434,48 +617,268 @@ namespace stdlib { namespace __crubit_internal { extern "C" void __crubit_thunk_Iterator_unext_ustdlib_ugolden_x0000003a_x0000003aNonCloneableIterator( - ::stdlib::NonCloneableIterator&, unsigned char* __ret_ptr); + ::stdlib::NonCloneableIterator&, + rs_std::Option<::stdlib::NonCloneableValue>* __ret_ptr); } } // namespace stdlib -inline ::std::optional<::stdlib::NonCloneableValue> +inline rs_std::Option<::stdlib::NonCloneableValue> rs_std::impl<::stdlib::NonCloneableIterator, ::rs::core::iter::Iterator>::next( ::stdlib::NonCloneableIterator& self) { - unsigned char __return_value_storage[::crubit::OptionAbi< - ::crubit::TransmuteAbi<::stdlib::NonCloneableValue>>::kSize]; + crubit::Slot> + __return_value_ret_val_holder; + auto* __return_value_storage = __return_value_ret_val_holder.Get(); stdlib::__crubit_internal:: __crubit_thunk_Iterator_unext_ustdlib_ugolden_x0000003a_x0000003aNonCloneableIterator( self, __return_value_storage); - return ::crubit::internal::Decode< - ::crubit::OptionAbi<::crubit::TransmuteAbi<::stdlib::NonCloneableValue>>>( - ::crubit::OptionAbi<::crubit::TransmuteAbi<::stdlib::NonCloneableValue>>( - ::crubit::TransmuteAbi<::stdlib::NonCloneableValue>()), - __return_value_storage); + return ::std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); } namespace stdlib { namespace __crubit_internal { extern "C" void __crubit_thunk_Iterator_unext_ustdlib_ugolden_x0000003a_x0000003aRefIterator_x0000003c_x00000027a_x0000003e( - ::stdlib::RefIterator&, unsigned char* __ret_ptr); + ::stdlib::RefIterator&, + rs_std::Option<::std::int32_t const * $static crubit_nonnull>* __ret_ptr); } } // namespace stdlib -inline ::std::optional<::std::int32_t const * $a crubit_nonnull> +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull> rs_std::impl<::stdlib::RefIterator, ::rs::core::iter::Iterator>::next( ::stdlib::RefIterator& self) { - unsigned char - __return_value_storage[::crubit::OptionAbi<::crubit::TransmuteAbi< - ::std::int32_t const * $static crubit_nonnull>>::kSize]; + crubit::Slot> + __return_value_ret_val_holder; + auto* __return_value_storage = __return_value_ret_val_holder.Get(); stdlib::__crubit_internal:: __crubit_thunk_Iterator_unext_ustdlib_ugolden_x0000003a_x0000003aRefIterator_x0000003c_x00000027a_x0000003e( self, __return_value_storage); - return ::crubit::internal::Decode<::crubit::OptionAbi< - ::crubit::TransmuteAbi<::std::int32_t const * $static crubit_nonnull>>>( - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t const * - $static crubit_nonnull>>( - ::crubit::TransmuteAbi<::std::int32_t const * - $static crubit_nonnull>()), - __return_value_storage); + return ::std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); +} + +#ifndef _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020const_x00000020_x0000002a_x00000020_d_x00000020static_x00000020crubit_unonnull_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020const_x00000020_x0000002a_x00000020_d_x00000020static_x00000020crubit_unonnull_x00000020_x0000003e +static_assert(::std::is_trivially_copy_constructible_v< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>>); +static_assert(::std::is_trivially_copy_assignable_v< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>>); +static_assert(::std::is_trivially_move_constructible_v< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>>); +static_assert(::std::is_trivially_move_assignable_v< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>>); +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull>::Option( + ::crubit::UnsafeRelocateTag, Option&& value) { + ::std::memcpy(this, &value, sizeof(value)); +} +static_assert(::std::is_trivially_destructible_v< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>>); +inline constexpr ::std::uint64_t rs_std::Option< + ::std::int32_t const * $static crubit_nonnull>::tag() const& noexcept { + ::std::array __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<::std::int32_t const * $static crubit_nonnull>::set_tag( + ::std::uint64_t tag) noexcept { + auto __bytes = + ::std::bit_cast<::std::array>( + tag); + for (::std::size_t i = 0; i < sizeof(::std::uint64_t); ++i) { + storage_[0 + i] = __bytes[i]; + } +} + +inline constexpr rs_std::Option<::std::int32_t const * $static crubit_nonnull>:: + Option(::std::nullopt_t) noexcept + : base_type(::std::nullopt) {} +inline constexpr rs_std::Option<::std::int32_t const * $static crubit_nonnull>& +rs_std::Option<::std::int32_t const * $static crubit_nonnull>::operator=( + ::std::nullopt_t) noexcept { + base_type::operator=(::std::nullopt); + return *this; +} +template + requires(rs_std::OptionForwardConstructible< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>, + ::std::int32_t const * $static crubit_nonnull, U>) +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull>::Option( + U&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionForwardConstructible< + rs_std::Option<::std::int32_t const * $static crubit_nonnull>, + ::std::int32_t const * $static crubit_nonnull, U>) +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull>& +rs_std::Option<::std::int32_t const * $static crubit_nonnull>::operator=( + U&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template + requires(rs_std::OptionFromStdOptional< + ::std::int32_t const * $static crubit_nonnull, Opt>) +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull>::Option( + Opt&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionFromStdOptional< + ::std::int32_t const * $static crubit_nonnull, Opt>) +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull>& +rs_std::Option<::std::int32_t const * $static crubit_nonnull>::operator=( + Opt&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template +inline rs_std::Option<::std::int32_t const * $static crubit_nonnull>::Option( + ::std::in_place_t ip, Args&&... args) noexcept + : base_type(ip, ::std::forward(args)...) {} + +#endif + +#ifndef _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000003e +static_assert( + ::std::is_trivially_copy_constructible_v>); +static_assert( + ::std::is_trivially_copy_assignable_v>); +static_assert( + ::std::is_trivially_move_constructible_v>); +static_assert( + ::std::is_trivially_move_assignable_v>); +inline rs_std::Option<::std::int32_t>::Option(::crubit::UnsafeRelocateTag, + Option&& value) { + ::std::memcpy(this, &value, sizeof(value)); +} +static_assert( + ::std::is_trivially_destructible_v>); +inline constexpr ::std::uint32_t rs_std::Option<::std::int32_t>::tag() + const& noexcept { + ::std::array __bytes = {}; + for (::std::size_t i = 0; i < sizeof(::std::uint32_t); ++i) { + __bytes[i] = storage_[0 + i]; + } + return ::std::bit_cast<::std::uint32_t>(__bytes); +} +inline constexpr void rs_std::Option<::std::int32_t>::set_tag( + ::std::uint32_t tag) noexcept { + auto __bytes = + ::std::bit_cast<::std::array>( + tag); + for (::std::size_t i = 0; i < sizeof(::std::uint32_t); ++i) { + storage_[0 + i] = __bytes[i]; + } } +inline constexpr rs_std::Option<::std::int32_t>::Option( + ::std::nullopt_t) noexcept + : base_type(::std::nullopt) {} +inline constexpr rs_std::Option<::std::int32_t>& +rs_std::Option<::std::int32_t>::operator=(::std::nullopt_t) noexcept { + base_type::operator=(::std::nullopt); + return *this; +} +template + requires(rs_std::OptionForwardConstructible, + ::std::int32_t, U>) +inline rs_std::Option<::std::int32_t>::Option(U&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionForwardConstructible, + ::std::int32_t, U>) +inline rs_std::Option<::std::int32_t>& +rs_std::Option<::std::int32_t>::operator=(U&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template + requires(rs_std::OptionFromStdOptional<::std::int32_t, Opt>) +inline rs_std::Option<::std::int32_t>::Option(Opt&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionFromStdOptional<::std::int32_t, Opt>) +inline rs_std::Option<::std::int32_t>& +rs_std::Option<::std::int32_t>::operator=(Opt&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template +inline rs_std::Option<::std::int32_t>::Option(::std::in_place_t ip, + Args&&... args) noexcept + : base_type(ip, ::std::forward(args)...) {} + +#endif + +#ifndef _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020stdlib_x00000020_x0000003a_x0000003a_x00000020NonCloneableValue_x00000020_x0000003e +#define _CRUBIT_BINDINGS_FOR_IMPL_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Option_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020stdlib_x00000020_x0000003a_x0000003a_x00000020NonCloneableValue_x00000020_x0000003e +static_assert(::std::is_trivially_move_constructible_v< + rs_std::Option<::stdlib::NonCloneableValue>>); +static_assert(::std::is_trivially_move_assignable_v< + rs_std::Option<::stdlib::NonCloneableValue>>); +inline rs_std::Option<::stdlib::NonCloneableValue>::Option( + ::crubit::UnsafeRelocateTag, Option&& value) { + ::std::memcpy(this, &value, sizeof(value)); +} +static_assert(::std::is_trivially_destructible_v< + rs_std::Option<::stdlib::NonCloneableValue>>); +inline constexpr ::std::uint32_t +rs_std::Option<::stdlib::NonCloneableValue>::tag() const& noexcept { + ::std::array __bytes = {}; + for (::std::size_t i = 0; i < sizeof(::std::uint32_t); ++i) { + __bytes[i] = storage_[0 + i]; + } + return ::std::bit_cast<::std::uint32_t>(__bytes); +} +inline constexpr void rs_std::Option<::stdlib::NonCloneableValue>::set_tag( + ::std::uint32_t tag) noexcept { + auto __bytes = + ::std::bit_cast<::std::array>( + tag); + for (::std::size_t i = 0; i < sizeof(::std::uint32_t); ++i) { + storage_[0 + i] = __bytes[i]; + } +} + +inline constexpr rs_std::Option<::stdlib::NonCloneableValue>::Option( + ::std::nullopt_t) noexcept + : base_type(::std::nullopt) {} +inline constexpr rs_std::Option<::stdlib::NonCloneableValue>& rs_std::Option< + ::stdlib::NonCloneableValue>::operator=(::std::nullopt_t) noexcept { + base_type::operator=(::std::nullopt); + return *this; +} +template + requires(rs_std::OptionForwardConstructible< + rs_std::Option<::stdlib::NonCloneableValue>, + ::stdlib::NonCloneableValue, U>) +inline rs_std::Option<::stdlib::NonCloneableValue>::Option(U&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionForwardConstructible< + rs_std::Option<::stdlib::NonCloneableValue>, + ::stdlib::NonCloneableValue, U>) +inline rs_std::Option<::stdlib::NonCloneableValue>& +rs_std::Option<::stdlib::NonCloneableValue>::operator=(U&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template + requires(rs_std::OptionFromStdOptional<::stdlib::NonCloneableValue, Opt>) +inline rs_std::Option<::stdlib::NonCloneableValue>::Option(Opt&& value) noexcept + : base_type(::std::forward(value)) {} +template + requires(rs_std::OptionFromStdOptional<::stdlib::NonCloneableValue, Opt>) +inline rs_std::Option<::stdlib::NonCloneableValue>& +rs_std::Option<::stdlib::NonCloneableValue>::operator=(Opt&& value) noexcept { + base_type::operator=(::std::forward(value)); + return *this; +} +template +inline rs_std::Option<::stdlib::NonCloneableValue>::Option( + ::std::in_place_t ip, Args&&... args) noexcept + : base_type(ip, ::std::forward(args)...) {} + +#endif + #pragma clang diagnostic pop #endif // THIRD_PARTY_CRUBIT_CC_BINDINGS_FROM_RS_TEST_TRAITS_STDLIB_STDLIB_GOLDEN diff --git a/cc_bindings_from_rs/test/traits/stdlib/stdlib_cc_api_impl.rs b/cc_bindings_from_rs/test/traits/stdlib/stdlib_cc_api_impl.rs index bf029db59..074598bba 100644 --- a/cc_bindings_from_rs/test/traits/stdlib/stdlib_cc_api_impl.rs +++ b/cc_bindings_from_rs/test/traits/stdlib/stdlib_cc_api_impl.rs @@ -94,17 +94,11 @@ const _: () = assert!(::core::mem::offset_of!(::stdlib_golden::RefIterator, inde #[unsafe(no_mangle)] unsafe extern "C" fn __crubit_thunk_Iterator_unext_ustdlib_ugolden_x0000003a_x0000003aMyStruct( __self: &'static mut ::stdlib_golden::MyStruct, - __ret_ptr: *mut core::ffi::c_uchar, + __ret_ptr: *mut core::ffi::c_void, ) -> () { unsafe { let __rs_return_value = <::stdlib_golden::MyStruct as ::core::iter::Iterator>::next(__self); - unsafe { - ::bridge_rust::internal::encode( - ::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::()), - __ret_ptr as *mut core::ffi::c_uchar, - __rs_return_value, - ); - } + (__ret_ptr as *mut ::core::option::Option).write(__rs_return_value); } } #[unsafe(no_mangle)] @@ -121,36 +115,23 @@ unsafe extern "C" fn __crubit_thunk_ToString_uto_ustring_ustdlib_ugolden_x000000 #[unsafe(no_mangle)] unsafe extern "C" fn __crubit_thunk_Iterator_unext_ustdlib_ugolden_x0000003a_x0000003aNonCloneableIterator( __self: &'static mut ::stdlib_golden::NonCloneableIterator, - __ret_ptr: *mut core::ffi::c_uchar, + __ret_ptr: *mut core::ffi::c_void, ) -> () { unsafe { let __rs_return_value = <::stdlib_golden::NonCloneableIterator as ::core::iter::Iterator>::next(__self); - unsafe { - ::bridge_rust::internal::encode( - ::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::< - ::stdlib_golden::NonCloneableValue, - >()), - __ret_ptr as *mut core::ffi::c_uchar, - __rs_return_value, - ); - } + (__ret_ptr as *mut ::core::option::Option<::stdlib_golden::NonCloneableValue>) + .write(__rs_return_value); } } #[unsafe(no_mangle)] unsafe extern "C" fn __crubit_thunk_Iterator_unext_ustdlib_ugolden_x0000003a_x0000003aRefIterator_x0000003c_x00000027a_x0000003e( __self: &'static mut ::stdlib_golden::RefIterator<'static>, - __ret_ptr: *mut core::ffi::c_uchar, + __ret_ptr: *mut core::ffi::c_void, ) -> () { unsafe { let __rs_return_value = <::stdlib_golden::RefIterator 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); } } diff --git a/cc_bindings_from_rs/test/tuples/tuples_cc_api.h b/cc_bindings_from_rs/test/tuples/tuples_cc_api.h index c5afc7052..7de913762 100644 --- a/cc_bindings_from_rs/test/tuples/tuples_cc_api.h +++ b/cc_bindings_from_rs/test/tuples/tuples_cc_api.h @@ -15,7 +15,6 @@ #pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma clang diagnostic ignored "-Wignored-attributes" #include "support/annotations_internal.h" -#include "support/bridge.h" #include "support/internal/memswap.h" #include "support/internal/slot.h" #include "support/lifetime_annotations.h" @@ -275,7 +274,7 @@ void param_nontrivial_drop_in_tuple( ::std::tuple<::tuples::NontrivialDrop> nontrivial_drop); // CRUBIT_ANNOTATE: must_bind= -void param_option_in_tuple(::std::tuple<::std::optional<::std::int32_t>> opt); +void param_option_in_tuple(::std::tuple> opt); // CRUBIT_ANNOTATE: must_bind= void param_triply_nested_tuple( @@ -304,10 +303,10 @@ return_nested_tuples(); ::std::tuple<::tuples::NontrivialDrop> return_new_nontrivial_drop_in_tuple(); // CRUBIT_ANNOTATE: must_bind= -::std::tuple<::std::optional<::std::int32_t>> return_option_in_tuple(); +::std::tuple> return_option_in_tuple(); // CRUBIT_ANNOTATE: must_bind= -::std::optional<::std::int32_t> return_option_in_tuple_ref( +rs_std::Option<::std::int32_t> return_option_in_tuple_ref( rs_std::Tuple> const& opt); // CRUBIT_ANNOTATE: must_bind= @@ -2148,16 +2147,9 @@ namespace __crubit_internal { extern "C" void __crubit_thunk_param_uoption_uin_utuple(void**); } inline void param_option_in_tuple( - ::std::tuple<::std::optional<::std::int32_t>> opt) { + ::std::tuple> opt) { auto&& opt_0 = ::std::get<0>(opt); - unsigned char opt_0_buffer - [::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>::kSize]; - ::crubit::internal::Encode< - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>>( - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>( - ::crubit::TransmuteAbi<::std::int32_t>()), - opt_0_buffer, ::std::move(opt_0)); - auto&& opt_cabi_0 = opt_0_buffer; + auto&& opt_cabi_0 = &opt_0; void* opt_cabi[] = {&opt_cabi_0}; return __crubit_internal::__crubit_thunk_param_uoption_uin_utuple(opt_cabi); } @@ -2260,36 +2252,28 @@ return_new_nontrivial_drop_in_tuple() { namespace __crubit_internal { extern "C" void __crubit_thunk_return_uoption_uin_utuple(void** __ret_ptr); } -inline ::std::tuple<::std::optional<::std::int32_t>> return_option_in_tuple() { - unsigned char __return_value_0_storage - [::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>::kSize]; +inline ::std::tuple> return_option_in_tuple() { + crubit::Slot> __return_value_0_ret_val_holder; + auto* __return_value_0_storage = __return_value_0_ret_val_holder.Get(); void* __return_value_storage[] = {__return_value_0_storage}; __crubit_internal::__crubit_thunk_return_uoption_uin_utuple( __return_value_storage); return ::std::make_tuple( - ::crubit::internal::Decode< - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>>( - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>( - ::crubit::TransmuteAbi<::std::int32_t>()), - __return_value_0_storage)); + ::std::move(__return_value_0_ret_val_holder).AssumeInitAndTakeValue()); } namespace __crubit_internal { extern "C" void __crubit_thunk_return_uoption_uin_utuple_uref( rs_std::Tuple> const&, - unsigned char* __ret_ptr); + rs_std::Option<::std::int32_t>* __ret_ptr); } -inline ::std::optional<::std::int32_t> return_option_in_tuple_ref( +inline rs_std::Option<::std::int32_t> return_option_in_tuple_ref( rs_std::Tuple> const& opt) { - unsigned char __return_value_storage - [::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>::kSize]; + crubit::Slot> __return_value_ret_val_holder; + auto* __return_value_storage = __return_value_ret_val_holder.Get(); __crubit_internal::__crubit_thunk_return_uoption_uin_utuple_uref( opt, __return_value_storage); - return ::crubit::internal::Decode< - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>>( - ::crubit::OptionAbi<::crubit::TransmuteAbi<::std::int32_t>>( - ::crubit::TransmuteAbi<::std::int32_t>()), - __return_value_storage); + return ::std::move(__return_value_ret_val_holder).AssumeInitAndTakeValue(); } namespace __crubit_internal { diff --git a/cc_bindings_from_rs/test/tuples/tuples_cc_api_impl.rs b/cc_bindings_from_rs/test/tuples/tuples_cc_api_impl.rs index 0e41e188f..ecdfdb729 100644 --- a/cc_bindings_from_rs/test/tuples/tuples_cc_api_impl.rs +++ b/cc_bindings_from_rs/test/tuples/tuples_cc_api_impl.rs @@ -355,14 +355,11 @@ unsafe extern "C" fn __crubit_thunk_param_uoption_uin_utuple( ) -> () { unsafe { let opt = ({ - let opt_0: *const core::ffi::c_uchar = - ((*opt)[0usize] as *const *const core::ffi::c_uchar).read(); - let opt_0 = unsafe { - ::bridge_rust::internal::decode( - ::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::()), - opt_0, - ) - }; + let opt_0: &'static mut ::core::mem::MaybeUninit<::core::option::Option> = ((*opt) + [0usize] + as *const &'static mut ::core::mem::MaybeUninit<::core::option::Option>) + .read(); + let opt_0 = opt_0.assume_init_read(); opt_0 },); ::tuples_golden::param_option_in_tuple(opt) @@ -458,29 +455,17 @@ unsafe extern "C" fn __crubit_thunk_return_uoption_uin_utuple( let __rs_return_value = ::tuples_golden::return_option_in_tuple(); let (__rs_return_value_0,) = __rs_return_value; let [__ret_ptr_0] = *(__ret_ptr as *mut [*mut core::ffi::c_void; 1usize]); - unsafe { - ::bridge_rust::internal::encode( - ::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::()), - __ret_ptr_0 as *mut core::ffi::c_uchar, - __rs_return_value_0, - ); - } + (__ret_ptr_0 as *mut ::core::option::Option).write(__rs_return_value_0); } } #[unsafe(no_mangle)] unsafe extern "C" fn __crubit_thunk_return_uoption_uin_utuple_uref( opt: &'static (::core::option::Option,), - __ret_ptr: *mut core::ffi::c_uchar, + __ret_ptr: *mut core::ffi::c_void, ) -> () { unsafe { let __rs_return_value = ::tuples_golden::return_option_in_tuple_ref(opt); - unsafe { - ::bridge_rust::internal::encode( - ::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::()), - __ret_ptr as *mut core::ffi::c_uchar, - __rs_return_value, - ); - } + (__ret_ptr as *mut ::core::option::Option).write(__rs_return_value); } } #[unsafe(no_mangle)] @@ -606,13 +591,7 @@ unsafe extern "C" fn __crubit_thunk_Clone_uclone_u_x00000028std_x0000003a_x00000 ) as ::core::clone::Clone>::clone(__self); let (__rs_return_value_0, __rs_return_value_1) = __rs_return_value; let [__ret_ptr_0, __ret_ptr_1] = *(__ret_ptr as *mut [*mut core::ffi::c_void; 2usize]); - unsafe { - ::bridge_rust::internal::encode( - ::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::()), - __ret_ptr_0 as *mut core::ffi::c_uchar, - __rs_return_value_0, - ); - } + (__ret_ptr_0 as *mut ::core::option::Option).write(__rs_return_value_0); (__ret_ptr_1 as *mut ::core::result::Result) .write(__rs_return_value_1); } @@ -641,13 +620,7 @@ unsafe extern "C" fn __crubit_thunk_Default_udefault_u_x00000028std_x0000003a_x0 <(::core::option::Option,) as ::core::default::Default>::default(); let (__rs_return_value_0,) = __rs_return_value; let [__ret_ptr_0] = *(__ret_ptr as *mut [*mut core::ffi::c_void; 1usize]); - unsafe { - ::bridge_rust::internal::encode( - ::bridge_rust::OptionAbi(::bridge_rust::transmute_abi::()), - __ret_ptr_0 as *mut core::ffi::c_uchar, - __rs_return_value_0, - ); - } + (__ret_ptr_0 as *mut ::core::option::Option).write(__rs_return_value_0); } } #[unsafe(no_mangle)] diff --git a/features/global_features.bzl b/features/global_features.bzl index 21b6b7145..f3c44a9ac 100644 --- a/features/global_features.bzl +++ b/features/global_features.bzl @@ -9,6 +9,7 @@ visibility(["//..."]) SUPPORTED_FEATURES = [ "supported", "assume_lifetimes", + "always_specialize_generics_in_cpp_api_from_rust", ] # A list of targets that should not be granted the `assume_lifetimes` feature by default.