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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

use crate::generate_function_thunk::replace_all_regions_with_static;
use crate::generate_function_thunk::{make_thunk_name, replace_all_regions_with_static, ThunkKind};
use crate::generate_struct_and_union::{
generate_associated_item, generate_relocating_ctor, has_type_or_const_vars,
scalar_value_to_string,
Expand Down Expand Up @@ -900,15 +900,19 @@ fn specialize_vec<'tcx>(
.unwrap_or_else(|err| err.explicitly_deleted);
let relocating_ctor_snippets = generate_relocating_ctor(db, &core.cc_short_name);

let target_path_mangled_hash = if db.is_golden_test() {
"".to_string()
} else {
format!("{:x}_", tcx.stable_crate_id(db.source_crate_num()))
};

let qualified_name = cc_fully_qualified_name.to_string();
let name = escape_non_identifier_chars(&qualified_name);
let drop_thunk_name = format_ident!("__crubit_drop_{}{}", target_path_mangled_hash, name);
let drop_trait = tcx.lang_items().drop_trait().expect("Could not find Drop trait");
let drop_assoc_fn = tcx
.associated_items(drop_trait)
.in_definition_order()
.find(|item| matches!(item.kind, ty::AssocKind::Fn { .. }))
.expect("Drop should have a method");
let substs = tcx.mk_args_trait(rs_std.self_ty_rs, std::iter::empty());
let drop_thunk_name = format_ident!(
"{}",
make_thunk_name(db, ThunkKind::TraitMethod { method: drop_assoc_fn, substs })
);

let rs_drop = quote! {
#[unsafe(no_mangle)]
Expand Down
4 changes: 2 additions & 2 deletions cc_bindings_from_rs/test/known_traits/index/rs_index_cc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,10 @@ rs_std::Vec<::rs::alloc::string::String>::operator=(Vec&& other) {
return *this;
}
extern "C" void
__crubit_drop_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Vec_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020rs_x00000020_x0000003a_x0000003a_x00000020alloc_x00000020_x0000003a_x0000003a_x00000020string_x00000020_x0000003a_x0000003a_x00000020String_x00000020_x0000003e(
__crubit_thunk_Drop_udrop_ustd_x0000003a_x0000003avec_x0000003a_x0000003aVec_x0000003cstd_x0000003a_x0000003astring_x0000003a_x0000003aString_x0000003e(
void* vec) noexcept;
inline rs_std::Vec<::rs::alloc::string::String>::~Vec() noexcept {
__crubit_drop_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Vec_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020rs_x00000020_x0000003a_x0000003a_x00000020alloc_x00000020_x0000003a_x0000003a_x00000020string_x00000020_x0000003a_x0000003a_x00000020String_x00000020_x0000003e(
__crubit_thunk_Drop_udrop_ustd_x0000003a_x0000003avec_x0000003a_x0000003aVec_x0000003cstd_x0000003a_x0000003astring_x0000003a_x0000003aString_x0000003e(
this);
}
inline ::rs::alloc::string::String*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ unsafe extern "C" fn __crubit_thunk_Clone_uclone_ufrom_ustd_x0000003a_x0000003av
}
}
#[unsafe(no_mangle)]
unsafe extern "C" fn __crubit_drop_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Vec_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020rs_x00000020_x0000003a_x0000003a_x00000020alloc_x00000020_x0000003a_x0000003a_x00000020string_x00000020_x0000003a_x0000003a_x00000020String_x00000020_x0000003e(
unsafe extern "C" fn __crubit_thunk_Drop_udrop_ustd_x0000003a_x0000003avec_x0000003a_x0000003aVec_x0000003cstd_x0000003a_x0000003astring_x0000003a_x0000003aString_x0000003e(
vec: *mut ::alloc::vec::Vec<::alloc::string::String>,
) {
unsafe { ::core::ptr::drop_in_place(vec) };
Expand Down
8 changes: 4 additions & 4 deletions cc_bindings_from_rs/test/vec/vec_cc_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ inline rs_std::Vec<::std::int32_t>& rs_std::Vec<::std::int32_t>::operator=(
return *this;
}
extern "C" void
__crubit_drop_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Vec_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000003e(
__crubit_thunk_Drop_udrop_ustd_x0000003a_x0000003avec_x0000003a_x0000003aVec_x0000003ci32_x0000003e(
void* vec) noexcept;
inline rs_std::Vec<::std::int32_t>::~Vec() noexcept {
__crubit_drop_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Vec_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000003e(
__crubit_thunk_Drop_udrop_ustd_x0000003a_x0000003avec_x0000003a_x0000003aVec_x0000003ci32_x0000003e(
this);
}
inline ::std::int32_t* rs_std::Vec<::std::int32_t>::data() noexcept {
Expand Down Expand Up @@ -341,10 +341,10 @@ inline rs_std::Vec<::std::uint8_t>& rs_std::Vec<::std::uint8_t>::operator=(
return *this;
}
extern "C" void
__crubit_drop_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Vec_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020uint8_ut_x00000020_x0000003e(
__crubit_thunk_Drop_udrop_ustd_x0000003a_x0000003avec_x0000003a_x0000003aVec_x0000003cu8_x0000003e(
void* vec) noexcept;
inline rs_std::Vec<::std::uint8_t>::~Vec() noexcept {
__crubit_drop_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Vec_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020uint8_ut_x00000020_x0000003e(
__crubit_thunk_Drop_udrop_ustd_x0000003a_x0000003avec_x0000003a_x0000003aVec_x0000003cu8_x0000003e(
this);
}
inline ::std::uint8_t* rs_std::Vec<::std::uint8_t>::data() noexcept {
Expand Down
4 changes: 2 additions & 2 deletions cc_bindings_from_rs/test/vec/vec_cc_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ unsafe extern "C" fn __crubit_thunk_Clone_uclone_ufrom_ustd_x0000003a_x0000003av
unsafe { <::alloc::vec::Vec<i32> as ::core::clone::Clone>::clone_from(__self, source) }
}
#[unsafe(no_mangle)]
unsafe extern "C" fn __crubit_drop_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Vec_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020int32_ut_x00000020_x0000003e(
unsafe extern "C" fn __crubit_thunk_Drop_udrop_ustd_x0000003a_x0000003avec_x0000003a_x0000003aVec_x0000003ci32_x0000003e(
vec: *mut ::alloc::vec::Vec<i32>,
) {
unsafe { ::core::ptr::drop_in_place(vec) };
Expand Down Expand Up @@ -109,7 +109,7 @@ unsafe extern "C" fn __crubit_thunk_Clone_uclone_ufrom_ustd_x0000003a_x0000003av
unsafe { <::alloc::vec::Vec<u8> as ::core::clone::Clone>::clone_from(__self, source) }
}
#[unsafe(no_mangle)]
unsafe extern "C" fn __crubit_drop_rs_ustd_x00000020_x0000003a_x0000003a_x00000020Vec_x00000020_x0000003c_x00000020_x0000003a_x0000003a_x00000020std_x00000020_x0000003a_x0000003a_x00000020uint8_ut_x00000020_x0000003e(
unsafe extern "C" fn __crubit_thunk_Drop_udrop_ustd_x0000003a_x0000003avec_x0000003a_x0000003aVec_x0000003cu8_x0000003e(
vec: *mut ::alloc::vec::Vec<u8>,
) {
unsafe { ::core::ptr::drop_in_place(vec) };
Expand Down