diff --git a/docs/bindings/reference/primitive_scalar_types.md b/docs/bindings/reference/primitive_scalar_types.md index 050b5e53..5d6bb2e2 100644 --- a/docs/bindings/reference/primitive_scalar_types.md +++ b/docs/bindings/reference/primitive_scalar_types.md @@ -30,35 +30,32 @@ The C++ types below are mapped one-way into the corresponding Rust types. ("one-way" means that the type doesn't round-trip - for example `size_t` maps to `usize`, but `usize` maps to `uintptr_t`.) -C++ | Rust ------------ | ------- -`ptrdiff_t` | `isize` -`size_t` | `usize` -`char16_t` | `u16` -`char32_t` | `u32` -`wchar_t` | `i32` - -### Platform-specific map - -TODO(b/276790180): These will eventually become `ffi::c_char`, `ffi::c_int`, -etc. - -The following C++ types are mapped in a platform-dependent way to the -corresponding Rust type of the same width and signedness: - -C++ | Rust --------------------- | ----------------------- -`char` | `i8` or `u8`, or higher -`signed char` | `i8` or higher -`unsigned char` | `u8` or higher -`short` | `i16` or higher -`unsigned short` | `u16` or higher -`int` | `i16` or higher -`unsigned int` | `u16` or higher -`long` | `i32` or higher -`unsigned long` | `u32` or higher -`long long` | `i64` -`unsigned long long` | `u64` +TODO(b/283258442): `::core::ffi::*` should eventually be a bidirectional mapping + +| C++ | Rust | Notes | +| -------------------- | -------------------------- | ------------------------ | +| `ptrdiff_t` | `isize` | | +| `size_t` | `usize` | | +| `char16_t` | `u16` | | +| `char32_t` | `u32` | Unlike `rs_std::rs_char` | +: : : above, `char32_t` may : +: : : contain invalid Unicode : +: : : characters : +| `wchar_t` | `i32` | TODO(b/283268558): This | +: : : is wrong on Windows. : +| `char` | `u8` or `i8` depending on | TODO(b/276790180): This | +: : whether `char` is signed : may eventually become : +: : on the target platform : `c_char` : +| `signed char` | `::core::ffi::c_schar` | | +| `unsigned char` | `::core::ffi::c_uchar` | | +| `short` | `::core::ffi::c_short` | | +| `unsigned short` | `::core::ffi::c_ushort` | | +| `int` | `::core::ffi::c_int` | | +| `unsigned int` | `::core::ffi::c_uint` | | +| `long` | `::core::ffi::c_long` | | +| `unsigned long` | `::core::ffi::c_ulong` | | +| `long long` | `::core::ffi::c_longlong` | | +| `unsigned long long` | `::core::ffi::c_ulonglong` | | ## Unsupported types diff --git a/rs_bindings_from_cc/importer.cc b/rs_bindings_from_cc/importer.cc index 85f723a7..cf26d263 100644 --- a/rs_bindings_from_cc/importer.cc +++ b/rs_bindings_from_cc/importer.cc @@ -837,30 +837,52 @@ absl::StatusOr Importer::ConvertType( switch (builtin_type->getKind()) { case clang::BuiltinType::Bool: return MappedType::Simple("bool", "bool"); - break; + case clang::BuiltinType::Void: + return MappedType::Void(); + + // Floating-point numbers + // + // TODO(b/255768062): Generated bindings should explicitly check if + // `math.h` defines the `__STDC_IEC_559__` macro. case clang::BuiltinType::Float: - // TODO(b/255768062): Generated bindings should explicitly check if - // `math.h` defines the `__STDC_IEC_559__` macro. return MappedType::Simple("f32", "float"); - break; case clang::BuiltinType::Double: - // TODO(b/255768062): Generated bindings should explicitly check if - // `math.h` defines the `__STDC_IEC_559__` macro. return MappedType::Simple("f64", "double"); - break; - case clang::BuiltinType::Void: - return MappedType::Void(); - break; + + // `char` + case clang::BuiltinType::Char_S: // 'char' in targets where it's signed + // TODO(b/276790180, b/276931370): use `::core::ffi::c_char` instead. + return MappedType::Simple("i8", "char"); + case clang::BuiltinType::Char_U: // 'char' in targets where it's unsigned + // TODO(b/276790180, b/276931370): use `::core::ffi::c_char` instead. + return MappedType::Simple("u8", "char"); + case clang::BuiltinType::SChar: // 'signed char', explicitly qualified + return MappedType::Simple("::core::ffi::c_schar", "signed char"); + case clang::BuiltinType::UChar: // 'unsigned char', explicitly qualified + return MappedType::Simple("::core::ffi::c_uchar", "unsigned char"); + + // Signed integers + case clang::BuiltinType::Short: + return MappedType::Simple("::core::ffi::c_short", "short"); + case clang::BuiltinType::Int: + return MappedType::Simple("::core::ffi::c_int", "int"); + case clang::BuiltinType::Long: + return MappedType::Simple("::core::ffi::c_long", "long"); + case clang::BuiltinType::LongLong: + return MappedType::Simple("::core::ffi::c_longlong", "long long"); + + // Unsigned integers + case clang::BuiltinType::UShort: + return MappedType::Simple("::core::ffi::c_ushort", "unsigned short"); + case clang::BuiltinType::UInt: + return MappedType::Simple("::core::ffi::c_uint", "unsigned int"); + case clang::BuiltinType::ULong: + return MappedType::Simple("::core::ffi::c_ulong", "unsigned long"); + case clang::BuiltinType::ULongLong: + return MappedType::Simple("::core::ffi::c_ulonglong", + "unsigned long long"); default: - if (builtin_type->isIntegerType()) { - auto size = ctx_.getTypeSize(builtin_type); - if (size == 8 || size == 16 || size == 32 || size == 64) { - return MappedType::Simple( - absl::Substitute( - "$0$1", builtin_type->isSignedInteger() ? 'i' : 'u', size), - type_string); - } - } + break; } } else if (const auto* tag_type = type->getAsAdjusted()) { return ConvertTypeDecl(tag_type->getDecl()); diff --git a/rs_bindings_from_cc/importer_test.cc b/rs_bindings_from_cc/importer_test.cc index 4858cb6e..95cb3324 100644 --- a/rs_bindings_from_cc/importer_test.cc +++ b/rs_bindings_from_cc/importer_test.cc @@ -185,7 +185,9 @@ auto CcTypeParamsAre(const Args&... matchers) { auto IsCcInt() { return AllOf(NameIs("int"), CcTypeParamsAre()); } -auto IsRsInt() { return AllOf(NameIs("i32"), RsTypeParamsAre()); } +auto IsRsInt() { + return AllOf(NameIs("::core::ffi::c_int"), RsTypeParamsAre()); +} // Matches a CcType that is a pointer to a type matching `matcher`. template diff --git a/rs_bindings_from_cc/ir.h b/rs_bindings_from_cc/ir.h index 213d932a..a24c3b7e 100644 --- a/rs_bindings_from_cc/ir.h +++ b/rs_bindings_from_cc/ir.h @@ -185,7 +185,7 @@ struct RsType { llvm::json::Value ToJson() const; // The name of the type. Examples: - // - "i32" or "bool" + // - "i32" or "bool" or "::core::ffi::c_int" // - "()" (the unit type, equivalent of "void" in CcType) // - "&", "&mut", "*const", "*mut" (pointee stored in `type_args[0]`) // - "Option" (e.g. representing nullable, lifetime-annotated C++ pointer as diff --git a/rs_bindings_from_cc/ir_from_cc_test.rs b/rs_bindings_from_cc/ir_from_cc_test.rs index 2f8ba926..e6341fee 100644 --- a/rs_bindings_from_cc/ir_from_cc_test.rs +++ b/rs_bindings_from_cc/ir_from_cc_test.rs @@ -33,7 +33,7 @@ fn test_function() { doc_comment: None, return_type: MappedType { rs_type: RsType { - name: Some("i32"), + name: Some("::core::ffi::c_int"), lifetime_args: [], type_args: [], decl_id: None, @@ -49,7 +49,7 @@ fn test_function() { FuncParam { type_: MappedType { rs_type: RsType { - name: Some("i32"), + name: Some("::core::ffi::c_int"), lifetime_args: [], type_args: [], decl_id: None, @@ -66,7 +66,7 @@ fn test_function() { FuncParam { type_: MappedType { rs_type: RsType { - name: Some("i32"), + name: Some("::core::ffi::c_int"), lifetime_args: [], type_args: [], decl_id: None, @@ -399,7 +399,7 @@ fn test_bitfields() { Field { identifier: Some("b1"), ... type_: Ok(MappedType { - rs_type: RsType { name: Some("i32"), ... }, + rs_type: RsType { name: Some("::core::ffi::c_int"), ... }, cc_type: CcType { name: Some("int"), ... }, }), ... offset: 0, @@ -409,7 +409,7 @@ fn test_bitfields() { Field { identifier: Some("b2"), ... type_: Ok(MappedType { - rs_type: RsType { name: Some("i32"), ... }, + rs_type: RsType { name: Some("::core::ffi::c_int"), ... }, cc_type: CcType { name: Some("int"), ... }, }), ... offset: 1, @@ -419,7 +419,7 @@ fn test_bitfields() { Field { identifier: Some("b3"), ... type_: Ok(MappedType { - rs_type: RsType { name: Some("i32"), ... }, + rs_type: RsType { name: Some("::core::ffi::c_int"), ... }, cc_type: CcType { name: Some("int"), ... }, }), ... offset: 3, @@ -429,7 +429,7 @@ fn test_bitfields() { Field { identifier: Some("b4"), ... type_: Ok(MappedType { - rs_type: RsType { name: Some("i32"), ... }, + rs_type: RsType { name: Some("::core::ffi::c_int"), ... }, cc_type: CcType { name: Some("int"), ... }, }), ... offset: 16, @@ -909,37 +909,36 @@ fn test_type_conversion() -> Result<()> { assert_eq!(type_mapping["bool"], "bool"); - // TODO(b/276790180, b/276931370): use c_char instead. + // TODO(b/276790180, b/276931370): use `::core::ffi::c_char` instead. if multiplatform_testing::test_platform() == multiplatform_testing::Platform::X86Linux { assert_eq!(type_mapping["char"], "i8"); } else { assert_eq!(type_mapping["char"], "u8"); } + assert_eq!(type_mapping["unsigned char"], "::core::ffi::c_uchar"); + assert_eq!(type_mapping["signed char"], "::core::ffi::c_schar"); - assert_eq!(type_mapping["unsigned char"], "u8"); - assert_eq!(type_mapping["signed char"], "i8"); assert_eq!(type_mapping["char16_t"], "u16"); + // We cannot map C++ char32_t or wchar_t to Rust char, // because Rust requires that chars are valid UTF scalar values. assert_eq!(type_mapping["char32_t"], "u32"); - assert_eq!(type_mapping["wchar_t"], "i32"); - assert_eq!(type_mapping["short"], "i16"); - assert_eq!(type_mapping["int"], "i32"); - assert_eq!(type_mapping["long"], "i64"); - assert_eq!(type_mapping["long long"], "i64"); + // TODO(b/283268558): Per https://en.cppreference.com/w/cpp/language/types#Character_types + // maybe `wchar_t` should translate to`i16` on Windows? + assert_eq!(type_mapping["wchar_t"], "i32"); - assert_eq!(type_mapping["unsigned short"], "u16"); - assert_eq!(type_mapping["unsigned int"], "u32"); - assert_eq!(type_mapping["unsigned long"], "u64"); - assert_eq!(type_mapping["unsigned long long"], "u64"); + assert_eq!(type_mapping["short"], "::core::ffi::c_short"); + assert_eq!(type_mapping["int"], "::core::ffi::c_int"); + assert_eq!(type_mapping["long"], "::core::ffi::c_long"); + assert_eq!(type_mapping["long long"], "::core::ffi::c_longlong"); - assert_eq!(type_mapping["short"], "i16"); - assert_eq!(type_mapping["int"], "i32"); - assert_eq!(type_mapping["long"], "i64"); - assert_eq!(type_mapping["long long"], "i64"); + assert_eq!(type_mapping["unsigned short"], "::core::ffi::c_ushort"); + assert_eq!(type_mapping["unsigned int"], "::core::ffi::c_uint"); + assert_eq!(type_mapping["unsigned long"], "::core::ffi::c_ulong"); + assert_eq!(type_mapping["unsigned long long"], "::core::ffi::c_ulonglong"); - /* TOOD(b/275876867): Reenable assertions below after fix the `#include` problem. + /* TOOD(b/275876867): Reenable assertions below after fixing the `#include` problem. assert_eq!(type_mapping["int8_t"], "i8"); assert_eq!(type_mapping["int16_t"], "i16"); assert_eq!(type_mapping["int32_t"], "i32"); @@ -989,7 +988,7 @@ fn test_typedef() -> Result<()> { let int = quote! { MappedType { rs_type: RsType { - name: Some("i32"), + name: Some("::core::ffi::c_int"), lifetime_args: [], type_args: [], decl_id: None, @@ -1117,7 +1116,7 @@ fn test_typedef_of_full_template_specialization() -> Result<()> { identifier: Some("value"), ... doc_comment: Some("Doc comment of `value` field."), ... type_: Ok(MappedType { - rs_type: RsType { name: Some("i32"), ... }, + rs_type: RsType { name: Some("::core::ffi::c_int"), ... }, cc_type: CcType { name: Some("int"), ... }, }), access: Public, @@ -1226,7 +1225,7 @@ fn test_typedef_for_explicit_template_specialization() -> Result<()> { identifier: Some("value"), ... doc_comment: Some("Doc comment of the `value` field specialization for T=int."), ... type_: Ok(MappedType { - rs_type: RsType { name: Some("i32"), ... }, + rs_type: RsType { name: Some("::core::ffi::c_int"), ... }, cc_type: CcType { name: Some("int"), ... }, }), access: Public, @@ -1503,14 +1502,14 @@ fn test_subst_template_type_parm_pack_type() -> Result<()> { params: [ FuncParam { type_: MappedType { - rs_type: RsType { name: Some("i32"), ... }, + rs_type: RsType { name: Some("::core::ffi::c_int"), ... }, cc_type: CcType { name: Some("int"), ... }, }, identifier: "__my_args_0", }, FuncParam { type_: MappedType { - rs_type: RsType { name: Some("i32"), ... }, + rs_type: RsType { name: Some("::core::ffi::c_int"), ... }, cc_type: CcType { name: Some("int"), ... }, }, identifier: "__my_args_1", @@ -1759,7 +1758,7 @@ fn test_template_with_decltype_and_with_auto() -> Result<()> { Func { name: "TemplatedAdd", ... return_type: MappedType { - rs_type: RsType { name: Some("i64"), ... }, + rs_type: RsType { name: Some("::core::ffi::c_longlong"), ... }, cc_type: CcType { name: Some("long long"), ... }, }, ... } @@ -1798,7 +1797,7 @@ fn test_subst_template_type_parm_type_vs_const_when_non_const_template_param() - return_type: MappedType { rs_type: RsType { name: Some("&"), ... - type_args: [RsType { name: Some("i32"), ... }], ... + type_args: [RsType { name: Some("::core::ffi::c_int"), ... }], ... }, cc_type: CcType { name: Some("&"), @@ -1820,7 +1819,7 @@ fn test_subst_template_type_parm_type_vs_const_when_non_const_template_param() - return_type: MappedType { rs_type: RsType { name: Some("&mut"), ... - type_args: [RsType { name: Some("i32"), ... }], ... + type_args: [RsType { name: Some("::core::ffi::c_int"), ... }], ... }, cc_type: CcType { name: Some("&"), @@ -1867,7 +1866,7 @@ fn test_subst_template_type_parm_type_vs_const_when_const_template_param() -> Re return_type: MappedType { rs_type: RsType { name: Some("&"), ... - type_args: [RsType { name: Some("i32"), ... }], ... + type_args: [RsType { name: Some("::core::ffi::c_int"), ... }], ... }, cc_type: CcType { name: Some("&"), @@ -1889,7 +1888,7 @@ fn test_subst_template_type_parm_type_vs_const_when_const_template_param() -> Re return_type: MappedType { rs_type: RsType { name: Some("&"), ... - type_args: [RsType { name: Some("i32"), ... }], ... + type_args: [RsType { name: Some("::core::ffi::c_int"), ... }], ... }, cc_type: CcType { name: Some("&"), @@ -2528,7 +2527,7 @@ fn test_struct() { Field { identifier: Some("first_field"), ... type_: Ok(MappedType { - rs_type : RsType { name : Some ("i32"), ...}, + rs_type : RsType { name : Some("::core::ffi::c_int"), ...}, cc_type : CcType { name : Some ("int"), ...}, }), ... offset: 0, ... @@ -2538,7 +2537,7 @@ fn test_struct() { Field { identifier: Some("second_field"), ... type_: Ok(MappedType { - rs_type : RsType { name : Some ("i32"), ...}, + rs_type : RsType { name : Some("::core::ffi::c_int"), ...}, cc_type : CcType { name : Some ("int"), ...}, }), ... offset: 32, ... @@ -2631,7 +2630,7 @@ fn test_union() { Field { identifier: Some("first_field"), ... type_: Ok(MappedType { - rs_type : RsType { name : Some ("i32"), ...}, + rs_type : RsType { name : Some("::core::ffi::c_int"), ...}, cc_type : CcType { name : Some ("int"), ...}, }), ... offset: 0, ... @@ -2641,7 +2640,7 @@ fn test_union() { Field { identifier: Some("second_field"), ... type_: Ok(MappedType { - rs_type : RsType { name : Some ("i32"), ...}, + rs_type : RsType { name : Some("::core::ffi::c_int"), ...}, cc_type : CcType { name : Some ("int"), ...}, }), ... offset: 0, ... diff --git a/rs_bindings_from_cc/src_code_gen.rs b/rs_bindings_from_cc/src_code_gen.rs index 556eea06..587d76c3 100644 --- a/rs_bindings_from_cc/src_code_gen.rs +++ b/rs_bindings_from_cc/src_code_gen.rs @@ -3490,10 +3490,10 @@ impl RsTypeKind { } } RsTypeKind::Other { name, type_args } => { - let ident = make_rs_ident(name); + let name: TokenStream = name.parse().expect("Invalid RsType::name in the IR"); let generic_params = format_generic_params_replacing_by_self(type_args.iter(), self_record); - quote! {#ident #generic_params} + quote! {#name #generic_params} } _ => self.to_token_stream(), } @@ -3568,10 +3568,10 @@ impl ToTokens for RsTypeKind { // omitted. RsTypeKind::Unit => quote! {::core::ffi::c_void}, RsTypeKind::Other { name, type_args } => { - let ident = make_rs_ident(name); + let name: TokenStream = name.parse().expect("Invalid RsType::name in the IR"); let generic_params = format_generic_params(/* lifetimes= */ &[], type_args.iter()); - quote! {#ident #generic_params} + quote! {#name #generic_params} } } } @@ -4314,7 +4314,7 @@ mod tests { rs_api, quote! { #[inline(always)] - pub fn Add(a: i32, b: i32) -> i32 { + pub fn Add(a: ::core::ffi::c_int, b: ::core::ffi::c_int) -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___Z3Addii(a, b) } } } @@ -4327,7 +4327,7 @@ mod tests { use super::*; extern "C" { #[link_name = "_Z3Addii"] - pub(crate) fn __rust_thunk___Z3Addii(a: i32, b: i32) -> i32; + pub(crate) fn __rust_thunk___Z3Addii(a: ::core::ffi::c_int, b: ::core::ffi::c_int) -> ::core::ffi::c_int; } } } @@ -4346,7 +4346,7 @@ mod tests { rs_api, quote! { #[inline(always)] - pub fn Add(a: i32, b: i32) -> i32 { + pub fn Add(a: ::core::ffi::c_int, b: ::core::ffi::c_int) -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___Z3Addii(a, b) } } } @@ -4358,7 +4358,7 @@ mod tests { #[allow(unused_imports)] use super::*; extern "C" { - pub(crate) fn __rust_thunk___Z3Addii(a: i32, b: i32) -> i32; + pub(crate) fn __rust_thunk___Z3Addii(a: ::core::ffi::c_int, b: ::core::ffi::c_int) -> ::core::ffi::c_int; } } } @@ -4447,7 +4447,7 @@ mod tests { quote! { #[repr(C)] pub struct __CcTemplateInst10MyTemplateIiE { - pub field: i32, + pub field: ::core::ffi::c_int, } } ); @@ -4457,7 +4457,7 @@ mod tests { impl __CcTemplateInst10MyTemplateIiE { #[doc = " Generated from: google3/test/dependency_header.h;l=4"] #[inline(always)] - pub fn GetValue<'a>(self: ... Pin<&'a mut Self>) -> i32 { unsafe { + pub fn GetValue<'a>(self: ... Pin<&'a mut Self>) -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___ZN10MyTemplateIiE8GetValueEv__2f_2ftest_3atesting_5ftarget( self) }} @@ -4478,7 +4478,7 @@ mod tests { pub(crate) fn __rust_thunk___ZN10MyTemplateIiE8GetValueEv__2f_2ftest_3atesting_5ftarget<'a>( __this: ... Pin<&'a mut crate::__CcTemplateInst10MyTemplateIiE> - ) -> i32; + ) -> ::core::ffi::c_int; ... } } } @@ -4577,7 +4577,7 @@ mod tests { #[repr(C, align(4))] pub struct SomeStruct { __non_field_data: [::core::mem::MaybeUninit; 0], - pub public_int: i32, + pub public_int: ::core::ffi::c_int, #[doc = " Reason for representing this field as a blob of bytes:\n Types of non-public C++ fields can be elided away"] pub(crate) protected_int: [::core::mem::MaybeUninit; 4], #[doc = " Reason for representing this field as a blob of bytes:\n Types of non-public C++ fields can be elided away"] @@ -4588,7 +4588,6 @@ mod tests { assert_rs_matches!( rs_api, quote! { - const _: () = assert!(::core::mem::size_of::>() == ::core::mem::size_of::<&i32>()); const _: () = assert!(::core::mem::size_of::() == 12); const _: () = assert!(::core::mem::align_of::() == 4); const _: () = { static_assertions::assert_not_impl_any!(crate::SomeStruct: Copy); }; @@ -4725,7 +4724,7 @@ mod tests { )?; let BindingsTokens { rs_api, rs_api_impl } = generate_bindings_tokens(ir)?; // TODO(b/200067824): This should use the alias's real name in Rust, as well. - assert_rs_matches!(rs_api, quote! { pub fn Function() -> i32 { ... } },); + assert_rs_matches!(rs_api, quote! { pub fn Function() -> ::core::ffi::c_int { ... } },); assert_cc_matches!( rs_api_impl, @@ -4874,9 +4873,9 @@ mod tests { quote! { #[repr(C)] pub struct SomeStruct { - pub first_field: i32, ... + pub first_field: ::core::ffi::c_int, ... __bitfields1: [::core::mem::MaybeUninit; 4], - pub last_field: i32, + pub last_field: ::core::ffi::c_int, } ... const _: () = assert!(memoffset::offset_of!(crate::SomeStruct, first_field) == 0); @@ -5078,12 +5077,12 @@ mod tests { quote! { #[repr(C, align(4))] pub struct StructWithUnnamedMembers { - pub first_field: i32, + pub first_field: ::core::ffi::c_int, #[doc =" Reason for representing this field as a blob of bytes:\n Unsupported type 'struct StructWithUnnamedMembers::(anonymous at ./ir_from_cc_virtual_header.h:7:15)': No generated bindings found for ''"] pub(crate) __unnamed_field1: [::core::mem::MaybeUninit; 8], #[doc =" Reason for representing this field as a blob of bytes:\n Unsupported type 'union StructWithUnnamedMembers::(anonymous at ./ir_from_cc_virtual_header.h:11:15)': No generated bindings found for ''"] pub(crate) __unnamed_field2: [::core::mem::MaybeUninit; 4], - pub last_field: i32, + pub last_field: ::core::ffi::c_int, } ... const _: () = assert!(memoffset::offset_of!( @@ -5176,7 +5175,7 @@ mod tests { rs_api, quote! { #[inline(always)] - pub unsafe fn Deref(p: *const *mut i32) -> *mut i32 { + pub unsafe fn Deref(p: *const *mut ::core::ffi::c_int) -> *mut ::core::ffi::c_int { crate::detail::__rust_thunk___Z5DerefPKPi(p) } } @@ -5188,7 +5187,7 @@ mod tests { #[allow(unused_imports)] use super::*; extern "C" { - pub(crate) fn __rust_thunk___Z5DerefPKPi(p: *const *mut i32) -> *mut i32; + pub(crate) fn __rust_thunk___Z5DerefPKPi(p: *const *mut ::core::ffi::c_int) -> *mut ::core::ffi::c_int; } } } @@ -5219,7 +5218,7 @@ mod tests { rs_api, quote! { #[inline(always)] - pub unsafe fn f(str: *const i8) { + pub unsafe fn f(str: *const ::core::ffi::c_schar) { crate::detail::__rust_thunk___Z1fPKa(str) } } @@ -5228,7 +5227,7 @@ mod tests { rs_api, quote! { extern "C" { - pub(crate) fn __rust_thunk___Z1fPKa(str: *const i8); + pub(crate) fn __rust_thunk___Z1fPKa(str: *const ::core::ffi::c_schar); } } ); @@ -5250,7 +5249,7 @@ mod tests { rs_api, quote! { #[inline(always)] - pub fn get_ptr_to_func() -> Option i32> { + pub fn get_ptr_to_func() -> Option ::core::ffi::c_int> { unsafe { crate::detail::__rust_thunk___Z15get_ptr_to_funcv() } } } @@ -5264,7 +5263,7 @@ mod tests { extern "C" { #[link_name = "_Z15get_ptr_to_funcv"] pub(crate) fn __rust_thunk___Z15get_ptr_to_funcv() - -> Option i32>; + -> Option ::core::ffi::c_int>; } } } @@ -5290,7 +5289,7 @@ mod tests { rs_api, quote! { #[inline(always)] - pub fn get_ref_to_func() -> extern "C" fn (f32, f64) -> i32 { + pub fn get_ref_to_func() -> extern "C" fn (f32, f64) -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___Z15get_ref_to_funcv() } } } @@ -5322,7 +5321,7 @@ mod tests { rs_api, quote! { #[inline(always)] - pub fn get_ptr_to_func() -> Option *const i32> { + pub fn get_ptr_to_func() -> Option *const ::core::ffi::c_int> { unsafe { crate::detail::__rust_thunk___Z15get_ptr_to_funcv() } } } @@ -5336,7 +5335,7 @@ mod tests { extern "C" { #[link_name = "_Z15get_ptr_to_funcv"] pub(crate) fn __rust_thunk___Z15get_ptr_to_funcv() - -> Option *const i32>; + -> Option *const ::core::ffi::c_int>; } } } @@ -5406,7 +5405,7 @@ mod tests { rs_api, quote! { #[inline(always)] - pub fn get_ptr_to_func() -> Option i32> { + pub fn get_ptr_to_func() -> Option ::core::ffi::c_int> { unsafe { crate::detail::__rust_thunk___Z15get_ptr_to_funcv() } } } @@ -5422,7 +5421,7 @@ mod tests { extern "C" { #[link_name = "_Z15get_ptr_to_funcv"] pub(crate) fn __rust_thunk___Z15get_ptr_to_funcv() - -> Option i32>; + -> Option ::core::ffi::c_int>; } } } @@ -5625,7 +5624,7 @@ mod tests { #[repr(C, align(8))] pub struct Derived { __non_field_data: [::core::mem::MaybeUninit; 10], - pub z: i16, + pub z: ::core::ffi::c_short, } } ); @@ -5650,7 +5649,7 @@ mod tests { #[repr(C, align(8))] pub struct Derived { __non_field_data: [::core::mem::MaybeUninit; 10], - pub z: i16, + pub z: ::core::ffi::c_short, } } ); @@ -5675,7 +5674,7 @@ mod tests { #[repr(C, align(8))] pub struct Derived { __non_field_data: [::core::mem::MaybeUninit; 10], - pub z: i16, + pub z: ::core::ffi::c_short, } } ); @@ -5742,7 +5741,7 @@ mod tests { rs_api, quote! { pub struct Derived { - pub x: i16, + pub x: ::core::ffi::c_short, } } ); @@ -5768,7 +5767,7 @@ mod tests { quote! { pub struct NonAggregate { __non_field_data: [::core::mem::MaybeUninit; 0], - pub x: i16, + pub x: ::core::ffi::c_short, } } ); @@ -5800,7 +5799,7 @@ mod tests { pub(crate) field1: [::core::mem::MaybeUninit; 8], ... pub(crate) field2: [::core::mem::MaybeUninit; 2], - pub z: i16, + pub z: ::core::ffi::c_short, } } ); @@ -5869,7 +5868,7 @@ mod tests { pub struct Struct { ... pub(crate) field: [::core::mem::MaybeUninit; 0], - pub x: i32, + pub x: ::core::ffi::c_int, } } ); @@ -5909,18 +5908,18 @@ mod tests { quote! { #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] - pub struct Color(u32); + pub struct Color(::core::ffi::c_uint); impl Color { pub const kRed: Color = Color(5); pub const kBlue: Color = Color(6); } - impl From for Color { - fn from(value: u32) -> Color { + impl From<::core::ffi::c_uint> for Color { + fn from(value: ::core::ffi::c_uint) -> Color { Color(value) } } - impl From for u32 { - fn from(value: Color) -> u32 { + impl From for ::core::ffi::c_uint { + fn from(value: Color) -> ::core::ffi::c_uint { value.0 } } @@ -5938,18 +5937,18 @@ mod tests { quote! { #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] - pub struct Color(i32); + pub struct Color(::core::ffi::c_int); impl Color { pub const kRed: Color = Color(-5); pub const kBlue: Color = Color(-4); } - impl From for Color { - fn from(value: i32) -> Color { + impl From<::core::ffi::c_int> for Color { + fn from(value: ::core::ffi::c_int) -> Color { Color(value) } } - impl From for i32 { - fn from(value: Color) -> i32 { + impl From for ::core::ffi::c_int { + fn from(value: Color) -> ::core::ffi::c_int { value.0 } } @@ -5961,7 +5960,13 @@ mod tests { #[test] fn test_generate_enum_with_64_bit_signed_vals() -> Result<()> { let ir = ir_from_cc( - "enum Color : long { kViolet = -9223372036854775807 - 1LL, kRed = -5, kBlue, kGreen = 3, kMagenta = 9223372036854775807 };", + r#"enum Color : long { + kViolet = -9223372036854775807 - 1LL, + kRed = -5, + kBlue, + kGreen = 3, + kMagenta = 9223372036854775807 + };"#, )?; let rs_api = generate_bindings_tokens(ir)?.rs_api; assert_rs_matches!( @@ -5969,7 +5974,7 @@ mod tests { quote! { #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] - pub struct Color(i64); + pub struct Color(::core::ffi::c_long); impl Color { pub const kViolet: Color = Color(-9223372036854775808); pub const kRed: Color = Color(-5); @@ -5977,13 +5982,13 @@ mod tests { pub const kGreen: Color = Color(3); pub const kMagenta: Color = Color(9223372036854775807); } - impl From for Color { - fn from(value: i64) -> Color { + impl From<::core::ffi::c_long> for Color { + fn from(value: ::core::ffi::c_long) -> Color { Color(value) } } - impl From for i64 { - fn from(value: Color) -> i64 { + impl From for ::core::ffi::c_long { + fn from(value: Color) -> ::core::ffi::c_long { value.0 } } @@ -5995,7 +6000,11 @@ mod tests { #[test] fn test_generate_enum_with_64_bit_unsigned_vals() -> Result<()> { let ir = ir_from_cc( - "enum Color: unsigned long { kRed, kBlue, kLimeGreen = 18446744073709551615 };", + r#" enum Color: unsigned long { + kRed, + kBlue, + kLimeGreen = 18446744073709551615 + }; "#, )?; let rs_api = generate_bindings_tokens(ir)?.rs_api; assert_rs_matches!( @@ -6003,19 +6012,19 @@ mod tests { quote! { #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] - pub struct Color(u64); + pub struct Color(::core::ffi::c_ulong); impl Color { pub const kRed: Color = Color(0); pub const kBlue: Color = Color(1); pub const kLimeGreen: Color = Color(18446744073709551615); } - impl From for Color { - fn from(value: u64) -> Color { + impl From<::core::ffi::c_ulong> for Color { + fn from(value: ::core::ffi::c_ulong) -> Color { Color(value) } } - impl From for u64 { - fn from(value: Color) -> u64 { + impl From for ::core::ffi::c_ulong { + fn from(value: Color) -> ::core::ffi::c_ulong { value.0 } } @@ -6035,7 +6044,7 @@ mod tests { quote! { #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] - pub struct Color(i32); + pub struct Color(::core::ffi::c_int); impl Color { pub const kViolet: Color = Color(-2147483648); pub const kRed: Color = Color(-5); @@ -6043,13 +6052,13 @@ mod tests { pub const kGreen: Color = Color(3); pub const kMagenta: Color = Color(2147483647); } - impl From for Color { - fn from(value: i32) -> Color { + impl From<::core::ffi::c_int> for Color { + fn from(value: ::core::ffi::c_int) -> Color { Color(value) } } - impl From for i32 { - fn from(value: Color) -> i32 { + impl From for ::core::ffi::c_int { + fn from(value: Color) -> ::core::ffi::c_int { value.0 } } @@ -6067,19 +6076,19 @@ mod tests { quote! { #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] - pub struct Color(u32); + pub struct Color(::core::ffi::c_uint); impl Color { pub const kRed: Color = Color(0); pub const kBlue: Color = Color(1); pub const kLimeGreen: Color = Color(4294967295); } - impl From for Color { - fn from(value: u32) -> Color { + impl From<::core::ffi::c_uint> for Color { + fn from(value: ::core::ffi::c_uint) -> Color { Color(value) } } - impl From for u32 { - fn from(value: Color) -> u32 { + impl From for ::core::ffi::c_uint { + fn from(value: Color) -> ::core::ffi::c_uint { value.0 } } @@ -6189,7 +6198,7 @@ mod tests { #[repr(C)] pub struct SomeStruct { # [doc = " Field doc"] - pub field: i32, + pub field: ::core::ffi::c_int, } } ); @@ -6215,8 +6224,8 @@ mod tests { #[derive(Clone, Copy)] #[repr(C)] pub union SomeUnion { - pub some_field: i32, - pub some_bigger_field: i64, + pub some_field: ::core::ffi::c_int, + pub some_bigger_field: ::core::ffi::c_longlong, } } ); @@ -6260,7 +6269,7 @@ mod tests { #[repr(C, align(4))] pub union MyUnion { ... first_field: [::core::mem::MaybeUninit; 56], - pub second_field: i32, + pub second_field: ::core::ffi::c_int, } } ); @@ -6314,7 +6323,7 @@ mod tests { #[derive(Clone, Copy)] #[repr(C, align(8))] pub union SomeUnionWithPrivateFields { - pub public_field: i32, + pub public_field: ::core::ffi::c_int, #[doc = " Reason for representing this field as a blob of bytes:\n Types of non-public C++ fields can be elided away"] pub(crate) private_field: [::core::mem::MaybeUninit; 8], } @@ -6451,7 +6460,7 @@ mod tests { quote! { #[repr(C)] pub union UnionWithNontrivialField { - pub trivial_field: i32, + pub trivial_field: ::core::ffi::c_int, pub nontrivial_field: ::core::mem::ManuallyDrop, } } @@ -6485,7 +6494,7 @@ mod tests { #[derive(Clone, Copy)] #[repr(C)] pub union UnionWithDefaultConstructors { - pub a: i32, + pub a: ::core::ffi::c_int, } } ); @@ -6671,7 +6680,7 @@ mod tests { } } ); - assert_rs_matches!(rs_api, quote! {pub x: i32,}); + assert_rs_matches!(rs_api, quote! {pub x: ::core::ffi::c_int,}); assert_rs_matches!( rs_api, quote! {pub nts: ::core::mem::ManuallyDrop,} @@ -6709,7 +6718,7 @@ mod tests { } } ); - assert_rs_matches!(rs_api, quote! {pub x: i32,}); + assert_rs_matches!(rs_api, quote! {pub x: ::core::ffi::c_int,}); assert_rs_matches!(rs_api, quote! {pub ts: crate::TrivialStruct,}); assert_rs_matches!( rs_api, @@ -6731,7 +6740,7 @@ mod tests { let BindingsTokens { rs_api, rs_api_impl } = generate_bindings_tokens(ir)?; assert_rs_not_matches!(rs_api, quote! {impl Drop}); assert_rs_not_matches!(rs_api, quote! {impl ::ctor::PinnedDrop}); - assert_rs_matches!(rs_api, quote! {pub x: i32}); + assert_rs_matches!(rs_api, quote! {pub x: ::core::ffi::c_int}); assert_cc_not_matches!(rs_api_impl, quote! { std::destroy_at }); Ok(()) } @@ -6854,9 +6863,9 @@ mod tests { assert_rs_matches!( rs_api, quote! { - impl From for SomeStruct { + impl From<::core::ffi::c_int> for SomeStruct { #[inline(always)] - fn from(i: i32) -> Self { + fn from(i: ::core::ffi::c_int) -> Self { let mut tmp = ::core::mem::MaybeUninit::::zeroed(); unsafe { crate::detail::__rust_thunk___ZN10SomeStructC1Ei(&mut tmp, i); @@ -7360,14 +7369,14 @@ mod tests { assert_rs_matches!( rs_api, quote! { - pub fn f<'a, 'b>(&'a mut self, i: &'b mut i32) -> &'a mut i32 { ... } + pub fn f<'a, 'b>(&'a mut self, i: &'b mut ::core::ffi::c_int) -> &'a mut ::core::ffi::c_int { ... } } ); assert_rs_matches!( rs_api, quote! { - pub(crate) fn __rust_thunk___ZN1S1fERi<'a, 'b>(__this: &'a mut crate::S, i: &'b mut i32) - -> &'a mut i32; + pub(crate) fn __rust_thunk___ZN1S1fERi<'a, 'b>(__this: &'a mut crate::S, i: &'b mut ::core::ffi::c_int) + -> &'a mut ::core::ffi::c_int; } ); Ok(()) @@ -7384,14 +7393,14 @@ mod tests { assert_rs_matches!( rs_api, quote! { - pub fn f<'a>(i1: &'a mut i32, i2: &'a mut i32) -> &'a mut i32 { ... } + pub fn f<'a>(i1: &'a mut ::core::ffi::c_int, i2: &'a mut ::core::ffi::c_int) -> &'a mut ::core::ffi::c_int { ... } } ); assert_rs_matches!( rs_api, quote! { - pub(crate) fn __rust_thunk___Z1fRiS_<'a>(i1: &'a mut i32, i2: &'a mut i32) - -> &'a mut i32; + pub(crate) fn __rust_thunk___Z1fRiS_<'a>(i1: &'a mut ::core::ffi::c_int, i2: &'a mut ::core::ffi::c_int) + -> &'a mut ::core::ffi::c_int; } ); Ok(()) @@ -7464,7 +7473,7 @@ mod tests { quote! { __COMMENT__ #txt } }); assert_rs_not_matches!(rs_api, quote! {pub fn f()}); - assert_rs_not_matches!(rs_api, quote! {pub fn f(i: i32)}); + assert_rs_not_matches!(rs_api, quote! {pub fn f(i: ::core::ffi::c_int)}); assert_cc_matches!(rs_api, { let txt = "Generated from: google3/ir_from_cc_virtual_header.h;l=7\n\ @@ -7482,7 +7491,7 @@ mod tests { assert_rs_matches!(rs_api, quote! {pub fn f<'a>(&'a mut self)}); // We can also import overloaded single-parameter constructors. - assert_rs_matches!(rs_api, quote! {impl From for S3}); + assert_rs_matches!(rs_api, quote! {impl From<::core::ffi::c_int> for S3}); assert_rs_matches!(rs_api, quote! {impl From for S3}); // And we can import functions that have the same name + signature, but that are @@ -7513,10 +7522,10 @@ mod tests { rs_api, quote! { #[doc = " MyTypedefDecl doc comment\n \n Generated from: google3/ir_from_cc_virtual_header.h;l=5"] - pub type MyTypedefDecl = i32; + pub type MyTypedefDecl = ::core::ffi::c_int; } ); - assert_rs_matches!(rs_api, quote! { pub type MyTypeAliasDecl = i32; }); + assert_rs_matches!(rs_api, quote! { pub type MyTypeAliasDecl = ::core::ffi::c_int; }); assert_rs_matches!( rs_api, quote! { pub type MyTypeAliasDecl_Alias = crate::MyTypeAliasDecl; } @@ -7563,13 +7572,43 @@ mod tests { let tests = vec![ // Validity of the next few tests is verified via // `assert_[not_]impl_all!` static assertions above. - Test { cc: "int", lifetimes: true, rs: "i32", is_copy: true }, - Test { cc: "const int&", lifetimes: true, rs: "& 'a i32", is_copy: true }, - Test { cc: "int&", lifetimes: true, rs: "& 'a mut i32", is_copy: false }, - Test { cc: "const int*", lifetimes: true, rs: "Option < & 'a i32 >", is_copy: true }, - Test { cc: "int*", lifetimes: true, rs: "Option < & 'a mut i32 >", is_copy: false }, - Test { cc: "const int*", lifetimes: false, rs: "* const i32", is_copy: true }, - Test { cc: "int*", lifetimes: false, rs: "* mut i32", is_copy: true }, + Test { cc: "int", lifetimes: true, rs: ":: core :: ffi :: c_int", is_copy: true }, + Test { + cc: "const int&", + lifetimes: true, + rs: "& 'a :: core :: ffi :: c_int", + is_copy: true, + }, + Test { + cc: "int&", + lifetimes: true, + rs: "& 'a mut :: core :: ffi :: c_int", + is_copy: false, + }, + Test { + cc: "const int*", + lifetimes: true, + rs: "Option < & 'a :: core :: ffi :: c_int >", + is_copy: true, + }, + Test { + cc: "int*", + lifetimes: true, + rs: "Option < & 'a mut :: core :: ffi :: c_int >", + is_copy: false, + }, + Test { + cc: "const int*", + lifetimes: false, + rs: "* const :: core :: ffi :: c_int", + is_copy: true, + }, + Test { + cc: "int*", + lifetimes: false, + rs: "* mut :: core :: ffi :: c_int", + is_copy: true, + }, Test { cc: "void*", lifetimes: false, @@ -7832,7 +7871,7 @@ mod tests { fn test_rust_keywords_are_escaped_in_rs_api_file() -> Result<()> { let ir = ir_from_cc("struct type { int dyn; };")?; let rs_api = generate_bindings_tokens(ir)?.rs_api; - assert_rs_matches!(rs_api, quote! { struct r#type { ... r#dyn: i32 ... } }); + assert_rs_matches!(rs_api, quote! { struct r#type { ... r#dyn: ::core::ffi::c_int ... } }); Ok(()) } @@ -8014,11 +8053,11 @@ mod tests { assert_rs_matches!( rs_api, quote! { - impl ::ctor::CtorNew for HasConstructor { + impl ::ctor::CtorNew<::core::ffi::c_uchar> for HasConstructor { type CtorType = impl ::ctor::Ctor; #[inline (always)] - fn ctor_new(args: u8) -> Self::CtorType { + fn ctor_new(args: ::core::ffi::c_uchar) -> Self::CtorType { let input = args; unsafe { ::ctor::FnCtor::new(move |dest: ::core::pin::Pin<&mut ::core::mem::MaybeUninit>| { @@ -8044,11 +8083,11 @@ mod tests { assert_rs_matches!( rs_api, quote! { - impl ::ctor::CtorNew<(u8, i8)> for HasConstructor { + impl ::ctor::CtorNew<(::core::ffi::c_uchar, ::core::ffi::c_schar)> for HasConstructor { type CtorType = impl ::ctor::Ctor; #[inline (always)] - fn ctor_new(args: (u8, i8)) -> Self::CtorType { + fn ctor_new(args: (::core::ffi::c_uchar, ::core::ffi::c_schar)) -> Self::CtorType { let (input1, input2) = args; unsafe { ::ctor::FnCtor::new(move |dest: ::core::pin::Pin<&mut ::core::mem::MaybeUninit>| { @@ -8085,7 +8124,7 @@ mod tests { rs_api, quote! { impl <'b, 'y, 'b_2> ::ctor::CtorNew<( - &'b i32, + &'b ::core::ffi::c_int, ::ctor::RvalueReference<'y, Self>, ::ctor::RvalueReference<'b_2, Self>) > for HasConstructor { @@ -8098,7 +8137,7 @@ mod tests { #[inline (always)] fn ctor_new(args: ( - &'b i32, + &'b ::core::ffi::c_int, ::ctor::RvalueReference<'y, Self>, ::ctor::RvalueReference<'b_2, Self>) ) -> Self::CtorType { @@ -8129,7 +8168,7 @@ mod tests { assert_rs_matches!( rs_api, quote! { - pub fn ReturnsByValue<'a, 'b>(x: &'a i32, y: &'b i32) + pub fn ReturnsByValue<'a, 'b>(x: &'a ::core::ffi::c_int, y: &'b ::core::ffi::c_int) -> impl ::ctor::Ctor + ::ctor::Captures<'a> + ::ctor::Captures<'b> { @@ -8169,7 +8208,7 @@ mod tests { assert_rs_matches!( rs_api, quote! { - pub fn ReturnsByValue<'a, 'b>(x: &'a i32, y: &'b i32) + pub fn ReturnsByValue<'a, 'b>(x: &'a ::core::ffi::c_int, y: &'b ::core::ffi::c_int) -> impl ::ctor::Ctor + ::ctor::Captures<'a> + ::ctor::Captures<'b> { @@ -8587,13 +8626,13 @@ mod tests { quote! { pub mod test_namespace_bindings { ... - pub fn func() -> i32 { ... } + pub fn func() -> ::core::ffi::c_int { ... } ... pub struct S { ... } ... pub mod inner { ... - pub fn inner_func() -> i32 { ... } + pub fn inner_func() -> ::core::ffi::c_int { ... } ... pub struct InnerS { ... } ... @@ -8627,7 +8666,7 @@ mod tests { use super::*; extern "C" { #[link_name = "_ZN23test_namespace_bindings1fEv"] - pub(crate) fn __rust_thunk___ZN23test_namespace_bindings1fEv() -> i32; + pub(crate) fn __rust_thunk___ZN23test_namespace_bindings1fEv() -> ::core::ffi::c_int; } } ... @@ -8917,7 +8956,7 @@ mod tests { } ... pub struct __CcTemplateInstN23test_namespace_bindings10MyTemplateIiEE { - pub value_: i32, + pub value_: ::core::ffi::c_int, } ... } diff --git a/rs_bindings_from_cc/test/golden/bitfields_rs_api.rs b/rs_bindings_from_cc/test/golden/bitfields_rs_api.rs index f6b140ab..60e34299 100644 --- a/rs_bindings_from_cc/test/golden/bitfields_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/bitfields_rs_api.rs @@ -30,12 +30,12 @@ pub struct WithBitfields { // f1 : 2 bits __bitfields0: [::core::mem::MaybeUninit; 1], - pub f2: i32, + pub f2: ::core::ffi::c_int, // f3 : 4 bits // f4 : 8 bits // : 45 bits __bitfields2: [::core::mem::MaybeUninit; 10], - pub f5: i32, + pub f5: ::core::ffi::c_int, // f6 : 23 bits __bitfields4: [::core::mem::MaybeUninit; 3], /// Reason for representing this field as a blob of bytes: diff --git a/rs_bindings_from_cc/test/golden/clang_attrs_rs_api.rs b/rs_bindings_from_cc/test/golden/clang_attrs_rs_api.rs index 0ca420e1..331e7f45 100644 --- a/rs_bindings_from_cc/test/golden/clang_attrs_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/clang_attrs_rs_api.rs @@ -567,7 +567,7 @@ impl<'b> ::ctor::Assign<::ctor::RvalueReference<'b, Self>> impl __CcTemplateInstN28template_with_preferred_name12SomeTemplateIiEE { #[inline(always)] - pub fn foo<'a>(self: ::core::pin::Pin<&'a mut Self>) -> i32 { + pub fn foo<'a>(self: ::core::pin::Pin<&'a mut Self>) -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___ZN28template_with_preferred_name12SomeTemplateIiE3fooEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3aclang_5fattrs_5fcc(self) } @@ -713,7 +713,7 @@ mod detail { __this: ::core::pin::Pin< &'a mut crate::__CcTemplateInstN28template_with_preferred_name12SomeTemplateIiEE, >, - ) -> i32; + ) -> ::core::ffi::c_int; } } diff --git a/rs_bindings_from_cc/test/golden/comment_rs_api.rs b/rs_bindings_from_cc/test/golden/comment_rs_api.rs index 7b8cf810..1524fc65 100644 --- a/rs_bindings_from_cc/test/golden/comment_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/comment_rs_api.rs @@ -31,9 +31,9 @@ #[repr(C)] pub struct Foo { /// A field - pub i: i32, + pub i: ::core::ffi::c_int, /// Another field - pub j: i32, + pub j: ::core::ffi::c_int, } forward_declare::unsafe_define!(forward_declare::symbol!("Foo"), crate::Foo); @@ -102,7 +102,7 @@ pub fn foo() { #[derive(Clone, Copy)] #[repr(C)] pub struct Bar { - pub i: i32, + pub i: ::core::ffi::c_int, } forward_declare::unsafe_define!(forward_declare::symbol!("Bar"), crate::Bar); @@ -150,7 +150,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for Bar { #[derive(Clone, Copy)] #[repr(C)] pub struct HasNoComments { - pub i: i32, + pub i: ::core::ffi::c_int, } forward_declare::unsafe_define!(forward_declare::symbol!("HasNoComments"), crate::HasNoComments); diff --git a/rs_bindings_from_cc/test/golden/doc_comment_rs_api.rs b/rs_bindings_from_cc/test/golden/doc_comment_rs_api.rs index f010bcfa..52c19c45 100644 --- a/rs_bindings_from_cc/test/golden/doc_comment_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/doc_comment_rs_api.rs @@ -28,7 +28,7 @@ pub struct DocCommentSlashes { __non_field_data: [::core::mem::MaybeUninit; 0], /// A field. - pub i: i32, + pub i: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!("DocCommentSlashes"), @@ -79,9 +79,9 @@ impl Default for DocCommentSlashes { /// An implicit conversion constructor which will get translated into `impl /// From for DocCommentSlashes`. -impl From for DocCommentSlashes { +impl From<::core::ffi::c_int> for DocCommentSlashes { #[inline(always)] - fn from(__param_0: i32) -> Self { + fn from(__param_0: ::core::ffi::c_int) -> Self { let mut tmp = ::core::mem::MaybeUninit::::zeroed(); unsafe { crate::detail::__rust_thunk___ZN17DocCommentSlashesC1Ei(&mut tmp, __param_0); @@ -93,7 +93,7 @@ impl From for DocCommentSlashes { impl DocCommentSlashes { /// A non-static member function (`const` flavor). #[inline(always)] - pub fn get_field_value<'a>(&'a self) -> i32 { + pub fn get_field_value<'a>(&'a self) -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___ZNK17DocCommentSlashes15get_field_valueEv(self) } } } @@ -101,7 +101,7 @@ impl DocCommentSlashes { impl DocCommentSlashes { /// A non-static member function (non-`const` flavor). #[inline(always)] - pub fn set_field_value<'a>(&'a mut self, new_value: i32) { + pub fn set_field_value<'a>(&'a mut self, new_value: ::core::ffi::c_int) { unsafe { crate::detail::__rust_thunk___ZN17DocCommentSlashes15set_field_valueEi(self, new_value) } @@ -111,7 +111,7 @@ impl DocCommentSlashes { impl DocCommentSlashes { /// A static method. #[inline(always)] - pub fn static_method() -> i32 { + pub fn static_method() -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___ZN17DocCommentSlashes13static_methodEv() } } } @@ -123,7 +123,7 @@ impl DocCommentSlashes { #[repr(C)] pub struct DocCommentBang { /// A field - pub i: i32, + pub i: ::core::ffi::c_int, } forward_declare::unsafe_define!(forward_declare::symbol!("DocCommentBang"), crate::DocCommentBang); @@ -174,7 +174,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for DocCommentBa #[repr(C)] pub struct MultilineCommentTwoStars { /// A field - pub i: i32, + pub i: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!("MultilineCommentTwoStars"), @@ -228,7 +228,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for MultilineCom #[repr(C)] pub struct LineComment { /// A field - pub i: i32, + pub i: ::core::ffi::c_int, } forward_declare::unsafe_define!(forward_declare::symbol!("LineComment"), crate::LineComment); @@ -279,7 +279,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for LineComment #[repr(C)] pub struct MultilineOneStar { /// A field - pub i: i32, + pub i: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!("MultilineOneStar"), @@ -328,7 +328,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for MultilineOne /// A function #[inline(always)] -pub fn foo() -> i32 { +pub fn foo() -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___Z3foov() } } @@ -363,7 +363,7 @@ pub type MySpecializedInstantiation = crate::__CcTemplateInst10MyTemplateIfE; #[repr(C)] pub struct __CcTemplateInst10MyTemplateIiE { /// Data member. - pub value: i32, + pub value: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!("MyTemplate"), @@ -417,7 +417,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> impl __CcTemplateInst10MyTemplateIiE { /// A non-static member function. #[inline(always)] - pub fn get_field_value<'a>(&'a self) -> &'a i32 { + pub fn get_field_value<'a>(&'a self) -> &'a ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___ZNK10MyTemplateIiE15get_field_valueEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3adoc_5fcomment_5fcc(self) } @@ -511,19 +511,19 @@ mod detail { #[link_name = "_ZN17DocCommentSlashesC1Ei"] pub(crate) fn __rust_thunk___ZN17DocCommentSlashesC1Ei<'a>( __this: &'a mut ::core::mem::MaybeUninit, - __param_0: i32, + __param_0: ::core::ffi::c_int, ); #[link_name = "_ZNK17DocCommentSlashes15get_field_valueEv"] pub(crate) fn __rust_thunk___ZNK17DocCommentSlashes15get_field_valueEv<'a>( __this: &'a crate::DocCommentSlashes, - ) -> i32; + ) -> ::core::ffi::c_int; #[link_name = "_ZN17DocCommentSlashes15set_field_valueEi"] pub(crate) fn __rust_thunk___ZN17DocCommentSlashes15set_field_valueEi<'a>( __this: &'a mut crate::DocCommentSlashes, - new_value: i32, + new_value: ::core::ffi::c_int, ); #[link_name = "_ZN17DocCommentSlashes13static_methodEv"] - pub(crate) fn __rust_thunk___ZN17DocCommentSlashes13static_methodEv() -> i32; + pub(crate) fn __rust_thunk___ZN17DocCommentSlashes13static_methodEv() -> ::core::ffi::c_int; pub(crate) fn __rust_thunk___ZN14DocCommentBangC1Ev<'a>( __this: &'a mut ::core::mem::MaybeUninit, ); @@ -584,7 +584,7 @@ mod detail { __this: &'a mut crate::MultilineOneStar, __param_0: ::ctor::RvalueReference<'b, crate::MultilineOneStar>, ) -> &'a mut crate::MultilineOneStar; - pub(crate) fn __rust_thunk___Z3foov() -> i32; + pub(crate) fn __rust_thunk___Z3foov() -> ::core::ffi::c_int; pub(crate) fn __rust_thunk___ZN10MyTemplateIiEC1Ev__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3adoc_5fcomment_5fcc< 'a, >( @@ -615,7 +615,7 @@ mod detail { 'a, >( __this: &'a crate::__CcTemplateInst10MyTemplateIiE, - ) -> &'a i32; + ) -> &'a ::core::ffi::c_int; pub(crate) fn __rust_thunk___ZN10MyTemplateIfEC1Ev__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3adoc_5fcomment_5fcc< 'a, >( diff --git a/rs_bindings_from_cc/test/golden/enums_rs_api.rs b/rs_bindings_from_cc/test/golden/enums_rs_api.rs index 31c092c9..9d29eefd 100644 --- a/rs_bindings_from_cc/test/golden/enums_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/enums_rs_api.rs @@ -22,34 +22,34 @@ #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] -pub struct Color(u32); +pub struct Color(::core::ffi::c_uint); impl Color { pub const kRed: Color = Color(0); pub const kBlue: Color = Color(1); pub const kGreen: Color = Color(2); } -impl From for Color { - fn from(value: u32) -> Color { +impl From<::core::ffi::c_uint> for Color { + fn from(value: ::core::ffi::c_uint) -> Color { Color(value) } } -impl From for u32 { - fn from(value: Color) -> u32 { +impl From for ::core::ffi::c_uint { + fn from(value: Color) -> ::core::ffi::c_uint { value.0 } } #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] -pub struct Empty(u32); +pub struct Empty(::core::ffi::c_uint); impl Empty {} -impl From for Empty { - fn from(value: u32) -> Empty { +impl From<::core::ffi::c_uint> for Empty { + fn from(value: ::core::ffi::c_uint) -> Empty { Empty(value) } } -impl From for u32 { - fn from(value: Empty) -> u32 { +impl From for ::core::ffi::c_uint { + fn from(value: Empty) -> ::core::ffi::c_uint { value.0 } } @@ -71,15 +71,15 @@ impl From for bool { #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] -pub struct EmptyInt(u32); +pub struct EmptyInt(::core::ffi::c_uint); impl EmptyInt {} -impl From for EmptyInt { - fn from(value: u32) -> EmptyInt { +impl From<::core::ffi::c_uint> for EmptyInt { + fn from(value: ::core::ffi::c_uint) -> EmptyInt { EmptyInt(value) } } -impl From for u32 { - fn from(value: EmptyInt) -> u32 { +impl From for ::core::ffi::c_uint { + fn from(value: EmptyInt) -> ::core::ffi::c_uint { value.0 } } @@ -119,18 +119,18 @@ impl From for bool { #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] -pub struct NonEmptyInt(u32); +pub struct NonEmptyInt(::core::ffi::c_uint); impl NonEmptyInt { pub const kInt1: NonEmptyInt = NonEmptyInt(0); pub const kInt2: NonEmptyInt = NonEmptyInt(4294967295); } -impl From for NonEmptyInt { - fn from(value: u32) -> NonEmptyInt { +impl From<::core::ffi::c_uint> for NonEmptyInt { + fn from(value: ::core::ffi::c_uint) -> NonEmptyInt { NonEmptyInt(value) } } -impl From for u32 { - fn from(value: NonEmptyInt) -> u32 { +impl From for ::core::ffi::c_uint { + fn from(value: NonEmptyInt) -> ::core::ffi::c_uint { value.0 } } @@ -155,15 +155,15 @@ impl From for u8 { #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] -pub struct EmptyClass(i32); +pub struct EmptyClass(::core::ffi::c_int); impl EmptyClass {} -impl From for EmptyClass { - fn from(value: i32) -> EmptyClass { +impl From<::core::ffi::c_int> for EmptyClass { + fn from(value: ::core::ffi::c_int) -> EmptyClass { EmptyClass(value) } } -impl From for i32 { - fn from(value: EmptyClass) -> i32 { +impl From for ::core::ffi::c_int { + fn from(value: EmptyClass) -> ::core::ffi::c_int { value.0 } } @@ -185,15 +185,15 @@ impl From for bool { #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] -pub struct EmptyIntClass(i32); +pub struct EmptyIntClass(::core::ffi::c_int); impl EmptyIntClass {} -impl From for EmptyIntClass { - fn from(value: i32) -> EmptyIntClass { +impl From<::core::ffi::c_int> for EmptyIntClass { + fn from(value: ::core::ffi::c_int) -> EmptyIntClass { EmptyIntClass(value) } } -impl From for i32 { - fn from(value: EmptyIntClass) -> i32 { +impl From for ::core::ffi::c_int { + fn from(value: EmptyIntClass) -> ::core::ffi::c_int { value.0 } } @@ -233,18 +233,18 @@ impl From for bool { #[repr(transparent)] #[derive(Debug, PartialEq, Eq, Copy, Clone, Hash, PartialOrd, Ord)] -pub struct NonEmptyIntClass(u32); +pub struct NonEmptyIntClass(::core::ffi::c_uint); impl NonEmptyIntClass { pub const k1: NonEmptyIntClass = NonEmptyIntClass(0); pub const k2: NonEmptyIntClass = NonEmptyIntClass(4294967295); } -impl From for NonEmptyIntClass { - fn from(value: u32) -> NonEmptyIntClass { +impl From<::core::ffi::c_uint> for NonEmptyIntClass { + fn from(value: ::core::ffi::c_uint) -> NonEmptyIntClass { NonEmptyIntClass(value) } } -impl From for u32 { - fn from(value: NonEmptyIntClass) -> u32 { +impl From for ::core::ffi::c_uint { + fn from(value: NonEmptyIntClass) -> ::core::ffi::c_uint { value.0 } } diff --git a/rs_bindings_from_cc/test/golden/escaping_keywords_rs_api.rs b/rs_bindings_from_cc/test/golden/escaping_keywords_rs_api.rs index 3f604bf4..41d1184b 100644 --- a/rs_bindings_from_cc/test/golden/escaping_keywords_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/escaping_keywords_rs_api.rs @@ -23,7 +23,7 @@ #[derive(Clone, Copy)] #[repr(C)] pub struct r#type { - pub r#dyn: i32, + pub r#dyn: ::core::ffi::c_int, } forward_declare::unsafe_define!(forward_declare::symbol!("type"), crate::r#type); @@ -68,7 +68,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for r#type { } #[inline(always)] -pub fn r#impl(r#match: i32) { +pub fn r#impl(r#match: ::core::ffi::c_int) { unsafe { crate::detail::__rust_thunk___Z4impli(r#match) } } @@ -100,7 +100,7 @@ mod detail { __param_0: ::ctor::RvalueReference<'b, crate::r#type>, ) -> &'a mut crate::r#type; #[link_name = "_Z4impli"] - pub(crate) fn __rust_thunk___Z4impli(r#match: i32); + pub(crate) fn __rust_thunk___Z4impli(r#match: ::core::ffi::c_int); } } diff --git a/rs_bindings_from_cc/test/golden/friend_functions_rs_api.rs b/rs_bindings_from_cc/test/golden/friend_functions_rs_api.rs index 699a9410..005ca17e 100644 --- a/rs_bindings_from_cc/test/golden/friend_functions_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/friend_functions_rs_api.rs @@ -93,7 +93,7 @@ pub fn visible_rref<'a>(__param_0: ::ctor::RvalueReference<'a, crate::SomeClass> /// Uint128Low64 declarations from absl/numeric/int128.h. This is a /// regression test for b/244311755. #[inline(always)] -pub fn multiple_declarations<'a>(__param_0: &'a crate::SomeClass) -> i32 { +pub fn multiple_declarations<'a>(__param_0: &'a crate::SomeClass) -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___Z21multiple_declarationsRK9SomeClass(__param_0) } } @@ -133,7 +133,7 @@ mod detail { ); pub(crate) fn __rust_thunk___Z21multiple_declarationsRK9SomeClass<'a>( __param_0: &'a crate::SomeClass, - ) -> i32; + ) -> ::core::ffi::c_int; } } diff --git a/rs_bindings_from_cc/test/golden/item_order_rs_api.rs b/rs_bindings_from_cc/test/golden/item_order_rs_api.rs index dc7e44b9..14a235ce 100644 --- a/rs_bindings_from_cc/test/golden/item_order_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/item_order_rs_api.rs @@ -23,7 +23,7 @@ #[derive(Clone, Copy)] #[repr(C)] pub struct FirstStruct { - pub field: i32, + pub field: ::core::ffi::c_int, } forward_declare::unsafe_define!(forward_declare::symbol!("FirstStruct"), crate::FirstStruct); @@ -68,14 +68,14 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for FirstStruct } #[inline(always)] -pub fn first_func() -> i32 { +pub fn first_func() -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___Z10first_funcv() } } #[derive(Clone, Copy)] #[repr(C)] pub struct SecondStruct { - pub field: i32, + pub field: ::core::ffi::c_int, } forward_declare::unsafe_define!(forward_declare::symbol!("SecondStruct"), crate::SecondStruct); @@ -120,7 +120,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for SecondStruct } #[inline(always)] -pub fn second_func() -> i32 { +pub fn second_func() -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___Z11second_funcv() } } @@ -145,7 +145,7 @@ mod detail { __this: &'a mut crate::FirstStruct, __param_0: ::ctor::RvalueReference<'b, crate::FirstStruct>, ) -> &'a mut crate::FirstStruct; - pub(crate) fn __rust_thunk___Z10first_funcv() -> i32; + pub(crate) fn __rust_thunk___Z10first_funcv() -> ::core::ffi::c_int; pub(crate) fn __rust_thunk___ZN12SecondStructC1Ev<'a>( __this: &'a mut ::core::mem::MaybeUninit, ); @@ -161,7 +161,7 @@ mod detail { __this: &'a mut crate::SecondStruct, __param_0: ::ctor::RvalueReference<'b, crate::SecondStruct>, ) -> &'a mut crate::SecondStruct; - pub(crate) fn __rust_thunk___Z11second_funcv() -> i32; + pub(crate) fn __rust_thunk___Z11second_funcv() -> ::core::ffi::c_int; } } diff --git a/rs_bindings_from_cc/test/golden/lifetimes_rs_api.rs b/rs_bindings_from_cc/test/golden/lifetimes_rs_api.rs index 9fec5f2d..3b622996 100644 --- a/rs_bindings_from_cc/test/golden/lifetimes_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/lifetimes_rs_api.rs @@ -45,7 +45,7 @@ pub fn AddAnotherHookWithTypedef(hook: extern "C" fn()) { } #[inline(always)] -pub unsafe fn ConsumeArray(pair: *mut i32) { +pub unsafe fn ConsumeArray(pair: *mut ::core::ffi::c_int) { crate::detail::__rust_thunk___Z12ConsumeArrayPi(pair) } @@ -53,7 +53,7 @@ pub unsafe fn ConsumeArray(pair: *mut i32) { // Unsupported type 'int[2]': Unsupported clang::Type class 'ConstantArray' #[inline(always)] -pub unsafe fn ConsumeArrayWithTypedef(__param_0: *mut i32) { +pub unsafe fn ConsumeArrayWithTypedef(__param_0: *mut ::core::ffi::c_int) { crate::detail::__rust_thunk___Z23ConsumeArrayWithTypedefPi(__param_0) } @@ -72,9 +72,11 @@ mod detail { #[link_name = "_Z25AddAnotherHookWithTypedefRFvvE"] pub(crate) fn __rust_thunk___Z25AddAnotherHookWithTypedefRFvvE(hook: extern "C" fn()); #[link_name = "_Z12ConsumeArrayPi"] - pub(crate) fn __rust_thunk___Z12ConsumeArrayPi(pair: *mut i32); + pub(crate) fn __rust_thunk___Z12ConsumeArrayPi(pair: *mut ::core::ffi::c_int); #[link_name = "_Z23ConsumeArrayWithTypedefPi"] - pub(crate) fn __rust_thunk___Z23ConsumeArrayWithTypedefPi(__param_0: *mut i32); + pub(crate) fn __rust_thunk___Z23ConsumeArrayWithTypedefPi( + __param_0: *mut ::core::ffi::c_int, + ); } } diff --git a/rs_bindings_from_cc/test/golden/namespace_rs_api.rs b/rs_bindings_from_cc/test/golden/namespace_rs_api.rs index 315db2a7..95628920 100644 --- a/rs_bindings_from_cc/test/golden/namespace_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/namespace_rs_api.rs @@ -24,7 +24,7 @@ pub mod test_namespace_bindings { #[derive(Clone, Copy)] #[repr(C)] pub struct S { - pub i: i32, + pub i: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!("S"), @@ -77,7 +77,7 @@ pub mod test_namespace_bindings { /// Free comment inside namespace #[inline(always)] - pub fn f(mut s: crate::test_namespace_bindings::S) -> i32 { + pub fn f(mut s: crate::test_namespace_bindings::S) -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___ZN23test_namespace_bindings1fENS_1SE(&mut s) } } @@ -312,7 +312,7 @@ mod detail { ) -> &'a mut crate::test_namespace_bindings::S; pub(crate) fn __rust_thunk___ZN23test_namespace_bindings1fENS_1SE( s: &mut crate::test_namespace_bindings::S, - ) -> i32; + ) -> ::core::ffi::c_int; pub(crate) fn __rust_thunk___ZN23test_namespace_bindings15inline_functionEv(); #[link_name = "_ZN23test_namespace_bindings5inner1iEv"] pub(crate) fn __rust_thunk___ZN23test_namespace_bindings5inner1iEv(); diff --git a/rs_bindings_from_cc/test/golden/no_elided_lifetimes_rs_api.rs b/rs_bindings_from_cc/test/golden/no_elided_lifetimes_rs_api.rs index cc70522c..ce5646e3 100644 --- a/rs_bindings_from_cc/test/golden/no_elided_lifetimes_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/no_elided_lifetimes_rs_api.rs @@ -21,7 +21,7 @@ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #[inline(always)] -pub unsafe fn free_function(p1: *mut i32) -> *mut i32 { +pub unsafe fn free_function(p1: *mut ::core::ffi::c_int) -> *mut ::core::ffi::c_int { crate::detail::__rust_thunk___Z13free_functionRi(p1) } @@ -49,14 +49,22 @@ forward_declare::unsafe_define!(forward_declare::symbol!("S"), crate::S); impl S { #[inline(always)] - pub unsafe fn const_method(__this: *const Self, p1: *mut i32, p2: *mut i32) -> *mut i32 { + pub unsafe fn const_method( + __this: *const Self, + p1: *mut ::core::ffi::c_int, + p2: *mut ::core::ffi::c_int, + ) -> *mut ::core::ffi::c_int { crate::detail::__rust_thunk___ZNK1S12const_methodERiS0_(__this, p1, p2) } } impl S { #[inline(always)] - pub unsafe fn method(__this: *mut Self, p1: *mut i32, p2: *mut i32) -> *mut i32 { + pub unsafe fn method( + __this: *mut Self, + p1: *mut ::core::ffi::c_int, + p2: *mut ::core::ffi::c_int, + ) -> *mut ::core::ffi::c_int { crate::detail::__rust_thunk___ZN1S6methodERiS0_(__this, p1, p2) } } @@ -85,7 +93,7 @@ impl ::ctor::PinnedDrop for TriviallyCopyableButNontriviallyDestructible { } #[inline(always)] -pub unsafe fn take_pointer(p: *mut i32) { +pub unsafe fn take_pointer(p: *mut ::core::ffi::c_int) { crate::detail::__rust_thunk___Z12take_pointerPi(p) } @@ -124,25 +132,27 @@ mod detail { use super::*; extern "C" { #[link_name = "_Z13free_functionRi"] - pub(crate) fn __rust_thunk___Z13free_functionRi(p1: *mut i32) -> *mut i32; + pub(crate) fn __rust_thunk___Z13free_functionRi( + p1: *mut ::core::ffi::c_int, + ) -> *mut ::core::ffi::c_int; #[link_name = "_ZNK1S12const_methodERiS0_"] pub(crate) fn __rust_thunk___ZNK1S12const_methodERiS0_( __this: *const crate::S, - p1: *mut i32, - p2: *mut i32, - ) -> *mut i32; + p1: *mut ::core::ffi::c_int, + p2: *mut ::core::ffi::c_int, + ) -> *mut ::core::ffi::c_int; #[link_name = "_ZN1S6methodERiS0_"] pub(crate) fn __rust_thunk___ZN1S6methodERiS0_( __this: *mut crate::S, - p1: *mut i32, - p2: *mut i32, - ) -> *mut i32; + p1: *mut ::core::ffi::c_int, + p2: *mut ::core::ffi::c_int, + ) -> *mut ::core::ffi::c_int; #[link_name = "_ZN44TriviallyCopyableButNontriviallyDestructibleD1Ev"] pub(crate) fn __rust_thunk___ZN44TriviallyCopyableButNontriviallyDestructibleD1Ev<'a>( __this: ::core::pin::Pin<&'a mut crate::TriviallyCopyableButNontriviallyDestructible>, ); #[link_name = "_Z12take_pointerPi"] - pub(crate) fn __rust_thunk___Z12take_pointerPi(p: *mut i32); + pub(crate) fn __rust_thunk___Z12take_pointerPi(p: *mut ::core::ffi::c_int); } } diff --git a/rs_bindings_from_cc/test/golden/no_unique_address_rs_api.rs b/rs_bindings_from_cc/test/golden/no_unique_address_rs_api.rs index c30a0ce5..6d19e127 100644 --- a/rs_bindings_from_cc/test/golden/no_unique_address_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/no_unique_address_rs_api.rs @@ -45,8 +45,8 @@ pub struct Struct { } forward_declare::unsafe_define!(forward_declare::symbol!("Struct"), crate::Struct); impl Struct { - pub fn field1(&self) -> &i32 { - unsafe { &*(&self.field1 as *const _ as *const i32) } + pub fn field1(&self) -> &::core::ffi::c_int { + unsafe { &*(&self.field1 as *const _ as *const ::core::ffi::c_int) } } pub fn field2(&self) -> &u8 { unsafe { &*(&self.field2 as *const _ as *const u8) } @@ -95,7 +95,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for Struct { impl Struct { #[inline(always)] - pub fn Make(f1: i32, f2: u8) -> crate::Struct { + pub fn Make(f1: ::core::ffi::c_int, f2: u8) -> crate::Struct { unsafe { let mut __return = ::core::mem::MaybeUninit::::uninit(); crate::detail::__rust_thunk___ZN6Struct4MakeEic(&mut __return, f1, f2); @@ -126,8 +126,8 @@ forward_declare::unsafe_define!( crate::PaddingBetweenFields ); impl PaddingBetweenFields { - pub fn field2(&self) -> &i32 { - unsafe { &*(&self.field2 as *const _ as *const i32) } + pub fn field2(&self) -> &::core::ffi::c_int { + unsafe { &*(&self.field2 as *const _ as *const ::core::ffi::c_int) } } } @@ -173,7 +173,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for PaddingBetwe impl PaddingBetweenFields { #[inline(always)] - pub fn Make(f1: u8, f2: i32) -> crate::PaddingBetweenFields { + pub fn Make(f1: u8, f2: ::core::ffi::c_int) -> crate::PaddingBetweenFields { unsafe { let mut __return = ::core::mem::MaybeUninit::::uninit(); crate::detail::__rust_thunk___ZN20PaddingBetweenFields4MakeEci(&mut __return, f1, f2); @@ -191,7 +191,7 @@ impl PaddingBetweenFields { #[repr(C)] pub struct FieldInTailPadding_InnerStruct { /// size: 4, alignment: 4 => offset: 0 - pub inner_int_field: i32, + pub inner_int_field: ::core::ffi::c_int, /// size: 1, alignment: 1 => offset: 4 pub inner_char_field: u8, } @@ -373,10 +373,10 @@ impl<'b> ::ctor::Assign<::ctor::RvalueReference<'b, Self>> for FieldInTailPaddin } } -impl ::ctor::CtorNew<(i32, u8, u8)> for FieldInTailPadding { +impl ::ctor::CtorNew<(::core::ffi::c_int, u8, u8)> for FieldInTailPadding { type CtorType = impl ::ctor::Ctor; #[inline(always)] - fn ctor_new(args: (i32, u8, u8)) -> Self::CtorType { + fn ctor_new(args: (::core::ffi::c_int, u8, u8)) -> Self::CtorType { let (inner_int, inner_char, outer_char) = args; unsafe { ::ctor::FnCtor::new( @@ -416,7 +416,7 @@ mod detail { ) -> &'a mut crate::Struct; pub(crate) fn __rust_thunk___ZN6Struct4MakeEic( __return: &mut ::core::mem::MaybeUninit, - f1: i32, + f1: ::core::ffi::c_int, f2: u8, ); pub(crate) fn __rust_thunk___ZN20PaddingBetweenFieldsC1Ev<'a>( @@ -437,7 +437,7 @@ mod detail { pub(crate) fn __rust_thunk___ZN20PaddingBetweenFields4MakeEci( __return: &mut ::core::mem::MaybeUninit, f1: u8, - f2: i32, + f2: ::core::ffi::c_int, ); pub(crate) fn __rust_thunk___ZN30FieldInTailPadding_InnerStructC1Ev<'a>( __this: &'a mut ::core::mem::MaybeUninit, @@ -474,7 +474,7 @@ mod detail { ) -> ::core::pin::Pin<&'a mut crate::FieldInTailPadding>; pub(crate) fn __rust_thunk___ZN18FieldInTailPaddingC1Eicc<'a>( __this: &'a mut ::core::mem::MaybeUninit, - inner_int: i32, + inner_int: ::core::ffi::c_int, inner_char: u8, outer_char: u8, ); @@ -524,7 +524,7 @@ const _: () = const _: () = assert!(memoffset::offset_of!(crate::FieldInTailPadding_InnerStruct, inner_char_field) == 4); const _: () = { - static_assertions::assert_impl_all!(i32:Copy); + static_assertions::assert_impl_all!(::core::ffi::c_int:Copy); }; const _: () = { static_assertions::assert_impl_all!(u8:Copy); diff --git a/rs_bindings_from_cc/test/golden/nontrivial_type_rs_api.rs b/rs_bindings_from_cc/test/golden/nontrivial_type_rs_api.rs index a76580e7..d1fb229e 100644 --- a/rs_bindings_from_cc/test/golden/nontrivial_type_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/nontrivial_type_rs_api.rs @@ -35,7 +35,7 @@ #[repr(C)] pub struct Nontrivial { __non_field_data: [::core::mem::MaybeUninit; 0], - pub field: i32, + pub field: ::core::ffi::c_int, } forward_declare::unsafe_define!(forward_declare::symbol!("Nontrivial"), crate::Nontrivial); @@ -56,10 +56,10 @@ impl ::ctor::CtorNew<()> for Nontrivial { } } -impl ::ctor::CtorNew for Nontrivial { +impl ::ctor::CtorNew<::core::ffi::c_int> for Nontrivial { type CtorType = impl ::ctor::Ctor; #[inline(always)] - fn ctor_new(args: i32) -> Self::CtorType { + fn ctor_new(args: ::core::ffi::c_int) -> Self::CtorType { let field = args; unsafe { ::ctor::FnCtor::new( @@ -73,19 +73,19 @@ impl ::ctor::CtorNew for Nontrivial { } } } -impl ::ctor::CtorNew<(i32,)> for Nontrivial { +impl ::ctor::CtorNew<(::core::ffi::c_int,)> for Nontrivial { type CtorType = impl ::ctor::Ctor; #[inline(always)] - fn ctor_new(args: (i32,)) -> Self::CtorType { + fn ctor_new(args: (::core::ffi::c_int,)) -> Self::CtorType { let (arg,) = args; - >::ctor_new(arg) + >::ctor_new(arg) } } -impl ::ctor::CtorNew<(i32, i32)> for Nontrivial { +impl ::ctor::CtorNew<(::core::ffi::c_int, ::core::ffi::c_int)> for Nontrivial { type CtorType = impl ::ctor::Ctor; #[inline(always)] - fn ctor_new(args: (i32, i32)) -> Self::CtorType { + fn ctor_new(args: (::core::ffi::c_int, ::core::ffi::c_int)) -> Self::CtorType { let (field, unused) = args; unsafe { ::ctor::FnCtor::new( @@ -174,9 +174,9 @@ impl<'b> ::ctor::Assign<::ctor::RvalueReference<'b, Self>> for Nontrivial { } } -impl ::ctor::Assign for Nontrivial { +impl ::ctor::Assign<::core::ffi::c_int> for Nontrivial { #[inline(always)] - fn assign<'a>(self: ::core::pin::Pin<&'a mut Self>, __param_0: i32) { + fn assign<'a>(self: ::core::pin::Pin<&'a mut Self>, __param_0: ::core::ffi::c_int) { unsafe { crate::detail::__rust_thunk___ZN10NontrivialaSEi(self, __param_0); } @@ -257,7 +257,7 @@ impl Nontrivial { #[repr(C)] pub struct NontrivialInline { __non_field_data: [::core::mem::MaybeUninit; 0], - pub field: i32, + pub field: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!("NontrivialInline"), @@ -281,10 +281,10 @@ impl ::ctor::CtorNew<()> for NontrivialInline { } } -impl ::ctor::CtorNew for NontrivialInline { +impl ::ctor::CtorNew<::core::ffi::c_int> for NontrivialInline { type CtorType = impl ::ctor::Ctor; #[inline(always)] - fn ctor_new(args: i32) -> Self::CtorType { + fn ctor_new(args: ::core::ffi::c_int) -> Self::CtorType { let field = args; unsafe { ::ctor::FnCtor::new( @@ -298,19 +298,19 @@ impl ::ctor::CtorNew for NontrivialInline { } } } -impl ::ctor::CtorNew<(i32,)> for NontrivialInline { +impl ::ctor::CtorNew<(::core::ffi::c_int,)> for NontrivialInline { type CtorType = impl ::ctor::Ctor; #[inline(always)] - fn ctor_new(args: (i32,)) -> Self::CtorType { + fn ctor_new(args: (::core::ffi::c_int,)) -> Self::CtorType { let (arg,) = args; - >::ctor_new(arg) + >::ctor_new(arg) } } -impl ::ctor::CtorNew<(i32, i32)> for NontrivialInline { +impl ::ctor::CtorNew<(::core::ffi::c_int, ::core::ffi::c_int)> for NontrivialInline { type CtorType = impl ::ctor::Ctor; #[inline(always)] - fn ctor_new(args: (i32, i32)) -> Self::CtorType { + fn ctor_new(args: (::core::ffi::c_int, ::core::ffi::c_int)) -> Self::CtorType { let (field, unused) = args; unsafe { ::ctor::FnCtor::new( @@ -399,9 +399,9 @@ impl<'b> ::ctor::Assign<::ctor::RvalueReference<'b, Self>> for NontrivialInline } } -impl ::ctor::Assign for NontrivialInline { +impl ::ctor::Assign<::core::ffi::c_int> for NontrivialInline { #[inline(always)] - fn assign<'a>(self: ::core::pin::Pin<&'a mut Self>, __param_0: i32) { + fn assign<'a>(self: ::core::pin::Pin<&'a mut Self>, __param_0: ::core::ffi::c_int) { unsafe { crate::detail::__rust_thunk___ZN16NontrivialInlineaSEi(self, __param_0); } @@ -538,7 +538,7 @@ impl<'b> ::ctor::Assign<::ctor::RvalueReference<'b, Self>> for NontrivialMembers #[repr(C)] pub struct NontrivialUnpin { __non_field_data: [::core::mem::MaybeUninit; 0], - pub field: i32, + pub field: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!("NontrivialUnpin"), @@ -556,9 +556,9 @@ impl Default for NontrivialUnpin { } } -impl From for NontrivialUnpin { +impl From<::core::ffi::c_int> for NontrivialUnpin { #[inline(always)] - fn from(field: i32) -> Self { + fn from(field: ::core::ffi::c_int) -> Self { let mut tmp = ::core::mem::MaybeUninit::::zeroed(); unsafe { crate::detail::__rust_thunk___ZN15NontrivialUnpinC1Ei(&mut tmp, field); @@ -621,9 +621,9 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for NontrivialUn } } -impl ::ctor::UnpinAssign for NontrivialUnpin { +impl ::ctor::UnpinAssign<::core::ffi::c_int> for NontrivialUnpin { #[inline(always)] - fn unpin_assign<'a>(&'a mut self, __param_0: i32) { + fn unpin_assign<'a>(&'a mut self, __param_0: ::core::ffi::c_int) { unsafe { crate::detail::__rust_thunk___ZN15NontrivialUnpinaSEi(self, __param_0); } @@ -927,13 +927,13 @@ mod detail { #[link_name = "_ZN10NontrivialC1Ei"] pub(crate) fn __rust_thunk___ZN10NontrivialC1Ei<'a>( __this: &'a mut ::core::mem::MaybeUninit, - field: i32, + field: ::core::ffi::c_int, ); #[link_name = "_ZN10NontrivialC1Eii"] pub(crate) fn __rust_thunk___ZN10NontrivialC1Eii<'a>( __this: &'a mut ::core::mem::MaybeUninit, - field: i32, - unused: i32, + field: ::core::ffi::c_int, + unused: ::core::ffi::c_int, ); #[link_name = "_ZN10NontrivialC1ERKS_"] pub(crate) fn __rust_thunk___ZN10NontrivialC1ERKS_<'a, 'b>( @@ -958,7 +958,7 @@ mod detail { #[link_name = "_ZN10NontrivialaSEi"] pub(crate) fn __rust_thunk___ZN10NontrivialaSEi<'a>( __this: ::core::pin::Pin<&'a mut crate::Nontrivial>, - __param_0: i32, + __param_0: ::core::ffi::c_int, ) -> ::core::pin::Pin<&'a mut crate::Nontrivial>; pub(crate) fn __rust_thunk___ZN10NontrivialaSEf<'a>( __return: &mut ::core::mem::MaybeUninit, @@ -998,12 +998,12 @@ mod detail { ); pub(crate) fn __rust_thunk___ZN16NontrivialInlineC1Ei<'a>( __this: &'a mut ::core::mem::MaybeUninit, - field: i32, + field: ::core::ffi::c_int, ); pub(crate) fn __rust_thunk___ZN16NontrivialInlineC1Eii<'a>( __this: &'a mut ::core::mem::MaybeUninit, - field: i32, - unused: i32, + field: ::core::ffi::c_int, + unused: ::core::ffi::c_int, ); pub(crate) fn __rust_thunk___ZN16NontrivialInlineC1ERKS_<'a, 'b>( __this: &'a mut ::core::mem::MaybeUninit, @@ -1023,7 +1023,7 @@ mod detail { ) -> ::core::pin::Pin<&'a mut crate::NontrivialInline>; pub(crate) fn __rust_thunk___ZN16NontrivialInlineaSEi<'a>( __this: ::core::pin::Pin<&'a mut crate::NontrivialInline>, - __param_0: i32, + __param_0: ::core::ffi::c_int, ) -> ::core::pin::Pin<&'a mut crate::NontrivialInline>; pub(crate) fn __rust_thunk___ZN16NontrivialInlineD1Ev<'a>( __this: ::core::pin::Pin<&'a mut crate::NontrivialInline>, @@ -1060,7 +1060,7 @@ mod detail { #[link_name = "_ZN15NontrivialUnpinC1Ei"] pub(crate) fn __rust_thunk___ZN15NontrivialUnpinC1Ei<'a>( __this: &'a mut ::core::mem::MaybeUninit, - field: i32, + field: ::core::ffi::c_int, ); #[link_name = "_ZN15NontrivialUnpinC1ERKS_"] pub(crate) fn __rust_thunk___ZN15NontrivialUnpinC1ERKS_<'a, 'b>( @@ -1090,7 +1090,7 @@ mod detail { #[link_name = "_ZN15NontrivialUnpinaSEi"] pub(crate) fn __rust_thunk___ZN15NontrivialUnpinaSEi<'a>( __this: &'a mut crate::NontrivialUnpin, - __param_0: i32, + __param_0: ::core::ffi::c_int, ) -> &'a mut crate::NontrivialUnpin; #[link_name = "_ZN15NontrivialUnpinD1Ev"] pub(crate) fn __rust_thunk___ZN15NontrivialUnpinD1Ev<'a>( @@ -1195,7 +1195,7 @@ const _: () = { }; const _: () = assert!(memoffset::offset_of!(crate::Nontrivial, field) == 0); const _: () = { - static_assertions::assert_impl_all!(i32:Copy); + static_assertions::assert_impl_all!(::core::ffi::c_int:Copy); }; const _: () = assert!(::core::mem::size_of::() == 4); @@ -1208,7 +1208,7 @@ const _: () = { }; const _: () = assert!(memoffset::offset_of!(crate::NontrivialInline, field) == 0); const _: () = { - static_assertions::assert_impl_all!(i32:Copy); + static_assertions::assert_impl_all!(::core::ffi::c_int:Copy); }; const _: () = assert!(::core::mem::size_of::() == 4); @@ -1231,7 +1231,7 @@ const _: () = { }; const _: () = assert!(memoffset::offset_of!(crate::NontrivialUnpin, field) == 0); const _: () = { - static_assertions::assert_impl_all!(i32:Copy); + static_assertions::assert_impl_all!(::core::ffi::c_int:Copy); }; const _: () = assert!(::core::mem::size_of::() == 1); diff --git a/rs_bindings_from_cc/test/golden/operators_rs_api.rs b/rs_bindings_from_cc/test/golden/operators_rs_api.rs index 62a6a15c..b3a31a22 100644 --- a/rs_bindings_from_cc/test/golden/operators_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/operators_rs_api.rs @@ -517,18 +517,18 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for Overloaded { } } -impl<'a> ::core::ops::Add for &'a crate::Overloaded { - type Output = i32; +impl<'a> ::core::ops::Add<::core::ffi::c_int> for &'a crate::Overloaded { + type Output = ::core::ffi::c_int; #[inline(always)] - fn add(self, rhs: i32) -> Self::Output { + fn add(self, rhs: ::core::ffi::c_int) -> Self::Output { unsafe { crate::detail::__rust_thunk___ZplRK10Overloadedi(self, rhs) } } } -impl<'a> ::core::ops::Add for &'a crate::Overloaded { - type Output = i32; +impl<'a> ::core::ops::Add<::core::ffi::c_uint> for &'a crate::Overloaded { + type Output = ::core::ffi::c_int; #[inline(always)] - fn add(self, rhs: u32) -> Self::Output { + fn add(self, rhs: ::core::ffi::c_uint) -> Self::Output { unsafe { crate::detail::__rust_thunk___ZplRK10Overloadedj(self, rhs) } } } @@ -796,9 +796,9 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for AddAssignMem } } -impl ::core::ops::AddAssign for AddAssignMemberInt { +impl ::core::ops::AddAssign<::core::ffi::c_int> for AddAssignMemberInt { #[inline(always)] - fn add_assign<'a>(&'a mut self, rhs: i32) { + fn add_assign<'a>(&'a mut self, rhs: ::core::ffi::c_int) { unsafe { crate::detail::__rust_thunk___ZN18AddAssignMemberIntpLEi(self, rhs); } @@ -1649,13 +1649,13 @@ mod detail { #[link_name = "_ZplRK10Overloadedi"] pub(crate) fn __rust_thunk___ZplRK10Overloadedi<'a>( lhs: &'a crate::Overloaded, - rhs: i32, - ) -> i32; + rhs: ::core::ffi::c_int, + ) -> ::core::ffi::c_int; #[link_name = "_ZplRK10Overloadedj"] pub(crate) fn __rust_thunk___ZplRK10Overloadedj<'a>( lhs: &'a crate::Overloaded, - rhs: u32, - ) -> i32; + rhs: ::core::ffi::c_uint, + ) -> ::core::ffi::c_int; pub(crate) fn __rust_thunk___ZN15IncompatibleLHSC1Ev<'a>( __this: &'a mut ::core::mem::MaybeUninit, ); @@ -1728,8 +1728,8 @@ mod detail { #[link_name = "_ZN18AddAssignMemberIntpLEi"] pub(crate) fn __rust_thunk___ZN18AddAssignMemberIntpLEi<'a>( __this: &'a mut crate::AddAssignMemberInt, - rhs: i32, - ) -> i32; + rhs: ::core::ffi::c_int, + ) -> ::core::ffi::c_int; pub(crate) fn __rust_thunk___ZN25AddAssignMemberByConstRefC1Ev<'a>( __this: &'a mut ::core::mem::MaybeUninit, ); diff --git a/rs_bindings_from_cc/test/golden/private_members_rs_api.rs b/rs_bindings_from_cc/test/golden/private_members_rs_api.rs index 71aec095..2df75fac 100644 --- a/rs_bindings_from_cc/test/golden/private_members_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/private_members_rs_api.rs @@ -25,7 +25,7 @@ pub mod test_namespace_bindings { #[repr(C, align(4))] pub struct SomeClass { __non_field_data: [::core::mem::MaybeUninit; 0], - pub public_member_variable_: i32, + pub public_member_variable_: ::core::ffi::c_int, /// Reason for representing this field as a blob of bytes: /// Types of non-public C++ fields can be elided away pub(crate) private_member_variable_: [::core::mem::MaybeUninit; 4], diff --git a/rs_bindings_from_cc/test/golden/static_methods_rs_api.rs b/rs_bindings_from_cc/test/golden/static_methods_rs_api.rs index 7334caa1..ac81ef75 100644 --- a/rs_bindings_from_cc/test/golden/static_methods_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/static_methods_rs_api.rs @@ -73,7 +73,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for SomeClass { impl SomeClass { /// Example of a factory method. #[inline(always)] - pub fn static_factory_method(initial_value_of_field: i32) -> crate::SomeClass { + pub fn static_factory_method(initial_value_of_field: ::core::ffi::c_int) -> crate::SomeClass { unsafe { let mut __return = ::core::mem::MaybeUninit::::uninit(); crate::detail::__rust_thunk___ZN9SomeClass21static_factory_methodEi( @@ -88,7 +88,10 @@ impl SomeClass { impl SomeClass { /// Static method working on primitive types (and unrelated to the struct). #[inline(always)] - pub fn static_method_that_multiplies_its_args(x: i32, y: i32) -> i32 { + pub fn static_method_that_multiplies_its_args( + x: ::core::ffi::c_int, + y: ::core::ffi::c_int, + ) -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___ZN9SomeClass38static_method_that_multiplies_its_argsEii( x, y, @@ -120,13 +123,13 @@ mod detail { ) -> &'a mut crate::SomeClass; pub(crate) fn __rust_thunk___ZN9SomeClass21static_factory_methodEi( __return: &mut ::core::mem::MaybeUninit, - initial_value_of_field: i32, + initial_value_of_field: ::core::ffi::c_int, ); #[link_name = "_ZN9SomeClass38static_method_that_multiplies_its_argsEii"] pub(crate) fn __rust_thunk___ZN9SomeClass38static_method_that_multiplies_its_argsEii( - x: i32, - y: i32, - ) -> i32; + x: ::core::ffi::c_int, + y: ::core::ffi::c_int, + ) -> ::core::ffi::c_int; } } diff --git a/rs_bindings_from_cc/test/golden/templates_rs_api.rs b/rs_bindings_from_cc/test/golden/templates_rs_api.rs index 05070f8f..1ad275c9 100644 --- a/rs_bindings_from_cc/test/golden/templates_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/templates_rs_api.rs @@ -534,7 +534,9 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> impl __CcTemplateInstN23test_namespace_bindings10MyTemplateIiEE { #[inline(always)] - pub fn Create(value: i32) -> crate::__CcTemplateInstN23test_namespace_bindings10MyTemplateIiEE { + pub fn Create( + value: ::core::ffi::c_int, + ) -> crate::__CcTemplateInstN23test_namespace_bindings10MyTemplateIiEE { unsafe { let mut __return = ::core::mem::MaybeUninit::::uninit(); crate::detail::__rust_thunk___ZN23test_namespace_bindings10MyTemplateIiE6CreateEi__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3atemplates_5fcc(&mut __return,value); @@ -545,7 +547,7 @@ impl __CcTemplateInstN23test_namespace_bindings10MyTemplateIiEE { impl __CcTemplateInstN23test_namespace_bindings10MyTemplateIiEE { #[inline(always)] - pub fn value<'a>(&'a self) -> &'a i32 { + pub fn value<'a>(&'a self) -> &'a ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___ZNK23test_namespace_bindings10MyTemplateIiE5valueEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3atemplates_5fcc(self) } @@ -556,7 +558,7 @@ impl __CcTemplateInstN23test_namespace_bindings10MyTemplateIiEE { #[repr(C)] pub struct __CcTemplateInstN23test_namespace_bindings21TemplateWithTwoParamsINS0_IiiEEiEE { pub value1: crate::__CcTemplateInstN23test_namespace_bindings21TemplateWithTwoParamsIiiEE, - pub value2: i32, + pub value2: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!( @@ -614,7 +616,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> #[derive(Clone, Copy)] #[repr(C)] pub struct __CcTemplateInstN23test_namespace_bindings21TemplateWithTwoParamsIifEE { - pub value1: i32, + pub value1: ::core::ffi::c_int, pub value2: f32, } forward_declare::unsafe_define!( @@ -671,8 +673,8 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> #[derive(Clone, Copy)] #[repr(C)] pub struct __CcTemplateInstN23test_namespace_bindings21TemplateWithTwoParamsIiiEE { - pub value1: i32, - pub value2: i32, + pub value1: ::core::ffi::c_int, + pub value2: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!("test_namespace_bindings::TemplateWithTwoParams"), @@ -991,7 +993,7 @@ impl<'b> ::ctor::Assign<::ctor::RvalueReference<'b, Self>> impl __CcTemplateInstN24template_template_params10MyTemplateINS_6PolicyEEE { #[inline(always)] - pub fn GetPolicy() -> i32 { + pub fn GetPolicy() -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___ZN24template_template_params10MyTemplateINS_6PolicyEE9GetPolicyEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3atemplates_5fcc() } @@ -1175,13 +1177,13 @@ mod detail { __return: &mut ::core::mem::MaybeUninit< crate::__CcTemplateInstN23test_namespace_bindings10MyTemplateIiEE, >, - value: i32, + value: ::core::ffi::c_int, ); pub(crate) fn __rust_thunk___ZNK23test_namespace_bindings10MyTemplateIiE5valueEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3atemplates_5fcc< 'a, >( __this: &'a crate::__CcTemplateInstN23test_namespace_bindings10MyTemplateIiEE, - ) -> &'a i32; + ) -> &'a ::core::ffi::c_int; pub(crate) fn __rust_thunk___ZN23test_namespace_bindings21TemplateWithTwoParamsINS0_IiiEEiEC1Ev__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3atemplates_5fcc< 'a, >( @@ -1381,7 +1383,7 @@ mod detail { &'a mut crate::__CcTemplateInstN24template_template_params10MyTemplateINS_6PolicyEEE, >; pub(crate) fn __rust_thunk___ZN24template_template_params10MyTemplateINS_6PolicyEE9GetPolicyEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3atemplates_5fcc() - -> i32; + -> ::core::ffi::c_int; } } diff --git a/rs_bindings_from_cc/test/golden/templates_source_order_rs_api.rs b/rs_bindings_from_cc/test/golden/templates_source_order_rs_api.rs index 89ce32f0..5101277a 100644 --- a/rs_bindings_from_cc/test/golden/templates_source_order_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/templates_source_order_rs_api.rs @@ -410,7 +410,7 @@ forward_declare::unsafe_define!( impl __CcTemplateInst10MyTemplateIiE { #[inline(always)] - pub unsafe fn processT(__this: *mut Self, t: i32) { + pub unsafe fn processT(__this: *mut Self, t: ::core::ffi::c_int) { crate::detail::__rust_thunk___ZN10MyTemplateIiE8processTEi__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3atemplates_5fsource_5forder_5fcc(__this,t) } } @@ -453,7 +453,7 @@ mod detail { ); pub(crate) fn __rust_thunk___ZN10MyTemplateIiE8processTEi__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2fgolden_3atemplates_5fsource_5forder_5fcc( __this: *mut crate::__CcTemplateInst10MyTemplateIiE, - t: i32, + t: ::core::ffi::c_int, ); } } diff --git a/rs_bindings_from_cc/test/golden/trivial_type_rs_api.rs b/rs_bindings_from_cc/test/golden/trivial_type_rs_api.rs index 6b25647c..5188e8c0 100644 --- a/rs_bindings_from_cc/test/golden/trivial_type_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/trivial_type_rs_api.rs @@ -32,7 +32,7 @@ pub mod ns { #[derive(Clone, Copy)] #[repr(C)] pub struct Trivial { - pub trivial_field: i32, + pub trivial_field: ::core::ffi::c_int, } forward_declare::unsafe_define!(forward_declare::symbol!("Trivial"), crate::ns::Trivial); @@ -127,7 +127,7 @@ pub mod ns { #[::ctor::recursively_pinned] #[repr(C)] pub struct TrivialNonfinal { - pub trivial_field: i32, + pub trivial_field: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!("TrivialNonfinal"), diff --git a/rs_bindings_from_cc/test/golden/typedefs_rs_api.rs b/rs_bindings_from_cc/test/golden/typedefs_rs_api.rs index db08a8e1..53469703 100644 --- a/rs_bindings_from_cc/test/golden/typedefs_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/typedefs_rs_api.rs @@ -326,7 +326,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for SomeOtherUni } #[inline(always)] -pub fn FunctionUsingNestedType() -> i32 { +pub fn FunctionUsingNestedType() -> ::core::ffi::c_int { unsafe { crate::detail::__rust_thunk___Z23FunctionUsingNestedTypev() } } @@ -405,7 +405,7 @@ mod detail { __param_0: ::ctor::RvalueReference<'b, crate::SomeOtherUnion>, ) -> &'a mut crate::SomeOtherUnion; #[link_name = "_Z23FunctionUsingNestedTypev"] - pub(crate) fn __rust_thunk___Z23FunctionUsingNestedTypev() -> i32; + pub(crate) fn __rust_thunk___Z23FunctionUsingNestedTypev() -> ::core::ffi::c_int; } } diff --git a/rs_bindings_from_cc/test/golden/types_rs_api.rs b/rs_bindings_from_cc/test/golden/types_rs_api.rs index f7fe7e58..82e9f294 100644 --- a/rs_bindings_from_cc/test/golden/types_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/types_rs_api.rs @@ -80,23 +80,23 @@ forward_declare::forward_declare!(pub ForwardDeclaredStruct = forward_declare::s pub struct FieldTypeTestStruct { pub bool_field: bool, pub char_field: u8, - pub unsigned_char_field: u8, - pub signed_char_field: i8, + pub unsigned_char_field: ::core::ffi::c_uchar, + pub signed_char_field: ::core::ffi::c_schar, pub char16_t_field: u16, pub char32_t_field: u32, pub wchar_t_field: i32, - pub short_field: i16, - pub int_field: i32, - pub long_field: i64, - pub long_long_field: i64, - pub unsigned_short_field: u16, - pub unsigned_int_field: u32, - pub unsigned_long_field: u64, - pub unsigned_long_long_field: u64, - pub signed_short_field: i16, - pub signed_int_field: i32, - pub signed_long_field: i64, - pub signed_long_long_field: i64, + pub short_field: ::core::ffi::c_short, + pub int_field: ::core::ffi::c_int, + pub long_field: ::core::ffi::c_long, + pub long_long_field: ::core::ffi::c_longlong, + pub unsigned_short_field: ::core::ffi::c_ushort, + pub unsigned_int_field: ::core::ffi::c_uint, + pub unsigned_long_field: ::core::ffi::c_ulong, + pub unsigned_long_long_field: ::core::ffi::c_ulonglong, + pub signed_short_field: ::core::ffi::c_short, + pub signed_int_field: ::core::ffi::c_int, + pub signed_long_field: ::core::ffi::c_long, + pub signed_long_long_field: ::core::ffi::c_longlong, /// Reason for representing this field as a blob of bytes: /// Unsupported type 'PtrDiff': No generated bindings found for 'PtrDiff' pub(crate) ptrdiff_t_field: [::core::mem::MaybeUninit; 8], @@ -105,7 +105,7 @@ pub struct FieldTypeTestStruct { pub(crate) size_t_field: [::core::mem::MaybeUninit; 8], pub float_field: f32, pub double_field: f64, - pub ptr_field: *mut i32, + pub ptr_field: *mut ::core::ffi::c_int, pub void_ptr_field: *mut ::core::ffi::c_void, pub const_void_ptr_field: *const ::core::ffi::c_void, pub void_double_ptr_field: *mut *mut ::core::ffi::c_void, @@ -145,8 +145,9 @@ pub fn VoidReturningFunction() { /// returning a function. In ML-like syntax: /// FunctionPointerReturningFunction : () -> (const int&, int*) -> int& #[inline(always)] -pub fn FunctionPointerReturningFunction() -> Option *mut i32> -{ +pub fn FunctionPointerReturningFunction() -> Option< + extern "C" fn(*const ::core::ffi::c_int, *mut ::core::ffi::c_int) -> *mut ::core::ffi::c_int, +> { unsafe { crate::detail::__rust_thunk___Z32FunctionPointerReturningFunctionv() } } @@ -200,8 +201,12 @@ mod detail { __param_0: ::ctor::RvalueReference<'b, crate::FieldTypeTestStruct>, ); pub(crate) fn __rust_thunk___Z21VoidReturningFunctionv(); - pub(crate) fn __rust_thunk___Z32FunctionPointerReturningFunctionv() - -> Option *mut i32>; + pub(crate) fn __rust_thunk___Z32FunctionPointerReturningFunctionv() -> Option< + extern "C" fn( + *const ::core::ffi::c_int, + *mut ::core::ffi::c_int, + ) -> *mut ::core::ffi::c_int, + >; pub(crate) fn __rust_thunk___Z24FunctionWithVoidPointersPvPKv( __param_0: *mut ::core::ffi::c_void, __param_1: *const ::core::ffi::c_void, diff --git a/rs_bindings_from_cc/test/golden/unions_rs_api.rs b/rs_bindings_from_cc/test/golden/unions_rs_api.rs index b5a293a4..c0833ec9 100644 --- a/rs_bindings_from_cc/test/golden/unions_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/unions_rs_api.rs @@ -76,7 +76,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for EmptyUnion { #[repr(C)] pub struct Nontrivial { __non_field_data: [::core::mem::MaybeUninit; 0], - pub field: i32, + pub field: ::core::ffi::c_int, } forward_declare::unsafe_define!(forward_declare::symbol!("Nontrivial"), crate::Nontrivial); @@ -179,8 +179,8 @@ impl ::ctor::PinnedDrop for TriviallyCopyableButNontriviallyDestructible { pub union NonEmptyUnion { pub bool_field: bool, pub char_field: u8, - pub int_field: i32, - pub long_long_field: i64, + pub int_field: ::core::ffi::c_int, + pub long_long_field: ::core::ffi::c_longlong, } forward_declare::unsafe_define!(forward_declare::symbol!("NonEmptyUnion"), crate::NonEmptyUnion); @@ -323,7 +323,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for UnionWithOpa #[::ctor::recursively_pinned] #[repr(C)] pub struct TrivialButInheritable { - pub x: i32, + pub x: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!("TrivialButInheritable"), @@ -882,10 +882,10 @@ const _: () = { static_assertions::assert_impl_all!(u8:Copy); }; const _: () = { - static_assertions::assert_impl_all!(i32:Copy); + static_assertions::assert_impl_all!(::core::ffi::c_int:Copy); }; const _: () = { - static_assertions::assert_impl_all!(i64:Copy); + static_assertions::assert_impl_all!(::core::ffi::c_longlong:Copy); }; const _: () = assert!(::core::mem::size_of::() == 4); diff --git a/rs_bindings_from_cc/test/golden/unsupported_rs_api.rs b/rs_bindings_from_cc/test/golden/unsupported_rs_api.rs index 5939b748..dbb4fd2f 100644 --- a/rs_bindings_from_cc/test/golden/unsupported_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/unsupported_rs_api.rs @@ -28,7 +28,7 @@ #[derive(Clone, Copy)] #[repr(C)] pub struct TrivialCustomType { - pub i: i32, + pub i: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!("TrivialCustomType"), @@ -85,7 +85,7 @@ impl<'b> ::ctor::UnpinAssign<::ctor::RvalueReference<'b, Self>> for TrivialCusto #[repr(C)] pub struct NontrivialCustomType { __non_field_data: [::core::mem::MaybeUninit; 0], - pub i: i32, + pub i: ::core::ffi::c_int, } forward_declare::unsafe_define!( forward_declare::symbol!("NontrivialCustomType"), diff --git a/rs_bindings_from_cc/test/rs_bindings_from_cc_test.sh b/rs_bindings_from_cc/test/rs_bindings_from_cc_test.sh index 1a8ae7e8..0c4c1339 100755 --- a/rs_bindings_from_cc/test/rs_bindings_from_cc_test.sh +++ b/rs_bindings_from_cc/test/rs_bindings_from_cc_test.sh @@ -199,7 +199,7 @@ function test::rustfmt_config_path() { local cc_out="${TEST_TMPDIR}/rs_api_impl.cc" local hdr="${TEST_TMPDIR}/hello_world.h" - echo "int MyFunction(int arg1, int arg2);" > "${hdr}" + echo "float MyFunction(float arg1, float arg2);" > "${hdr}" local json json="$(cat <<-EOT @@ -223,13 +223,13 @@ EOT EXPECT_FILE_NOT_EMPTY "${rs_out}" # Expecting: - # pub fn MyFunction(arg1: i32, arg2: i32) -> i32 + # pub fn MyFunction(arg1: f32, arg2: f32) -> f32 EXPECT_SUCCEED \ - "grep \"MyFunction.*arg1:.*i32,.*arg2:.*i32.*)\" \"${rs_out}\"" \ + "grep \"MyFunction.*arg1:.*f32,.*arg2:.*f32.*)\" \"${rs_out}\"" \ "Verify function args are on single line when using default rustfmt config (1)" EXPECT_FAIL \ - "grep \"^[^a-z]*arg1:[^a-z]*i32,[^a-z]*\\\$\" \"${rs_out}\"" \ - "Verify function args are *not on single line when using default rustfmt config (2)" + "grep \"^[^a-z]*arg1:[^a-z]*f32,[^a-z]*\\\$\" \"${rs_out}\"" \ + "Verify function args are on single line when using default rustfmt config (2)" ######################################################### # Testing a custom `rustfmt` config. @@ -255,15 +255,15 @@ EOF # Expecting: # pub fn MyFunction( - # arg1: i32, - # arg2: i32, - # ) -> i32 + # arg1: f32, + # arg2: f32, + # ) -> f32 EXPECT_FAIL \ - "grep \"MyFunction.*arg1:.*i32,.*arg2:.*i32.*)\" \"${rs_out}\"" \ - "Verify function args are *not* on single line when using default rustfmt config (1)" + "grep \"MyFunction.*arg1:.*f32,.*arg2:.*f32.*)\" \"${rs_out}\"" \ + "Verify function args are *not* on single line when using custom rustfmt config (1)" EXPECT_SUCCEED \ - "grep \"^[^a-z]*arg1:[^a-z]*i32,[^a-z]*\\\$\" \"${rs_out}\"" \ - "Verify function args are *not on single line when using default rustfmt config (2)" + "grep \"^[^a-z]*arg1:[^a-z]*f32,[^a-z]*\\\$\" \"${rs_out}\"" \ + "Verify function args are *not* on single line when using custom rustfmt config (2)" } function test::crubit_support_path() { diff --git a/rs_bindings_from_cc/type_map.cc b/rs_bindings_from_cc/type_map.cc index 4960c6cb..ae008ef0 100644 --- a/rs_bindings_from_cc/type_map.cc +++ b/rs_bindings_from_cc/type_map.cc @@ -53,7 +53,6 @@ std::optional MapKnownCcTypeToRsType( {"uint8_t", "u8"}, {"uint16_t", "u16"}, {"uint32_t", "u32"}, - {"uint64_t", "u64"}, {"std::uint8_t", "u8"}, {"std::uint16_t", "u16"},