From bd3c7b8b6f84d0309e818e946f80197b71a7f0fb Mon Sep 17 00:00:00 2001 From: Taylor Cramer Date: Fri, 27 Mar 2026 17:30:16 -0700 Subject: [PATCH] Generate methods as free functions In the future, method generation will be optional, instead exposing only free functions. To ensure that feature is additive, begin by exposing free functions. PiperOrigin-RevId: 890712035 --- examples/cpp/method/example_generated.rs | 18 +- examples/cpp/virtual/example_generated.rs | 30 ++- .../database/code_snippet.rs | 27 ++- .../generate_bindings/generate_function.rs | 223 ++++++++++++++---- .../generate_struct_and_union.rs | 2 + rs_bindings_from_cc/generate_bindings/lib.rs | 5 +- .../test/annotations/do_not_bind_rs_api.rs | 21 +- .../test/annotations/owned_ptr_rs_api.rs | 18 +- .../test/annotations/rust_name_rs_api.rs | 49 +++- .../member_function_rs_api.rs | 20 +- .../test/golden/callables_rs_api.rs | 22 +- .../test/golden/callables_supported_rs_api.rs | 22 +- .../test/golden/compatibility_rs_api.rs | 23 +- .../test/golden/doc_comment_rs_api.rs | 36 ++- .../test/golden/inheritance_rs_api.rs | 55 ++++- .../test/golden/method_access_rs_api.rs | 42 +++- .../test/golden/method_qualifiers_rs_api.rs | 112 ++++++++- .../test/golden/no_elided_lifetimes_rs_api.rs | 38 ++- .../test/golden/no_unique_address_rs_api.rs | 56 +++-- .../test/golden/noexcept_rs_api.rs | 42 +++- .../test/golden/nontrivial_type_rs_api.rs | 70 +++++- .../test/golden/operators_rs_api.rs | 28 ++- .../test/golden/overloads_rs_api.rs | 16 +- .../test/golden/polymorphic_rs_api.rs | 12 +- .../test/golden/private_members_rs_api.rs | 30 ++- .../test/golden/static_methods_rs_api.rs | 43 +++- .../test/golden/trivial_type_rs_api.rs | 34 ++- .../test/references/references_rs_api.rs | 4 +- .../struct/destructors/destructors_rs_api.rs | 68 ++++-- .../inheritance/inherited_methods_rs_api.rs | 64 +++-- .../test/struct/methods/methods_rs_api.rs | 141 ++++++++--- .../methods_qualifiers_rs_api.rs | 99 ++++++-- .../templates/type_alias/type_alias_rs_api.rs | 35 ++- 33 files changed, 1240 insertions(+), 265 deletions(-) diff --git a/examples/cpp/method/example_generated.rs b/examples/cpp/method/example_generated.rs index 4bc4be020..38dfe6503 100644 --- a/examples/cpp/method/example_generated.rs +++ b/examples/cpp/method/example_generated.rs @@ -37,7 +37,7 @@ pub mod foo { /// Generated from: examples/cpp/method/example.h;l=14 #[inline(always)] pub unsafe fn MyMethod(__this: *mut Self) { - crate::detail::__rust_thunk___ZN3foo3Bar8MyMethodEv(__this) + self::bar::MyMethod(__this) } } @@ -52,6 +52,22 @@ pub mod foo { } } } + + pub mod bar { + #[allow(unused_imports)] + use super::*; + + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + /// + /// Generated from: examples/cpp/method/example.h;l=14 + #[inline(always)] + pub unsafe fn MyMethod(__this: *mut crate::foo::Bar) { + crate::detail::__rust_thunk___ZN3foo3Bar8MyMethodEv(__this) + } + } } // namespace foo diff --git a/examples/cpp/virtual/example_generated.rs b/examples/cpp/virtual/example_generated.rs index d6003c7ff..8a2d44e63 100644 --- a/examples/cpp/virtual/example_generated.rs +++ b/examples/cpp/virtual/example_generated.rs @@ -39,7 +39,7 @@ impl RustDerived { /// Generated from: examples/cpp/virtual/example.h;l=16 #[inline(always)] pub unsafe fn Method1(__this: *const Self) -> ::ffi_11::c_int { - crate::detail::__rust_thunk___ZNK11RustDerived7Method1Ev(__this) + self::rust_derived::Method1(__this) } /// # Safety /// @@ -49,7 +49,7 @@ impl RustDerived { /// Generated from: examples/cpp/virtual/example.h;l=18 #[inline(always)] pub unsafe fn Upcast(__this: *mut Self) -> *mut ::base::ExampleBase { - crate::detail::__rust_thunk___ZN11RustDerived6UpcastEv(__this) + self::rust_derived::Upcast(__this) } } @@ -132,6 +132,32 @@ unsafe impl ::operator::Delete for crate::RustDerived { } } +pub mod rust_derived { + #[allow(unused_imports)] + use super::*; + + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + /// + /// Generated from: examples/cpp/virtual/example.h;l=16 + #[inline(always)] + pub unsafe fn Method1(__this: *const crate::RustDerived) -> ::ffi_11::c_int { + crate::detail::__rust_thunk___ZNK11RustDerived7Method1Ev(__this) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + /// + /// Generated from: examples/cpp/virtual/example.h;l=18 + #[inline(always)] + pub unsafe fn Upcast(__this: *mut crate::RustDerived) -> *mut ::base::ExampleBase { + crate::detail::__rust_thunk___ZN11RustDerived6UpcastEv(__this) + } +} + // Generated from: nowhere/llvm/src/libcxx/include/__type_traits/integral_constant.h;l=21 // error: struct `std::integral_constant` could not be bound // template instantiation is not yet supported diff --git a/rs_bindings_from_cc/generate_bindings/database/code_snippet.rs b/rs_bindings_from_cc/generate_bindings/database/code_snippet.rs index f36925e2b..9bff47dab 100644 --- a/rs_bindings_from_cc/generate_bindings/database/code_snippet.rs +++ b/rs_bindings_from_cc/generate_bindings/database/code_snippet.rs @@ -56,6 +56,8 @@ pub struct ApiSnippets { pub features: FlagSet, pub member_functions: HashMap>, + + pub free_functions: HashMap>, } impl ApiSnippets { @@ -75,6 +77,9 @@ impl ApiSnippets { for (item_id, member_functions) in other.member_functions { self.member_functions.entry(item_id).or_default().extend(member_functions); } + for (item_id, free_methods) in other.free_functions { + self.free_functions.entry(item_id).or_default().extend(free_methods); + } self.thunks.extend(other.thunks); self.assertions.extend(other.assertions); self.cc_details.extend(other.cc_details); @@ -559,6 +564,18 @@ pub fn integer_constant_to_token_stream( }) } +/// Returns the name of the snake-cased module that exposes the given record's nested items. +pub fn record_name_to_associated_module_name(record_ident: &Ident) -> Ident { + let ident_string = record_ident.to_string(); + let snake_case_name = ident_string.to_snake_case(); + let name = if snake_case_name == ident_string { + format!("{}_items", snake_case_name) + } else { + snake_case_name + }; + make_rs_ident(&name) +} + pub fn generated_items_to_tokens<'db>( generated_items: &HashMap, db: &'db crate::BindingsGenerator<'db>, @@ -601,6 +618,7 @@ pub fn generated_items_to_tokens<'db>( delete, owned_type_name, member_methods, + free_functions, lifetime_params, } = record_item.as_ref(); @@ -790,16 +808,16 @@ pub fn generated_items_to_tokens<'db>( } .to_tokens(tokens); } - - if !nested_items.is_empty() { - let snake_case_name = make_rs_ident(&ident.to_string().to_snake_case()); + let module_name = record_name_to_associated_module_name(&ident); + if !free_functions.is_empty() || !nested_items.is_empty() { let nested_items_to_tokens = generated_items_to_token_stream(generated_items, db, nested_items); quote! { - pub mod #snake_case_name { + pub mod #module_name { #[allow(unused_imports)] use super::*; __NEWLINE__ __NEWLINE__ + #( #free_functions )* #nested_items_to_tokens } } @@ -1028,6 +1046,7 @@ pub struct Record { /// The name of the owning wrapper type when the type was annotated with CRUBIT_OWNED_POINTEE. pub owned_type_name: Option, pub member_methods: Vec, + pub free_functions: Vec, pub lifetime_params: Vec, } diff --git a/rs_bindings_from_cc/generate_bindings/generate_function.rs b/rs_bindings_from_cc/generate_bindings/generate_function.rs index 73d2c3291..7229ac7f7 100644 --- a/rs_bindings_from_cc/generate_bindings/generate_function.rs +++ b/rs_bindings_from_cc/generate_bindings/generate_function.rs @@ -5,7 +5,9 @@ use arc_anyhow::{ensure, Context, Result}; use code_gen_utils::{make_rs_ident, make_rs_lifetime_ident}; use crubit_abi_type::{CrubitAbiTypeToRustExprTokens, CrubitAbiTypeToRustTokens}; -use database::code_snippet::{ApiSnippets, Feature, GeneratedItem, Thunk, Visibility}; +use database::code_snippet::{ + record_name_to_associated_module_name, ApiSnippets, Feature, GeneratedItem, Thunk, Visibility, +}; use database::function_types::{FunctionId, GeneratedFunction, ImplFor, ImplKind, TraitName}; use database::rs_snippet::{ format_generic_params, format_generic_params_replacing_by_self, should_derive_clone, @@ -1065,7 +1067,7 @@ fn adjust_param_types_for_trait_impl( fn generate_func_body( db: &BindingsGenerator, impl_kind: &ImplKind, - crate_root_path: TokenStream, + crate_root_path: &TokenStream, return_type: &RsTypeKind, param_value_adjustments: &ParamValueAdjustments, thunk_ident: Ident, @@ -1074,6 +1076,21 @@ fn generate_func_body( ) -> Result { let ParamValueAdjustments { clone_prefixes, clone_suffixes } = param_value_adjustments; + // Note: for the time being, all !Unpin values are treated as if they were not + // trivially relocatable. We could, in the special case of trivial !Unpin types, + // not generate the thunk at all, but this would be a bit of extra work. + // + // TODO(jeanpierreda): separately handle non-Unpin and non-trivial types. + let return_type_or_self = { + let record = match impl_kind { + // Only use `Self` inside trait impls, and then only if the `Self` type is the same + // as the trait implementation record type. + ImplKind::Trait { record, impl_for: ImplFor::T, .. } => Some(&**record), + _ => None, + }; + return_type.to_token_stream_replacing_by_self(db, record) + }; + match &impl_kind { ImplKind::Trait { trait_name: TraitName::Clone | TraitName::Default | TraitName::From(_), @@ -1088,7 +1105,7 @@ fn generate_func_body( // we don't need to worry about them. Ok(quote! { #thunk_prepare - let mut tmp = ::core::mem::MaybeUninit::::zeroed(); + let mut tmp = ::core::mem::MaybeUninit::<#return_type_or_self>::zeroed(); unsafe { #crate_root_path::detail::#thunk_ident( &raw mut tmp as *mut _ #( , #thunk_args )* ); tmp.assume_init() @@ -1096,19 +1113,6 @@ fn generate_func_body( }) } _ => { - // Note: for the time being, all !Unpin values are treated as if they were not - // trivially relocatable. We could, in the special case of trivial !Unpin types, - // not generate the thunk at all, but this would be a bit of extra work. - // - // TODO(jeanpierreda): separately handle non-Unpin and non-trivial types. - let return_type_or_self = { - let record = match impl_kind { - ImplKind::Struct { record, .. } - | ImplKind::Trait { record, impl_for: ImplFor::T, .. } => Some(&**record), - _ => None, - }; - return_type.to_token_stream_replacing_by_self(db, record) - }; let mut body = match return_type.passing_convention() { PassingConvention::AbiCompatible | PassingConvention::Void => { let negate_symbol = if let ImplKind::Trait { @@ -1431,7 +1435,6 @@ pub fn generate_function( db.errors().add_category(error_report::Category::Function); let ir = db.ir(); let crate_root_path = ir.crate_root_path_tokens(); - let mut features = FlagSet::empty(); let (mut param_types, mut return_type) = rs_type_kinds_for_func(db, &func)?; let errors = Errors::new(); @@ -1479,9 +1482,9 @@ pub fn generate_function( return_type_fragment: mut quoted_return_type, thunk_prepare, thunk_args, + mut features, } = errors.consolidate_on_err(function_signature( db, - &mut features, &func, &impl_kind, ¶m_idents, @@ -1519,32 +1522,34 @@ pub fn generate_function( &format!("{sep}{derived_class_prefix}{sep}{}", &func.mangled_name), ); - let func_body = if reportable_status.is_ok() { - generate_func_body( - db, - &impl_kind, - crate_root_path, - &return_type, - ¶m_value_adjustments, - thunk_ident(&func), - thunk_prepare, - thunk_args, - )? - } else { - let mut result = quote! { - #![allow(unused_variables)] - unreachable!( - "This impl can never be instantiated. \ - If this message appears at runtime, please report a crubit.rs-bug." + let create_func_body = || -> Result { + if reportable_status.is_ok() { + generate_func_body( + db, + &impl_kind, + &crate_root_path, + &return_type, + ¶m_value_adjustments, + thunk_ident(&func), + thunk_prepare, + thunk_args, ) - }; - if !return_type.is_unpin() { - result.extend(quote! { - ; #[allow(unreachable_code)] - ::ctor::UnreachableCtor::new() - }); + } else { + let mut result = quote! { + #![allow(unused_variables)] + unreachable!( + "This impl can never be instantiated. \ + If this message appears at runtime, please report a crubit.rs-bug." + ) + }; + if !return_type.is_unpin() { + result.extend(quote! { + ; #[allow(unreachable_code)] + ::ctor::UnreachableCtor::new() + }); + } + Ok(result) } - result }; // Check to see if we can get precise location information. If it's not available, emit a stub @@ -1591,8 +1596,10 @@ pub fn generate_function( let api_func: TokenStream; let function_id: FunctionId; let mut member_functions_map = HashMap::new(); + let mut free_functions_map = HashMap::new(); match impl_kind { ImplKind::None { .. } => { + let func_body = create_func_body()?; let fn_generic_params = format_generic_params(&lifetimes, std::iter::empty::()); api_func = quote! { @@ -1613,12 +1620,117 @@ pub fn generate_function( function_path: syn::parse2(quote! { #namespace_qualifier #func_name }).unwrap(), }; } - ImplKind::Struct { record, .. } => { + ImplKind::Struct { + ref record, + format_first_param_as_self, + is_renamed_unpin_constructor, + is_unsafe, + } => { let record_name = make_rs_ident( derived_record.as_deref().unwrap_or(record.as_ref()).rs_name.identifier.as_ref(), ); let fn_generic_params = format_generic_params(&lifetimes, std::iter::empty::()); + + // Generate the free function. + let free_param_idents = { + // Replace `self` with `__this`. + let mut idents = param_idents.clone(); + if format_first_param_as_self { + idents[0] = make_rs_ident("__this"); + } + idents + }; + let mut free_param_types = param_types.clone(); + let mut free_return_type = return_type.clone(); + // When generating the free function, shift `ImplKind::Struct` to `ImplKind::None`. + let free_impl_kind = ImplKind::None { is_unsafe }; + + // Ignore `errors` because `function_signature` for the member method already + // checked parameters. + let free_errors = Errors::new(); + let BindingsSignature { + lifetimes: free_lifetimes, + params: free_api_params, + return_type_fragment: free_return_type_fragment, + thunk_prepare: free_thunk_prepare, + thunk_args: free_thunk_args, + features: free_features, + } = free_errors.consolidate_on_err(function_signature( + db, + &func, + &free_impl_kind, + &free_param_idents, + &mut free_param_types, + &mut free_return_type, + None, + &free_errors, + ))?; + free_errors.discard(); + + // Update main features mapping + features |= free_features; + + let free_func_body = if reportable_status.is_ok() { + generate_func_body( + db, + &impl_kind, + &crate_root_path, + &free_return_type, + ¶m_value_adjustments, + thunk_ident(&func), + free_thunk_prepare, + free_thunk_args, + )? + } else { + // Use the `unreachable` body + create_func_body()? + }; + + let free_fn_generic_params = + format_generic_params(&free_lifetimes, std::iter::empty::()); + + // Add the free method to the mapping, which we will extract and put into + // snippets inside db later. + free_functions_map.insert( + derived_record.as_deref().unwrap_or(record.as_ref()).id, + vec![quote! { + #capture_tags + #doc_comment + #[inline(always)] + #visibility + #unsafety + fn #bracketed_func_name #free_fn_generic_params( + #( #free_api_params ),* + ) #arrow #free_return_type_fragment { + #free_func_body + } + }], + ); + + // Delegate from the method to the free function. + // When translating args, `__this` acts as the first arg. + let mut method_delegation_args = param_idents.iter().enumerate().map(|(i, ident)| { + if i == 0 && impl_kind.format_first_param_as_self() { + if derived_record.is_some() { + quote! { oops::Upcast::<_>::upcast(self) } + } else { + quote! { self } + } + } else { + quote! { #ident } + } + }); + if is_renamed_unpin_constructor { + // For constructors which have been renamed to methods, skip the `__this` parameter, + // as it isn't accepted as an argument to the underlying function. + method_delegation_args.next(); + } + + // If the record name is already snake cased, then we need to add an `_items` suffix to + // name to avoid a name collision. + let mod_name = record_name_to_associated_module_name(&record_name); + member_functions_map.insert( derived_record.as_deref().unwrap_or(record.as_ref()).id, vec![quote! { @@ -1630,7 +1742,7 @@ pub fn generate_function( fn #bracketed_func_name #fn_generic_params( #( #api_params ),* ) #arrow #quoted_return_type #unsatisfied_where_clause { - #func_body + self::#mod_name::#func_name(#( #method_delegation_args ),*) } }], ); @@ -1646,11 +1758,11 @@ pub fn generate_function( }; } ImplKind::Trait { - record: trait_record, - trait_name, + record: ref trait_record, + ref trait_name, always_public, impl_for, - associated_return_type, + ref associated_return_type, .. } => { if !always_public && visibility == Visibility::PubCrate { @@ -1689,7 +1801,7 @@ pub fn generate_function( let trait_record = if assume_lifetimes { Rc::new(lifetime_defaults_transform_record(db, &*trait_record)?) } else { - trait_record + trait_record.clone() }; let mut extra_body = if let Some(name) = associated_return_type { @@ -1832,6 +1944,7 @@ pub fn generate_function( param_types[0].to_token_stream(db), ), }; + let func_body = create_func_body()?; api_func = quote! { #unimplemented_trait_def #doc_comment @@ -1881,6 +1994,7 @@ pub fn generate_function( features, cc_details, member_functions: member_functions_map, + free_functions: free_functions_map, ..Default::default() }; @@ -1916,6 +2030,9 @@ struct BindingsSignature { /// For example, if `params` is `vec![quote!{mut self}]`, this might be /// `vec![quote!{&mut self}]` since the thunk takes non-C-ABI values by reference. thunk_args: Vec, + + /// Any features required by the function. + features: FlagSet, } /// Reformats API parameters and return values to match Rust conventions and the @@ -1932,7 +2049,6 @@ struct BindingsSignature { #[allow(clippy::too_many_arguments)] fn function_signature( db: &BindingsGenerator, - features: &mut FlagSet, func: &Func, impl_kind: &ImplKind, param_idents: &[Ident], @@ -1941,6 +2057,8 @@ fn function_signature( derived_record: Option>, errors: &Errors, ) -> Result { + let mut features = FlagSet::::empty(); + if let Some(derived_record) = derived_record.as_deref() { ensure!( db.ir() @@ -2016,7 +2134,7 @@ fn function_signature( if !type_.is_move_constructible() { errors.add(anyhow!("Non-movable, non-trivial_abi type '{}' is not supported by value as parameter #{i}", type_.display(db))); } - *features |= Feature::impl_trait_in_assoc_type; + features |= Feature::impl_trait_in_assoc_type; api_params.push(quote! {#ident: ::ctor::Ctor![#quoted_type_or_self]}); thunk_args.push( quote! {::core::pin::Pin::into_inner_unchecked(::ctor::emplace!(#ident))}, @@ -2133,7 +2251,7 @@ fn function_signature( } else { quote! {+ use<#(#lifetimes),*> } }; - *features |= Feature::impl_trait_in_assoc_type; + features |= Feature::impl_trait_in_assoc_type; if extra_lifetimes.is_empty() { quote! {::ctor::Ctor![#ty]} } else { @@ -2166,7 +2284,7 @@ fn function_signature( quote! { self } }; api_params[0] = rs_snippet.tokens; - *features |= rs_snippet.features; + features |= rs_snippet.features; } else { api_params[0] = quote! { mut self }; if derived_record.is_some() { @@ -2215,6 +2333,7 @@ fn function_signature( return_type_fragment, thunk_prepare, thunk_args, + features, }) } diff --git a/rs_bindings_from_cc/generate_bindings/generate_struct_and_union.rs b/rs_bindings_from_cc/generate_bindings/generate_struct_and_union.rs index 5891751a7..009bdfb33 100644 --- a/rs_bindings_from_cc/generate_bindings/generate_struct_and_union.rs +++ b/rs_bindings_from_cc/generate_bindings/generate_struct_and_union.rs @@ -697,6 +697,7 @@ pub fn generate_record(db: &BindingsGenerator, record: Rc) -> Result) -> Result for RawThing { } } +pub mod raw_thing { + #[allow(unused_imports)] + use super::*; + + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + /// + /// Generated from: rs_bindings_from_cc/test/annotations/owned_ptr.h;l=21 + #[inline(always)] + pub unsafe fn Close(__this: *mut crate::RawThing) { + crate::detail::__rust_thunk___ZN5Thing5CloseEv(__this) + } +} + // Generated from: nowhere/llvm/src/libcxx/include/__type_traits/integral_constant.h;l=21 // error: struct `std::integral_constant` could not be bound // template instantiation is not yet supported diff --git a/rs_bindings_from_cc/test/annotations/rust_name_rs_api.rs b/rs_bindings_from_cc/test/annotations/rust_name_rs_api.rs index c1ea4cfc2..75ed91765 100644 --- a/rs_bindings_from_cc/test/annotations/rust_name_rs_api.rs +++ b/rs_bindings_from_cc/test/annotations/rust_name_rs_api.rs @@ -73,16 +73,7 @@ pub mod crubit { b: ::ffi_11::c_int, c: ::ffi_11::c_int, ) -> Self { - let mut tmp = ::core::mem::MaybeUninit::::zeroed(); - unsafe { - crate::detail::__rust_thunk___ZN6crubit4test10SomeStructC1Eiii( - &raw mut tmp as *mut _, - a, - b, - c, - ); - tmp.assume_init() - } + self::some_struct::ConstructorNewName(a, b, c) } /// # Safety /// @@ -93,7 +84,7 @@ pub mod crubit { /// Expanded at: rs_bindings_from_cc/test/annotations/rust_name.h;l=21 #[inline(always)] pub unsafe fn MethodNewName(__this: *const Self) { - crate::detail::__rust_thunk___ZNK6crubit4test10SomeStruct13MethodOldNameEv(__this) + self::some_struct::MethodNewName(__this) } } @@ -110,6 +101,42 @@ pub mod crubit { } } } + + pub mod some_struct { + #[allow(unused_imports)] + use super::*; + + /// Generated from: support/annotations_internal.h;l=14 + /// Expanded at: rs_bindings_from_cc/test/annotations/rust_name.h;l=19 + #[inline(always)] + pub fn ConstructorNewName( + __this: ::ffi_11::c_int, + a: ::ffi_11::c_int, + b: ::ffi_11::c_int, + ) -> crate::crubit::test::SomeStruct { + let mut tmp = ::core::mem::MaybeUninit::::zeroed(); + unsafe { + crate::detail::__rust_thunk___ZN6crubit4test10SomeStructC1Eiii( + &raw mut tmp as *mut _, + __this, + a, + b, + ); + tmp.assume_init() + } + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + /// + /// Generated from: support/annotations_internal.h;l=14 + /// Expanded at: rs_bindings_from_cc/test/annotations/rust_name.h;l=21 + #[inline(always)] + pub unsafe fn MethodNewName(__this: *const crate::crubit::test::SomeStruct) { + crate::detail::__rust_thunk___ZNK6crubit4test10SomeStruct13MethodOldNameEv(__this) + } + } } } diff --git a/rs_bindings_from_cc/test/assume_lifetimes/member_function_rs_api.rs b/rs_bindings_from_cc/test/assume_lifetimes/member_function_rs_api.rs index d493d4b66..5047fe391 100644 --- a/rs_bindings_from_cc/test/assume_lifetimes/member_function_rs_api.rs +++ b/rs_bindings_from_cc/test/assume_lifetimes/member_function_rs_api.rs @@ -31,12 +31,12 @@ impl S { /// Generated from: rs_bindings_from_cc/test/assume_lifetimes/member_function.h;l=9 #[inline(always)] pub fn int_accessor<'__this>(&'__this self) -> &'__this ::ffi_11::c_int { - unsafe { crate::detail::__rust_thunk___ZNK1S12int_accessorEv(self) } + self::s::int_accessor(self) } /// Generated from: rs_bindings_from_cc/test/assume_lifetimes/member_function.h;l=10 #[inline(always)] pub fn me<'__this>(&'__this mut self) -> &'__this mut crate::S { - unsafe { crate::detail::__rust_thunk___ZN1S2meEv(self) } + self::s::me(self) } } @@ -52,6 +52,22 @@ impl Default for S { } } +pub mod s { + #[allow(unused_imports)] + use super::*; + + /// Generated from: rs_bindings_from_cc/test/assume_lifetimes/member_function.h;l=9 + #[inline(always)] + pub fn int_accessor<'__this>(__this: &'__this crate::S) -> &'__this ::ffi_11::c_int { + unsafe { crate::detail::__rust_thunk___ZNK1S12int_accessorEv(__this) } + } + /// Generated from: rs_bindings_from_cc/test/assume_lifetimes/member_function.h;l=10 + #[inline(always)] + pub fn me<'__this>(__this: &'__this mut crate::S) -> &'__this mut crate::S { + unsafe { crate::detail::__rust_thunk___ZN1S2meEv(__this) } + } +} + mod detail { #[allow(unused_imports)] use super::*; diff --git a/rs_bindings_from_cc/test/golden/callables_rs_api.rs b/rs_bindings_from_cc/test/golden/callables_rs_api.rs index 9bbeb79f9..4e9f361a2 100644 --- a/rs_bindings_from_cc/test/golden/callables_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/callables_rs_api.rs @@ -135,10 +135,28 @@ unsafe impl ::cxx::ExternType for LayoutCompatible { type Kind = ::cxx::kind::Trivial; } impl LayoutCompatible { + #[inline(always)] + pub fn Create(x: ::ffi_11::c_int) -> crate::LayoutCompatible { + self::layout_compatible::Create(x) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn get(__this: *const Self) -> ::ffi_11::c_int { + self::layout_compatible::get(__this) + } +} + +pub mod layout_compatible { + #[allow(unused_imports)] + use super::*; + #[inline(always)] pub fn Create(x: ::ffi_11::c_int) -> crate::LayoutCompatible { unsafe { - let mut __return = ::core::mem::MaybeUninit::::uninit(); + let mut __return = ::core::mem::MaybeUninit::::uninit(); crate::detail::__rust_thunk___ZN16LayoutCompatible6CreateEi( &raw mut __return as *mut ::core::ffi::c_void, x, @@ -151,7 +169,7 @@ impl LayoutCompatible { /// The caller must ensure that the following unsafe arguments are not misused by the function: /// * `__this`: raw pointer #[inline(always)] - pub unsafe fn get(__this: *const Self) -> ::ffi_11::c_int { + pub unsafe fn get(__this: *const crate::LayoutCompatible) -> ::ffi_11::c_int { crate::detail::__rust_thunk___ZNK16LayoutCompatible3getEv(__this) } } diff --git a/rs_bindings_from_cc/test/golden/callables_supported_rs_api.rs b/rs_bindings_from_cc/test/golden/callables_supported_rs_api.rs index 0dcc5e6e2..c0ac355ce 100644 --- a/rs_bindings_from_cc/test/golden/callables_supported_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/callables_supported_rs_api.rs @@ -71,10 +71,28 @@ unsafe impl ::cxx::ExternType for LayoutCompatible { type Kind = ::cxx::kind::Trivial; } impl LayoutCompatible { + #[inline(always)] + pub fn Create(x: ::ffi_11::c_int) -> crate::LayoutCompatible { + self::layout_compatible::Create(x) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn get(__this: *const Self) -> ::ffi_11::c_int { + self::layout_compatible::get(__this) + } +} + +pub mod layout_compatible { + #[allow(unused_imports)] + use super::*; + #[inline(always)] pub fn Create(x: ::ffi_11::c_int) -> crate::LayoutCompatible { unsafe { - let mut __return = ::core::mem::MaybeUninit::::uninit(); + let mut __return = ::core::mem::MaybeUninit::::uninit(); crate::detail::__rust_thunk___ZN16LayoutCompatible6CreateEi( &raw mut __return as *mut ::core::ffi::c_void, x, @@ -87,7 +105,7 @@ impl LayoutCompatible { /// The caller must ensure that the following unsafe arguments are not misused by the function: /// * `__this`: raw pointer #[inline(always)] - pub unsafe fn get(__this: *const Self) -> ::ffi_11::c_int { + pub unsafe fn get(__this: *const crate::LayoutCompatible) -> ::ffi_11::c_int { crate::detail::__rust_thunk___ZNK16LayoutCompatible3getEv(__this) } } diff --git a/rs_bindings_from_cc/test/golden/compatibility_rs_api.rs b/rs_bindings_from_cc/test/golden/compatibility_rs_api.rs index 2575ef0ed..7d73aa8d4 100644 --- a/rs_bindings_from_cc/test/golden/compatibility_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/compatibility_rs_api.rs @@ -32,14 +32,14 @@ unsafe impl ::cxx::ExternType for CompatibleType { impl CompatibleType { #[inline(always)] pub fn renamed_default_constructor<'a>(self: ::core::pin::Pin<&'a mut Self>) { - unsafe { crate::detail::__rust_thunk___ZN14CompatibleTypeC1Ev(self) } + self::compatible_type::renamed_default_constructor(self) } #[inline(always)] pub fn renamed_constructor<'a>( self: ::core::pin::Pin<&'a mut Self>, __param_0: ::ffi_11::c_int, ) { - unsafe { crate::detail::__rust_thunk___ZN14CompatibleTypeC1Ei(self, __param_0) } + self::compatible_type::renamed_constructor(self, __param_0) } } @@ -50,6 +50,25 @@ impl CompatibleType { // Unsupported return type: references are not yet supported // Unsupported parameter #1 (__param_0): references are not yet supported +pub mod compatible_type { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn renamed_default_constructor<'a>( + __this: ::core::pin::Pin<&'a mut crate::CompatibleType>, + ) { + unsafe { crate::detail::__rust_thunk___ZN14CompatibleTypeC1Ev(__this) } + } + #[inline(always)] + pub fn renamed_constructor<'a>( + __this: ::core::pin::Pin<&'a mut crate::CompatibleType>, + __param_0: ::ffi_11::c_int, + ) { + unsafe { crate::detail::__rust_thunk___ZN14CompatibleTypeC1Ei(__this, __param_0) } + } +} + mod detail { #[allow(unused_imports)] use super::*; 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 75af87bc6..571a2e272 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 @@ -34,19 +34,17 @@ impl DocCommentSlashes { /// A non-static member function (`const` flavor). #[inline(always)] pub fn get_field_value<'a>(&'a self) -> ::ffi_11::c_int { - unsafe { crate::detail::__rust_thunk___ZNK17DocCommentSlashes15get_field_valueEv(self) } + self::doc_comment_slashes::get_field_value(self) } /// A non-static member function (non-`const` flavor). #[inline(always)] pub fn set_field_value<'a>(&'a mut self, new_value: ::ffi_11::c_int) { - unsafe { - crate::detail::__rust_thunk___ZN17DocCommentSlashes15set_field_valueEi(self, new_value) - } + self::doc_comment_slashes::set_field_value(self, new_value) } /// A static method. #[inline(always)] pub fn static_method() -> ::ffi_11::c_int { - unsafe { crate::detail::__rust_thunk___ZN17DocCommentSlashes13static_methodEv() } + self::doc_comment_slashes::static_method() } } @@ -102,6 +100,34 @@ impl ::ctor::CtorNew<::ffi_11::c_int> for DocCommentSlashes { } } +pub mod doc_comment_slashes { + #[allow(unused_imports)] + use super::*; + + /// A non-static member function (`const` flavor). + #[inline(always)] + pub fn get_field_value<'a>(__this: &'a crate::DocCommentSlashes) -> ::ffi_11::c_int { + unsafe { crate::detail::__rust_thunk___ZNK17DocCommentSlashes15get_field_valueEv(__this) } + } + /// A non-static member function (non-`const` flavor). + #[inline(always)] + pub fn set_field_value<'a>( + __this: &'a mut crate::DocCommentSlashes, + new_value: ::ffi_11::c_int, + ) { + unsafe { + crate::detail::__rust_thunk___ZN17DocCommentSlashes15set_field_valueEi( + __this, new_value, + ) + } + } + /// A static method. + #[inline(always)] + pub fn static_method() -> ::ffi_11::c_int { + unsafe { crate::detail::__rust_thunk___ZN17DocCommentSlashes13static_methodEv() } + } +} + /// Doc comment /// /// * with slashes and bang diff --git a/rs_bindings_from_cc/test/golden/inheritance_rs_api.rs b/rs_bindings_from_cc/test/golden/inheritance_rs_api.rs index cb1a0edc7..ec574e43a 100644 --- a/rs_bindings_from_cc/test/golden/inheritance_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/inheritance_rs_api.rs @@ -346,7 +346,7 @@ unsafe impl ::cxx::ExternType for MethodBase1 { impl MethodBase1 { #[inline(always)] pub fn Public<'a>(&'a mut self) { - unsafe { crate::detail::__rust_thunk___ZN11MethodBase16PublicEv(self) } + self::method_base1::Public(self) } /// # Safety /// @@ -354,15 +354,15 @@ impl MethodBase1 { /// * `__param_0`: raw pointer #[inline(always)] pub unsafe fn Equals<'a>(&'a mut self, __param_0: *const Self) { - crate::detail::__rust_thunk___ZN11MethodBase16EqualsEPKS_(self, __param_0) + self::method_base1::Equals(self, __param_0) } #[inline(always)] pub fn Colliding1<'a>(&'a mut self) { - unsafe { crate::detail::__rust_thunk___ZN11MethodBase110Colliding1Ev(self) } + self::method_base1::Colliding1(self) } #[inline(always)] pub fn Colliding2<'a>(&'a mut self) { - unsafe { crate::detail::__rust_thunk___ZN11MethodBase110Colliding2Ev(self) } + self::method_base1::Colliding2(self) } } @@ -391,6 +391,35 @@ impl Default for MethodBase1 { // Unsupported return type: references are not yet supported // Unsupported parameter #1 (__param_0): references are not yet supported +pub mod method_base1 { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn Public<'a>(__this: &'a mut crate::MethodBase1) { + unsafe { crate::detail::__rust_thunk___ZN11MethodBase16PublicEv(__this) } + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__param_0`: raw pointer + #[inline(always)] + pub unsafe fn Equals<'a>( + __this: &'a mut crate::MethodBase1, + __param_0: *const crate::MethodBase1, + ) { + crate::detail::__rust_thunk___ZN11MethodBase16EqualsEPKS_(__this, __param_0) + } + #[inline(always)] + pub fn Colliding1<'a>(__this: &'a mut crate::MethodBase1) { + unsafe { crate::detail::__rust_thunk___ZN11MethodBase110Colliding1Ev(__this) } + } + #[inline(always)] + pub fn Colliding2<'a>(__this: &'a mut crate::MethodBase1) { + unsafe { crate::detail::__rust_thunk___ZN11MethodBase110Colliding2Ev(__this) } + } +} + #[derive(Clone, Copy, ::ctor::MoveAndAssignViaCopy)] #[repr(C)] ///CRUBIT_ANNOTATE: cpp_type=MethodBase2 @@ -406,11 +435,11 @@ unsafe impl ::cxx::ExternType for MethodBase2 { impl MethodBase2 { #[inline(always)] pub fn Colliding1<'a>(&'a mut self) { - unsafe { crate::detail::__rust_thunk___ZN11MethodBase210Colliding1Ev(self) } + self::method_base2::Colliding1(self) } #[inline(always)] pub fn Colliding2<'a>(&'a mut self) { - unsafe { crate::detail::__rust_thunk___ZN11MethodBase210Colliding2Ev(self) } + self::method_base2::Colliding2(self) } } @@ -439,6 +468,20 @@ impl Default for MethodBase2 { // Unsupported return type: references are not yet supported // Unsupported parameter #1 (__param_0): references are not yet supported +pub mod method_base2 { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn Colliding1<'a>(__this: &'a mut crate::MethodBase2) { + unsafe { crate::detail::__rust_thunk___ZN11MethodBase210Colliding1Ev(__this) } + } + #[inline(always)] + pub fn Colliding2<'a>(__this: &'a mut crate::MethodBase2) { + unsafe { crate::detail::__rust_thunk___ZN11MethodBase210Colliding2Ev(__this) } + } +} + #[derive(Clone, Copy, ::ctor::MoveAndAssignViaCopy)] #[repr(C)] ///CRUBIT_ANNOTATE: cpp_type=MethodDerived diff --git a/rs_bindings_from_cc/test/golden/method_access_rs_api.rs b/rs_bindings_from_cc/test/golden/method_access_rs_api.rs index 17eeab532..3f75c3cb3 100644 --- a/rs_bindings_from_cc/test/golden/method_access_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/method_access_rs_api.rs @@ -32,7 +32,7 @@ impl Struct { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn AccessNone(__this: *mut Self) { - crate::detail::__rust_thunk___ZN6Struct10AccessNoneEv(__this) + self::r#struct::AccessNone(__this) } /// # Safety /// @@ -40,7 +40,7 @@ impl Struct { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn AccessPublic(__this: *mut Self) { - crate::detail::__rust_thunk___ZN6Struct12AccessPublicEv(__this) + self::r#struct::AccessPublic(__this) } } @@ -55,6 +55,28 @@ impl Default for Struct { } } +pub mod r#struct { + #[allow(unused_imports)] + use super::*; + + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn AccessNone(__this: *mut crate::Struct) { + crate::detail::__rust_thunk___ZN6Struct10AccessNoneEv(__this) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn AccessPublic(__this: *mut crate::Struct) { + crate::detail::__rust_thunk___ZN6Struct12AccessPublicEv(__this) + } +} + #[derive(Clone, Copy, ::ctor::MoveAndAssignViaCopy)] #[repr(C)] ///CRUBIT_ANNOTATE: cpp_type=Class @@ -74,7 +96,7 @@ impl Class { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn AccessPublic(__this: *mut Self) { - crate::detail::__rust_thunk___ZN5Class12AccessPublicEv(__this) + self::class::AccessPublic(__this) } } @@ -89,6 +111,20 @@ impl Default for Class { } } +pub mod class { + #[allow(unused_imports)] + use super::*; + + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn AccessPublic(__this: *mut crate::Class) { + crate::detail::__rust_thunk___ZN5Class12AccessPublicEv(__this) + } +} + mod detail { #[allow(unused_imports)] use super::*; diff --git a/rs_bindings_from_cc/test/golden/method_qualifiers_rs_api.rs b/rs_bindings_from_cc/test/golden/method_qualifiers_rs_api.rs index bcd9c58df..1bc3932ed 100644 --- a/rs_bindings_from_cc/test/golden/method_qualifiers_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/method_qualifiers_rs_api.rs @@ -32,7 +32,7 @@ impl Noninline { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn UnqualifiedMethod(__this: *mut Self) { - crate::detail::__rust_thunk___ZN9Noninline17UnqualifiedMethodEv(__this) + self::noninline::UnqualifiedMethod(__this) } /// # Safety /// @@ -40,7 +40,7 @@ impl Noninline { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn LvalueMethod(__this: *mut Self) { - crate::detail::__rust_thunk___ZNR9Noninline12LvalueMethodEv(__this) + self::noninline::LvalueMethod(__this) } /// # Safety /// @@ -48,7 +48,7 @@ impl Noninline { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn LvalueMethodConst(__this: *const Self) { - crate::detail::__rust_thunk___ZNKR9Noninline17LvalueMethodConstEv(__this) + self::noninline::LvalueMethodConst(__this) } /// # Safety /// @@ -56,7 +56,7 @@ impl Noninline { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn RvalueMethod(__this: *mut Self) { - crate::detail::__rust_thunk___ZNO9Noninline12RvalueMethodEv(__this) + self::noninline::RvalueMethod(__this) } /// # Safety /// @@ -64,7 +64,7 @@ impl Noninline { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn RvalueMethodConst(__this: *const Self) { - crate::detail::__rust_thunk___ZNKO9Noninline17RvalueMethodConstEv(__this) + self::noninline::RvalueMethodConst(__this) } } @@ -79,6 +79,52 @@ impl Default for Noninline { } } +pub mod noninline { + #[allow(unused_imports)] + use super::*; + + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn UnqualifiedMethod(__this: *mut crate::Noninline) { + crate::detail::__rust_thunk___ZN9Noninline17UnqualifiedMethodEv(__this) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn LvalueMethod(__this: *mut crate::Noninline) { + crate::detail::__rust_thunk___ZNR9Noninline12LvalueMethodEv(__this) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn LvalueMethodConst(__this: *const crate::Noninline) { + crate::detail::__rust_thunk___ZNKR9Noninline17LvalueMethodConstEv(__this) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn RvalueMethod(__this: *mut crate::Noninline) { + crate::detail::__rust_thunk___ZNO9Noninline12RvalueMethodEv(__this) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn RvalueMethodConst(__this: *const crate::Noninline) { + crate::detail::__rust_thunk___ZNKO9Noninline17RvalueMethodConstEv(__this) + } +} + #[derive(Clone, Copy, ::ctor::MoveAndAssignViaCopy)] #[repr(C)] ///CRUBIT_ANNOTATE: cpp_type=Inline @@ -98,7 +144,7 @@ impl Inline { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn UnqualifiedMethod(__this: *mut Self) { - crate::detail::__rust_thunk___ZN6Inline17UnqualifiedMethodEv(__this) + self::inline::UnqualifiedMethod(__this) } /// # Safety /// @@ -106,7 +152,7 @@ impl Inline { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn LvalueMethod(__this: *mut Self) { - crate::detail::__rust_thunk___ZNR6Inline12LvalueMethodEv(__this) + self::inline::LvalueMethod(__this) } /// # Safety /// @@ -114,7 +160,7 @@ impl Inline { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn LvalueMethodConst(__this: *const Self) { - crate::detail::__rust_thunk___ZNKR6Inline17LvalueMethodConstEv(__this) + self::inline::LvalueMethodConst(__this) } /// # Safety /// @@ -122,7 +168,7 @@ impl Inline { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn RvalueMethod(__this: *mut Self) { - crate::detail::__rust_thunk___ZNO6Inline12RvalueMethodEv(__this) + self::inline::RvalueMethod(__this) } /// # Safety /// @@ -130,7 +176,7 @@ impl Inline { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn RvalueMethodConst(__this: *const Self) { - crate::detail::__rust_thunk___ZNKO6Inline17RvalueMethodConstEv(__this) + self::inline::RvalueMethodConst(__this) } } @@ -145,6 +191,52 @@ impl Default for Inline { } } +pub mod inline { + #[allow(unused_imports)] + use super::*; + + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn UnqualifiedMethod(__this: *mut crate::Inline) { + crate::detail::__rust_thunk___ZN6Inline17UnqualifiedMethodEv(__this) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn LvalueMethod(__this: *mut crate::Inline) { + crate::detail::__rust_thunk___ZNR6Inline12LvalueMethodEv(__this) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn LvalueMethodConst(__this: *const crate::Inline) { + crate::detail::__rust_thunk___ZNKR6Inline17LvalueMethodConstEv(__this) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn RvalueMethod(__this: *mut crate::Inline) { + crate::detail::__rust_thunk___ZNO6Inline12RvalueMethodEv(__this) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn RvalueMethodConst(__this: *const crate::Inline) { + crate::detail::__rust_thunk___ZNKO6Inline17RvalueMethodConstEv(__this) + } +} + mod detail { #[allow(unused_imports)] use super::*; 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 eeaf60a09..def7920a0 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 @@ -47,7 +47,7 @@ impl S { p1: *mut ::ffi_11::c_int, p2: *mut ::ffi_11::c_int, ) -> *mut ::ffi_11::c_int { - crate::detail::__rust_thunk___ZNK1S12const_methodERiS0_(__this, p1, p2) + self::s::const_method(__this, p1, p2) } /// # Safety /// @@ -61,7 +61,7 @@ impl S { p1: *mut ::ffi_11::c_int, p2: *mut ::ffi_11::c_int, ) -> *mut ::ffi_11::c_int { - crate::detail::__rust_thunk___ZN1S6methodERiS0_(__this, p1, p2) + self::s::method(__this, p1, p2) } } @@ -76,6 +76,40 @@ impl Default for S { } } +pub mod s { + #[allow(unused_imports)] + use super::*; + + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + /// * `p1`: raw pointer + /// * `p2`: raw pointer + #[inline(always)] + pub unsafe fn const_method( + __this: *const crate::S, + p1: *mut ::ffi_11::c_int, + p2: *mut ::ffi_11::c_int, + ) -> *mut ::ffi_11::c_int { + crate::detail::__rust_thunk___ZNK1S12const_methodERiS0_(__this, p1, p2) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + /// * `p1`: raw pointer + /// * `p2`: raw pointer + #[inline(always)] + pub unsafe fn method( + __this: *mut crate::S, + p1: *mut ::ffi_11::c_int, + p2: *mut ::ffi_11::c_int, + ) -> *mut ::ffi_11::c_int { + crate::detail::__rust_thunk___ZN1S6methodERiS0_(__this, p1, p2) + } +} + #[::ctor::recursively_pinned(PinnedDrop)] #[repr(C)] ///CRUBIT_ANNOTATE: cpp_type=TriviallyCopyableButNontriviallyDestructible 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 c0704f53b..27763c2fb 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 @@ -41,15 +41,7 @@ unsafe impl ::cxx::ExternType for Struct { impl Struct { #[inline(always)] pub fn Make(f1: ::ffi_11::c_int, f2: ::ffi_11::c_char) -> crate::Struct { - unsafe { - let mut __return = ::core::mem::MaybeUninit::::uninit(); - crate::detail::__rust_thunk___ZN6Struct4MakeEic( - &raw mut __return as *mut ::core::ffi::c_void, - f1, - f2, - ); - __return.assume_init() - } + self::r#struct::Make(f1, f2) } } @@ -78,6 +70,24 @@ impl Default for Struct { // Unsupported return type: references are not yet supported // Unsupported parameter #1 (__param_0): references are not yet supported +pub mod r#struct { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn Make(f1: ::ffi_11::c_int, f2: ::ffi_11::c_char) -> crate::Struct { + unsafe { + let mut __return = ::core::mem::MaybeUninit::::uninit(); + crate::detail::__rust_thunk___ZN6Struct4MakeEic( + &raw mut __return as *mut ::core::ffi::c_void, + f1, + f2, + ); + __return.assume_init() + } + } +} + /// Regression test for b/232418721. This tests that the offset of `field2` is /// correct (given its alignment requirements there need to be 3 bytes of padding /// between `field1` and `field2`). The verification is mostly done through @@ -105,15 +115,7 @@ unsafe impl ::cxx::ExternType for PaddingBetweenFields { impl PaddingBetweenFields { #[inline(always)] pub fn Make(f1: ::ffi_11::c_char, f2: ::ffi_11::c_int) -> crate::PaddingBetweenFields { - unsafe { - let mut __return = ::core::mem::MaybeUninit::::uninit(); - crate::detail::__rust_thunk___ZN20PaddingBetweenFields4MakeEci( - &raw mut __return as *mut ::core::ffi::c_void, - f1, - f2, - ); - __return.assume_init() - } + self::padding_between_fields::Make(f1, f2) } } @@ -142,6 +144,24 @@ impl Default for PaddingBetweenFields { // Unsupported return type: references are not yet supported // Unsupported parameter #1 (__param_0): references are not yet supported +pub mod padding_between_fields { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn Make(f1: ::ffi_11::c_char, f2: ::ffi_11::c_int) -> crate::PaddingBetweenFields { + unsafe { + let mut __return = ::core::mem::MaybeUninit::::uninit(); + crate::detail::__rust_thunk___ZN20PaddingBetweenFields4MakeEci( + &raw mut __return as *mut ::core::ffi::c_void, + f1, + f2, + ); + __return.assume_init() + } + } +} + /// Layout properties of FieldInTailPadding_InnerStruct look as follows: /// - alignment: 4 (because of `inner_int_field`) /// - dsize (size without padding): 5 diff --git a/rs_bindings_from_cc/test/golden/noexcept_rs_api.rs b/rs_bindings_from_cc/test/golden/noexcept_rs_api.rs index d7a5ec44e..74d61b597 100644 --- a/rs_bindings_from_cc/test/golden/noexcept_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/noexcept_rs_api.rs @@ -28,7 +28,7 @@ unsafe impl ::cxx::ExternType for SomeClass { impl SomeClass { #[inline(always)] pub fn create(i: ::ffi_11::c_int, c: ::ffi_11::c_char) { - unsafe { crate::detail::__rust_thunk___ZN9SomeClass6createEic(i, c) } + self::some_class::create(i, c) } /// # Safety /// @@ -36,7 +36,7 @@ impl SomeClass { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn no_except_member(__this: *mut Self) { - crate::detail::__rust_thunk___ZN9SomeClass16no_except_memberEv(__this) + self::some_class::no_except_member(__this) } /// # Safety /// @@ -44,7 +44,7 @@ impl SomeClass { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn no_except_true_member(__this: *mut Self) { - crate::detail::__rust_thunk___ZN9SomeClass21no_except_true_memberEv(__this) + self::some_class::no_except_true_member(__this) } /// # Safety /// @@ -52,7 +52,7 @@ impl SomeClass { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn no_except_false_member(__this: *mut Self) { - crate::detail::__rust_thunk___ZN9SomeClass22no_except_false_memberEv(__this) + self::some_class::no_except_false_member(__this) } } @@ -67,6 +67,40 @@ impl Default for SomeClass { } } +pub mod some_class { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn create(i: ::ffi_11::c_int, c: ::ffi_11::c_char) { + unsafe { crate::detail::__rust_thunk___ZN9SomeClass6createEic(i, c) } + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn no_except_member(__this: *mut crate::SomeClass) { + crate::detail::__rust_thunk___ZN9SomeClass16no_except_memberEv(__this) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn no_except_true_member(__this: *mut crate::SomeClass) { + crate::detail::__rust_thunk___ZN9SomeClass21no_except_true_memberEv(__this) + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn no_except_false_member(__this: *mut crate::SomeClass) { + crate::detail::__rust_thunk___ZN9SomeClass22no_except_false_memberEv(__this) + } +} + #[inline(always)] pub fn no_except() { unsafe { crate::detail::__rust_thunk___Z9no_exceptv() } 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 8f1cf7179..0a8182673 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 @@ -34,19 +34,19 @@ unsafe impl ::cxx::ExternType for Nontrivial { impl Nontrivial { #[inline(always)] pub fn Unqualified<'a>(self: ::core::pin::Pin<&'a mut Self>) { - unsafe { crate::detail::__rust_thunk___ZN10Nontrivial11UnqualifiedEv(self) } + self::nontrivial::Unqualified(self) } #[inline(always)] pub fn ConstQualified<'a>(&'a self) { - unsafe { crate::detail::__rust_thunk___ZNK10Nontrivial14ConstQualifiedEv(self) } + self::nontrivial::ConstQualified(self) } #[inline(always)] pub fn LvalueRefQualified<'a>(self: ::core::pin::Pin<&'a mut Self>) { - unsafe { crate::detail::__rust_thunk___ZNR10Nontrivial18LvalueRefQualifiedEv(self) } + self::nontrivial::LvalueRefQualified(self) } #[inline(always)] pub fn ConstLvalueRefQualified<'a>(&'a self) { - unsafe { crate::detail::__rust_thunk___ZNKR10Nontrivial23ConstLvalueRefQualifiedEv(self) } + self::nontrivial::ConstLvalueRefQualified(self) } } @@ -168,6 +168,28 @@ impl ::ctor::PinnedDrop for Nontrivial { // error: function `Nontrivial::operator+=` could not be bound // Compound assignment operators are not supported for non-Unpin types, found ::core::pin::Pin<&'a mut crate::Nontrivial> +pub mod nontrivial { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn Unqualified<'a>(__this: ::core::pin::Pin<&'a mut crate::Nontrivial>) { + unsafe { crate::detail::__rust_thunk___ZN10Nontrivial11UnqualifiedEv(__this) } + } + #[inline(always)] + pub fn ConstQualified<'a>(__this: &'a crate::Nontrivial) { + unsafe { crate::detail::__rust_thunk___ZNK10Nontrivial14ConstQualifiedEv(__this) } + } + #[inline(always)] + pub fn LvalueRefQualified<'a>(__this: ::core::pin::Pin<&'a mut crate::Nontrivial>) { + unsafe { crate::detail::__rust_thunk___ZNR10Nontrivial18LvalueRefQualifiedEv(__this) } + } + #[inline(always)] + pub fn ConstLvalueRefQualified<'a>(__this: &'a crate::Nontrivial) { + unsafe { crate::detail::__rust_thunk___ZNKR10Nontrivial23ConstLvalueRefQualifiedEv(__this) } + } +} + /// Nontrivial due to (inline) user-specified constructor and destructor. /// /// This makes it nontrivial for calls (so not trivially relocatable), as well @@ -188,7 +210,7 @@ unsafe impl ::cxx::ExternType for NontrivialInline { impl NontrivialInline { #[inline(always)] pub fn MemberFunction<'a>(self: ::core::pin::Pin<&'a mut Self>) { - unsafe { crate::detail::__rust_thunk___ZN16NontrivialInline14MemberFunctionEv(self) } + self::nontrivial_inline::MemberFunction(self) } } @@ -276,6 +298,16 @@ impl ::ctor::PinnedDrop for NontrivialInline { } } +pub mod nontrivial_inline { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn MemberFunction<'a>(__this: ::core::pin::Pin<&'a mut crate::NontrivialInline>) { + unsafe { crate::detail::__rust_thunk___ZN16NontrivialInline14MemberFunctionEv(__this) } + } +} + /// Nontrivial due to member variables. /// /// This changes how the destructor / drop impl work -- instead of calling @@ -349,7 +381,7 @@ unsafe impl ::cxx::ExternType for NontrivialUnpin { impl NontrivialUnpin { #[inline(always)] pub fn MemberFunction<'a>(&'a mut self) { - unsafe { crate::detail::__rust_thunk___ZN15NontrivialUnpin14MemberFunctionEv(self) } + self::nontrivial_unpin::MemberFunction(self) } } @@ -435,6 +467,16 @@ impl Drop for NontrivialUnpin { } } +pub mod nontrivial_unpin { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn MemberFunction<'a>(__this: &'a mut crate::NontrivialUnpin) { + unsafe { crate::detail::__rust_thunk___ZN15NontrivialUnpin14MemberFunctionEv(__this) } + } +} + #[inline(always)] pub fn TakesByValue( nontrivial: ::ctor::Ctor![crate::Nontrivial], @@ -565,7 +607,7 @@ where #![allow(unused_variables)] unreachable!( "This impl can never be instantiated. \ - If this message appears at runtime, please report a crubit.rs-bug." + If this message appears at runtime, please report a crubit.rs-bug." ) } } @@ -585,7 +627,7 @@ unsafe impl ::cxx::ExternType for Nonmovable { impl Nonmovable { #[inline(always)] pub fn MemberFunction<'a>(self: ::core::pin::Pin<&'a mut Self>) { - unsafe { crate::detail::__rust_thunk___ZN10Nonmovable14MemberFunctionEv(self) } + self::nonmovable::MemberFunction(self) } } @@ -610,6 +652,16 @@ impl ::ctor::PinnedDrop for Nonmovable { } } +pub mod nonmovable { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn MemberFunction<'a>(__this: ::core::pin::Pin<&'a mut crate::Nonmovable>) { + unsafe { crate::detail::__rust_thunk___ZN10Nonmovable14MemberFunctionEv(__this) } + } +} + #[diagnostic::on_unimplemented( message = "binding generation for function failed\nNon-movable, non-trivial_abi type 'crate::Nonmovable' is not supported by value as parameter #0" )] @@ -622,7 +674,7 @@ where #![allow(unused_variables)] unreachable!( "This impl can never be instantiated. \ - If this message appears at runtime, please report a crubit.rs-bug." + If this message appears at runtime, please report a crubit.rs-bug." ) } 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 7266c9fc7..f2c87c5c4 100644 --- a/rs_bindings_from_cc/test/golden/operators_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/operators_rs_api.rs @@ -826,7 +826,7 @@ where #![allow(unused_variables)] unreachable!( "This impl can never be instantiated. \ - If this message appears at runtime, please report a crubit.rs-bug." + If this message appears at runtime, please report a crubit.rs-bug." ) } } @@ -889,14 +889,7 @@ unsafe impl ::cxx::ExternType for ManyOperators { impl ManyOperators { #[inline(always)] pub fn unary_plus<'a>(&'a self) -> crate::ManyOperators { - unsafe { - let mut __return = ::core::mem::MaybeUninit::::uninit(); - crate::detail::__rust_thunk___ZNK13ManyOperatorspsEv( - &raw mut __return as *mut ::core::ffi::c_void, - self, - ); - __return.assume_init() - } + self::many_operators::unary_plus(self) } } @@ -1028,6 +1021,23 @@ impl<'a> ::core::ops::Not for &'a crate::ManyOperators { // Unsupported return type: references are not yet supported // Unsupported parameter #1 (rhs): references are not yet supported +pub mod many_operators { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn unary_plus<'a>(__this: &'a crate::ManyOperators) -> crate::ManyOperators { + unsafe { + let mut __return = ::core::mem::MaybeUninit::::uninit(); + crate::detail::__rust_thunk___ZNK13ManyOperatorspsEv( + &raw mut __return as *mut ::core::ffi::c_void, + __this, + ); + __return.assume_init() + } + } +} + mod detail { #[allow(unused_imports)] use super::*; diff --git a/rs_bindings_from_cc/test/golden/overloads_rs_api.rs b/rs_bindings_from_cc/test/golden/overloads_rs_api.rs index 00e0e454a..2a60f4007 100644 --- a/rs_bindings_from_cc/test/golden/overloads_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/overloads_rs_api.rs @@ -70,7 +70,7 @@ impl Foo { /// * `__this`: raw pointer #[inline(always)] pub unsafe fn Bar(__this: *mut Self, __param_0: ::ffi_11::c_int) { - crate::detail::__rust_thunk___ZN3Foo3BarEi(__this, __param_0) + self::foo::Bar(__this, __param_0) } } @@ -93,6 +93,20 @@ impl Default for Foo { // Unsupported parameter #1 (__param_0): template instantiation is not yet supported // template instantiation is not yet supported +pub mod foo { + #[allow(unused_imports)] + use super::*; + + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `__this`: raw pointer + #[inline(always)] + pub unsafe fn Bar(__this: *mut crate::Foo, __param_0: ::ffi_11::c_int) { + crate::detail::__rust_thunk___ZN3Foo3BarEi(__this, __param_0) + } +} + // error: struct `Sizeof` could not be bound // template instantiation is not yet supported // template instantiation is not yet supported diff --git a/rs_bindings_from_cc/test/golden/polymorphic_rs_api.rs b/rs_bindings_from_cc/test/golden/polymorphic_rs_api.rs index df6eb3b99..4c46ca3d2 100644 --- a/rs_bindings_from_cc/test/golden/polymorphic_rs_api.rs +++ b/rs_bindings_from_cc/test/golden/polymorphic_rs_api.rs @@ -78,7 +78,7 @@ unsafe impl ::cxx::ExternType for PolymorphicBase2 { impl PolymorphicBase2 { #[inline(always)] pub fn Foo<'a>(self: ::core::pin::Pin<&'a mut Self>) { - unsafe { crate::detail::__rust_thunk___ZN16PolymorphicBase23FooEv(self) } + self::polymorphic_base2::Foo(self) } } @@ -119,6 +119,16 @@ unsafe impl ::operator::Delete for crate::PolymorphicBase2 { } } +pub mod polymorphic_base2 { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn Foo<'a>(__this: ::core::pin::Pin<&'a mut crate::PolymorphicBase2>) { + unsafe { crate::detail::__rust_thunk___ZN16PolymorphicBase23FooEv(__this) } + } +} + #[::ctor::recursively_pinned(PinnedDrop)] #[repr(C, align(8))] ///CRUBIT_ANNOTATE: cpp_type=PolymorphicDerived 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 1c4e805b9..94a06c392 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 @@ -33,17 +33,11 @@ pub mod test_namespace_bindings { impl SomeClass { #[inline(always)] pub fn public_method<'a>(&'a mut self) { - unsafe { - crate::detail::__rust_thunk___ZN23test_namespace_bindings9SomeClass13public_methodEv( - self, - ) - } + self::some_class::public_method(self) } #[inline(always)] pub fn public_static_method() { - unsafe { - crate::detail::__rust_thunk___ZN23test_namespace_bindings9SomeClass20public_static_methodEv() - } + self::some_class::public_static_method() } } @@ -73,6 +67,26 @@ pub mod test_namespace_bindings { // error: function `test_namespace_bindings::SomeClass::operator=` could not be bound // Unsupported return type: references are not yet supported // Unsupported parameter #1 (__param_0): references are not yet supported + + pub mod some_class { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn public_method<'a>(__this: &'a mut crate::test_namespace_bindings::SomeClass) { + unsafe { + crate::detail::__rust_thunk___ZN23test_namespace_bindings9SomeClass13public_methodEv( + __this, + ) + } + } + #[inline(always)] + pub fn public_static_method() { + unsafe { + crate::detail::__rust_thunk___ZN23test_namespace_bindings9SomeClass20public_static_methodEv() + } + } + } } // namespace test_namespace_bindings 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 8064f8650..ed9602bc8 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 @@ -29,11 +29,41 @@ unsafe impl ::cxx::ExternType for SomeClass { type Kind = ::cxx::kind::Trivial; } impl SomeClass { + /// Example of a factory method. + #[inline(always)] + pub fn static_factory_method(initial_value_of_field: ::ffi_11::c_int) -> crate::SomeClass { + self::some_class::static_factory_method(initial_value_of_field) + } + /// Static method working on primitive types (and unrelated to the struct). + #[inline(always)] + pub fn static_method_that_multiplies_its_args( + x: ::ffi_11::c_int, + y: ::ffi_11::c_int, + ) -> ::ffi_11::c_int { + self::some_class::static_method_that_multiplies_its_args(x, y) + } +} + +impl Default for SomeClass { + #[inline(always)] + fn default() -> Self { + let mut tmp = ::core::mem::MaybeUninit::::zeroed(); + unsafe { + crate::detail::__rust_thunk___ZN9SomeClassC1Ev(&raw mut tmp as *mut _); + tmp.assume_init() + } + } +} + +pub mod some_class { + #[allow(unused_imports)] + use super::*; + /// Example of a factory method. #[inline(always)] pub fn static_factory_method(initial_value_of_field: ::ffi_11::c_int) -> crate::SomeClass { unsafe { - let mut __return = ::core::mem::MaybeUninit::::uninit(); + let mut __return = ::core::mem::MaybeUninit::::uninit(); crate::detail::__rust_thunk___ZN9SomeClass21static_factory_methodEi( &raw mut __return as *mut ::core::ffi::c_void, initial_value_of_field, @@ -55,17 +85,6 @@ impl SomeClass { } } -impl Default for SomeClass { - #[inline(always)] - fn default() -> Self { - let mut tmp = ::core::mem::MaybeUninit::::zeroed(); - unsafe { - crate::detail::__rust_thunk___ZN9SomeClassC1Ev(&raw mut tmp as *mut _); - tmp.assume_init() - } - } -} - mod detail { #[allow(unused_imports)] use super::*; 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 6e89e679e..f507b9fd0 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 @@ -31,21 +31,19 @@ pub mod ns { impl Trivial { #[inline(always)] pub fn Unqualified<'a>(&'a mut self) { - unsafe { crate::detail::__rust_thunk___ZN2ns7Trivial11UnqualifiedEv(self) } + self::trivial::Unqualified(self) } #[inline(always)] pub fn ConstQualified<'a>(&'a self) { - unsafe { crate::detail::__rust_thunk___ZNK2ns7Trivial14ConstQualifiedEv(self) } + self::trivial::ConstQualified(self) } #[inline(always)] pub fn LvalueRefQualified<'a>(&'a mut self) { - unsafe { crate::detail::__rust_thunk___ZNR2ns7Trivial18LvalueRefQualifiedEv(self) } + self::trivial::LvalueRefQualified(self) } #[inline(always)] pub fn ConstLvalueRefQualified<'a>(&'a self) { - unsafe { - crate::detail::__rust_thunk___ZNKR2ns7Trivial23ConstLvalueRefQualifiedEv(self) - } + self::trivial::ConstLvalueRefQualified(self) } } @@ -80,6 +78,30 @@ pub mod ns { // error: function `ns::Trivial::ConstRvalueRefQualified` could not be bound // Unsupported parameter #0 (__this): references are not yet supported + pub mod trivial { + #[allow(unused_imports)] + use super::*; + + #[inline(always)] + pub fn Unqualified<'a>(__this: &'a mut crate::ns::Trivial) { + unsafe { crate::detail::__rust_thunk___ZN2ns7Trivial11UnqualifiedEv(__this) } + } + #[inline(always)] + pub fn ConstQualified<'a>(__this: &'a crate::ns::Trivial) { + unsafe { crate::detail::__rust_thunk___ZNK2ns7Trivial14ConstQualifiedEv(__this) } + } + #[inline(always)] + pub fn LvalueRefQualified<'a>(__this: &'a mut crate::ns::Trivial) { + unsafe { crate::detail::__rust_thunk___ZNR2ns7Trivial18LvalueRefQualifiedEv(__this) } + } + #[inline(always)] + pub fn ConstLvalueRefQualified<'a>(__this: &'a crate::ns::Trivial) { + unsafe { + crate::detail::__rust_thunk___ZNKR2ns7Trivial23ConstLvalueRefQualifiedEv(__this) + } + } + } + #[inline(always)] pub fn TakesByValue(mut trivial: crate::ns::Trivial) -> crate::ns::Trivial { unsafe { diff --git a/rs_bindings_from_cc/test/references/references_rs_api.rs b/rs_bindings_from_cc/test/references/references_rs_api.rs index 0a6fd6361..54f0db9e5 100644 --- a/rs_bindings_from_cc/test/references/references_rs_api.rs +++ b/rs_bindings_from_cc/test/references/references_rs_api.rs @@ -42,7 +42,7 @@ where #![allow(unused_variables)] unreachable!( "This impl can never be instantiated. \ - If this message appears at runtime, please report a crubit.rs-bug." + If this message appears at runtime, please report a crubit.rs-bug." ) } } @@ -75,7 +75,7 @@ where #![allow(unused_variables)] unreachable!( "This impl can never be instantiated. \ - If this message appears at runtime, please report a crubit.rs-bug." + If this message appears at runtime, please report a crubit.rs-bug." ) } } diff --git a/rs_bindings_from_cc/test/struct/destructors/destructors_rs_api.rs b/rs_bindings_from_cc/test/struct/destructors/destructors_rs_api.rs index eb4001cae..de07c49ae 100644 --- a/rs_bindings_from_cc/test/struct/destructors/destructors_rs_api.rs +++ b/rs_bindings_from_cc/test/struct/destructors/destructors_rs_api.rs @@ -33,25 +33,17 @@ impl DestructionOrderRecorder { /// Generated from: rs_bindings_from_cc/test/struct/destructors/destructors.h;l=34 #[inline(always)] pub fn RecordDestruction(int_field: ::ffi_11::c_int) { - unsafe { - crate::detail::__rust_thunk___ZN24DestructionOrderRecorder17RecordDestructionEi( - int_field, - ) - } + self::destruction_order_recorder::RecordDestruction(int_field) } /// Generated from: rs_bindings_from_cc/test/struct/destructors/destructors.h;l=35 #[inline(always)] pub fn GetDestructionRecord() -> ::ffi_11::c_int { - unsafe { - crate::detail::__rust_thunk___ZN24DestructionOrderRecorder20GetDestructionRecordEv() - } + self::destruction_order_recorder::GetDestructionRecord() } /// Generated from: rs_bindings_from_cc/test/struct/destructors/destructors.h;l=36 #[inline(always)] pub fn ClearDestructionRecord() { - unsafe { - crate::detail::__rust_thunk___ZN24DestructionOrderRecorder22ClearDestructionRecordEv() - } + self::destruction_order_recorder::ClearDestructionRecord() } } @@ -121,6 +113,35 @@ impl Drop for DestructionOrderRecorder { } } +pub mod destruction_order_recorder { + #[allow(unused_imports)] + use super::*; + + /// Generated from: rs_bindings_from_cc/test/struct/destructors/destructors.h;l=34 + #[inline(always)] + pub fn RecordDestruction(int_field: ::ffi_11::c_int) { + unsafe { + crate::detail::__rust_thunk___ZN24DestructionOrderRecorder17RecordDestructionEi( + int_field, + ) + } + } + /// Generated from: rs_bindings_from_cc/test/struct/destructors/destructors.h;l=35 + #[inline(always)] + pub fn GetDestructionRecord() -> ::ffi_11::c_int { + unsafe { + crate::detail::__rust_thunk___ZN24DestructionOrderRecorder20GetDestructionRecordEv() + } + } + /// Generated from: rs_bindings_from_cc/test/struct/destructors/destructors.h;l=36 + #[inline(always)] + pub fn ClearDestructionRecord() { + unsafe { + crate::detail::__rust_thunk___ZN24DestructionOrderRecorder22ClearDestructionRecordEv() + } + } +} + /// Generated from: rs_bindings_from_cc/test/struct/destructors/destructors.h;l=42 #[repr(C, align(4))] ///CRUBIT_ANNOTATE: cpp_type=FieldDestructionOrderTester @@ -150,11 +171,7 @@ impl FieldDestructionOrderTester { field2: ::ffi_11::c_int, field3: ::ffi_11::c_int, ) { - unsafe { - crate::detail::__rust_thunk___ZN27FieldDestructionOrderTester15DestructFromCppEiii( - field1, field2, field3, - ) - } + self::field_destruction_order_tester::DestructFromCpp(field1, field2, field3) } } @@ -249,6 +266,25 @@ impl } } +pub mod field_destruction_order_tester { + #[allow(unused_imports)] + use super::*; + + /// Generated from: rs_bindings_from_cc/test/struct/destructors/destructors.h;l=51 + #[inline(always)] + pub fn DestructFromCpp( + field1: ::ffi_11::c_int, + field2: ::ffi_11::c_int, + field3: ::ffi_11::c_int, + ) { + unsafe { + crate::detail::__rust_thunk___ZN27FieldDestructionOrderTester15DestructFromCppEiii( + field1, field2, field3, + ) + } + } +} + // Generated from: nowhere/llvm/src/libcxx/include/__type_traits/integral_constant.h;l=21 // error: struct `std::integral_constant` could not be bound // template instantiation is not yet supported diff --git a/rs_bindings_from_cc/test/struct/inheritance/inherited_methods_rs_api.rs b/rs_bindings_from_cc/test/struct/inheritance/inherited_methods_rs_api.rs index 9bd9d13ba..07455e312 100644 --- a/rs_bindings_from_cc/test/struct/inheritance/inherited_methods_rs_api.rs +++ b/rs_bindings_from_cc/test/struct/inheritance/inherited_methods_rs_api.rs @@ -62,7 +62,7 @@ impl Base { /// Generated from: rs_bindings_from_cc/test/struct/inheritance/inherited_methods.h;l=17 #[inline(always)] pub fn has_bindings<'__this>(&'__this self) -> bool { - unsafe { crate::detail::__rust_thunk___ZNK4Base12has_bindingsEv(self) } + self::base::has_bindings(self) } /// Generated from: rs_bindings_from_cc/test/struct/inheritance/inherited_methods.h;l=19 #[inline(always)] @@ -70,11 +70,7 @@ impl Base { where for<'error> &'error (): BindingFailedFor_ZNK4Base11no_bindingsE10Nonmovable, { - #![allow(unused_variables)] - unreachable!( - "This impl can never be instantiated. \ - If this message appears at runtime, please report a crubit.rs-bug." - ) + self::base::no_bindings(self, __param_0) } } @@ -95,6 +91,29 @@ impl Default for Base { )] pub trait BindingFailedFor_ZNK4Base11no_bindingsE10Nonmovable {} +pub mod base { + #[allow(unused_imports)] + use super::*; + + /// Generated from: rs_bindings_from_cc/test/struct/inheritance/inherited_methods.h;l=17 + #[inline(always)] + pub fn has_bindings<'__this>(__this: &'__this crate::Base) -> bool { + unsafe { crate::detail::__rust_thunk___ZNK4Base12has_bindingsEv(__this) } + } + /// Generated from: rs_bindings_from_cc/test/struct/inheritance/inherited_methods.h;l=19 + #[inline(always)] + pub fn no_bindings<'__this>( + __this: &'__this crate::Base, + __param_0: ::ctor::Ctor![crate::Nonmovable], + ) { + #![allow(unused_variables)] + unreachable!( + "This impl can never be instantiated. \ + If this message appears at runtime, please report a crubit.rs-bug." + ) + } +} + /// Generated from: rs_bindings_from_cc/test/struct/inheritance/inherited_methods.h;l=22 #[derive(Clone, Copy, ::ctor::MoveAndAssignViaCopy)] #[repr(C)] @@ -113,9 +132,7 @@ impl Derived { /// Generated from: rs_bindings_from_cc/test/struct/inheritance/inherited_methods.h;l=17 #[inline(always)] pub fn has_bindings<'__this>(&'__this self) -> bool { - unsafe { - crate::detail::__rust_thunk___ZNK4Base12has_bindingsEv(oops::Upcast::<_>::upcast(self)) - } + self::derived::has_bindings(oops::Upcast::<_>::upcast(self)) } /// Generated from: rs_bindings_from_cc/test/struct/inheritance/inherited_methods.h;l=19 #[inline(always)] @@ -123,11 +140,7 @@ impl Derived { where for<'error> &'error (): BindingFailedFor_7Derived__ZNK4Base11no_bindingsE10Nonmovable, { - #![allow(unused_variables)] - unreachable!( - "This impl can never be instantiated. \ - If this message appears at runtime, please report a crubit.rs-bug." - ) + self::derived::no_bindings(oops::Upcast::<_>::upcast(self), __param_0) } } @@ -154,6 +167,29 @@ unsafe impl oops::Inherits for crate::Derived { } } +pub mod derived { + #[allow(unused_imports)] + use super::*; + + /// Generated from: rs_bindings_from_cc/test/struct/inheritance/inherited_methods.h;l=17 + #[inline(always)] + pub fn has_bindings<'__this>(__this: &'__this crate::Base) -> bool { + unsafe { crate::detail::__rust_thunk___ZNK4Base12has_bindingsEv(__this) } + } + /// Generated from: rs_bindings_from_cc/test/struct/inheritance/inherited_methods.h;l=19 + #[inline(always)] + pub fn no_bindings<'__this>( + __this: &'__this crate::Base, + __param_0: ::ctor::Ctor![crate::Nonmovable], + ) { + #![allow(unused_variables)] + unreachable!( + "This impl can never be instantiated. \ + If this message appears at runtime, please report a crubit.rs-bug." + ) + } +} + mod detail { #[allow(unused_imports)] use super::*; diff --git a/rs_bindings_from_cc/test/struct/methods/methods_rs_api.rs b/rs_bindings_from_cc/test/struct/methods/methods_rs_api.rs index f01c419e4..7d3dd4068 100644 --- a/rs_bindings_from_cc/test/struct/methods/methods_rs_api.rs +++ b/rs_bindings_from_cc/test/struct/methods/methods_rs_api.rs @@ -28,11 +28,50 @@ unsafe impl ::cxx::ExternType for SomeClass { type Kind = ::cxx::kind::Trivial; } impl SomeClass { + /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=10 + #[inline(always)] + pub fn static_factory_method(int_var_initial_value: ::ffi_11::c_int) -> crate::SomeClass { + self::some_class::static_factory_method(int_var_initial_value) + } + /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=11 + #[inline(always)] + pub fn static_method_that_multiplies_its_args( + x: ::ffi_11::c_int, + y: ::ffi_11::c_int, + ) -> ::ffi_11::c_int { + self::some_class::static_method_that_multiplies_its_args(x, y) + } + /// Using an `inline` method forces generation of a C++ thunk in + /// methods_rs_api_impl.cc (helping add test coverage for such thunks). + /// + /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=16 + #[inline(always)] + pub fn static_inline_method(arg: ::ffi_11::c_int) -> ::ffi_11::c_int { + self::some_class::static_inline_method(arg) + } +} + +/// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=8 +impl Default for SomeClass { + #[inline(always)] + fn default() -> Self { + let mut tmp = ::core::mem::MaybeUninit::::zeroed(); + unsafe { + crate::detail::__rust_thunk___ZN9SomeClassC1Ev(&raw mut tmp as *mut _); + tmp.assume_init() + } + } +} + +pub mod some_class { + #[allow(unused_imports)] + use super::*; + /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=10 #[inline(always)] pub fn static_factory_method(int_var_initial_value: ::ffi_11::c_int) -> crate::SomeClass { unsafe { - let mut __return = ::core::mem::MaybeUninit::::uninit(); + let mut __return = ::core::mem::MaybeUninit::::uninit(); crate::detail::__rust_thunk___ZN9SomeClass21static_factory_methodEi( &raw mut __return as *mut ::core::ffi::c_void, int_var_initial_value, @@ -62,18 +101,6 @@ impl SomeClass { } } -/// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=8 -impl Default for SomeClass { - #[inline(always)] - fn default() -> Self { - let mut tmp = ::core::mem::MaybeUninit::::zeroed(); - unsafe { - crate::detail::__rust_thunk___ZN9SomeClassC1Ev(&raw mut tmp as *mut _); - tmp.assume_init() - } - } -} - /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=25 #[derive(Clone, Copy, ::ctor::MoveAndAssignViaCopy)] #[repr(C)] @@ -91,28 +118,22 @@ impl InstanceMethods { /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=26 #[inline(always)] pub fn get_int_field(&self) -> ::ffi_11::c_int { - unsafe { crate::detail::__rust_thunk___ZNK15InstanceMethods13get_int_fieldEv(self) } + self::instance_methods::get_int_field(self) } /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=27 #[inline(always)] pub fn set_int_field(&mut self, new_value: ::ffi_11::c_int) { - unsafe { - crate::detail::__rust_thunk___ZN15InstanceMethods13set_int_fieldEi(self, new_value) - } + self::instance_methods::set_int_field(self, new_value) } /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=29 #[inline(always)] pub fn inline_get_int_field(&self) -> ::ffi_11::c_int { - unsafe { crate::detail::__rust_thunk___ZNK15InstanceMethods20inline_get_int_fieldEv(self) } + self::instance_methods::inline_get_int_field(self) } /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=30 #[inline(always)] pub fn inline_set_int_field(&mut self, new_value: ::ffi_11::c_int) { - unsafe { - crate::detail::__rust_thunk___ZN15InstanceMethods20inline_set_int_fieldEi( - self, new_value, - ) - } + self::instance_methods::inline_set_int_field(self, new_value) } /// # Safety /// @@ -125,22 +146,22 @@ impl InstanceMethods { &mut self, input_ref: *mut ::ffi_11::c_int, ) -> *mut ::ffi_11::c_int { - crate::detail::__rust_thunk___ZN15InstanceMethods21takes_and_returns_refERi(self, input_ref) + self::instance_methods::takes_and_returns_ref(self, input_ref) } /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=32 #[inline(always)] pub fn ref_qualified(&mut self) { - unsafe { crate::detail::__rust_thunk___ZNR15InstanceMethods13ref_qualifiedEv(self) } + self::instance_methods::ref_qualified(self) } /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=33 #[inline(always)] pub fn const_ref_qualified(&self) { - unsafe { crate::detail::__rust_thunk___ZNKR15InstanceMethods19const_ref_qualifiedEv(self) } + self::instance_methods::const_ref_qualified(self) } /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=34 #[inline(always)] pub fn rvalue_qualified(&mut self) { - unsafe { crate::detail::__rust_thunk___ZNO15InstanceMethods16rvalue_qualifiedEv(self) } + self::instance_methods::rvalue_qualified(self) } } @@ -156,6 +177,72 @@ impl Default for InstanceMethods { } } +pub mod instance_methods { + #[allow(unused_imports)] + use super::*; + + /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=26 + #[inline(always)] + pub fn get_int_field(__this: &crate::InstanceMethods) -> ::ffi_11::c_int { + unsafe { crate::detail::__rust_thunk___ZNK15InstanceMethods13get_int_fieldEv(__this) } + } + /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=27 + #[inline(always)] + pub fn set_int_field(__this: &mut crate::InstanceMethods, new_value: ::ffi_11::c_int) { + unsafe { + crate::detail::__rust_thunk___ZN15InstanceMethods13set_int_fieldEi(__this, new_value) + } + } + /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=29 + #[inline(always)] + pub fn inline_get_int_field(__this: &crate::InstanceMethods) -> ::ffi_11::c_int { + unsafe { + crate::detail::__rust_thunk___ZNK15InstanceMethods20inline_get_int_fieldEv(__this) + } + } + /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=30 + #[inline(always)] + pub fn inline_set_int_field(__this: &mut crate::InstanceMethods, new_value: ::ffi_11::c_int) { + unsafe { + crate::detail::__rust_thunk___ZN15InstanceMethods20inline_set_int_fieldEi( + __this, new_value, + ) + } + } + /// # Safety + /// + /// The caller must ensure that the following unsafe arguments are not misused by the function: + /// * `input_ref`: raw pointer + /// + /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=31 + #[inline(always)] + pub unsafe fn takes_and_returns_ref( + __this: &mut crate::InstanceMethods, + input_ref: *mut ::ffi_11::c_int, + ) -> *mut ::ffi_11::c_int { + crate::detail::__rust_thunk___ZN15InstanceMethods21takes_and_returns_refERi( + __this, input_ref, + ) + } + /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=32 + #[inline(always)] + pub fn ref_qualified(__this: &mut crate::InstanceMethods) { + unsafe { crate::detail::__rust_thunk___ZNR15InstanceMethods13ref_qualifiedEv(__this) } + } + /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=33 + #[inline(always)] + pub fn const_ref_qualified(__this: &crate::InstanceMethods) { + unsafe { + crate::detail::__rust_thunk___ZNKR15InstanceMethods19const_ref_qualifiedEv(__this) + } + } + /// Generated from: rs_bindings_from_cc/test/struct/methods/methods.h;l=34 + #[inline(always)] + pub fn rvalue_qualified(__this: &mut crate::InstanceMethods) { + unsafe { crate::detail::__rust_thunk___ZNO15InstanceMethods16rvalue_qualifiedEv(__this) } + } +} + mod detail { #[allow(unused_imports)] use super::*; diff --git a/rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers_rs_api.rs b/rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers_rs_api.rs index 26f6e99af..c9c48025b 100644 --- a/rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers_rs_api.rs +++ b/rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers_rs_api.rs @@ -35,57 +35,41 @@ impl UnpinStructWithRefQualifiedMethods { /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=12 #[inline(always)] pub fn increment_i<'a>(&'a mut self) { - unsafe { - crate::detail::__rust_thunk___ZN34UnpinStructWithRefQualifiedMethods11increment_iEv( - self, - ) - } + self::unpin_struct_with_ref_qualified_methods::increment_i(self) } /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=13 #[inline(always)] pub fn unqualified_get_i<'a>(&'a mut self) -> ::ffi_11::c_int { - unsafe { - crate::detail::__rust_thunk___ZN34UnpinStructWithRefQualifiedMethods17unqualified_get_iEv(self) - } + self::unpin_struct_with_ref_qualified_methods::unqualified_get_i(self) } /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=14 #[inline(always)] pub fn const_qualified_get_i<'a>(&'a self) -> ::ffi_11::c_int { - unsafe { - crate::detail::__rust_thunk___ZNK34UnpinStructWithRefQualifiedMethods21const_qualified_get_iEv(self) - } + self::unpin_struct_with_ref_qualified_methods::const_qualified_get_i(self) } /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=15 #[inline(always)] pub fn lvalue_ref_qualified_get_i<'a>(&'a mut self) -> ::ffi_11::c_int { - unsafe { - crate::detail::__rust_thunk___ZNR34UnpinStructWithRefQualifiedMethods26lvalue_ref_qualified_get_iEv(self) - } + self::unpin_struct_with_ref_qualified_methods::lvalue_ref_qualified_get_i(self) } /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=16 #[inline(always)] pub fn const_lvalue_ref_qualified_get_i<'a>(&'a self) -> ::ffi_11::c_int { - unsafe { - crate::detail::__rust_thunk___ZNKR34UnpinStructWithRefQualifiedMethods32const_lvalue_ref_qualified_get_iEv(self) - } + self::unpin_struct_with_ref_qualified_methods::const_lvalue_ref_qualified_get_i(self) } /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=17 #[inline(always)] pub fn rvalue_ref_qualified_get_i<'a>( self: ::ctor::RvalueReference<'a, Self>, ) -> ::ffi_11::c_int { - unsafe { - crate::detail::__rust_thunk___ZNO34UnpinStructWithRefQualifiedMethods26rvalue_ref_qualified_get_iEv(self) - } + self::unpin_struct_with_ref_qualified_methods::rvalue_ref_qualified_get_i(self) } /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=18 #[inline(always)] pub fn const_rvalue_ref_qualified_get_i<'a>( self: ::ctor::ConstRvalueReference<'a, Self>, ) -> ::ffi_11::c_int { - unsafe { - crate::detail::__rust_thunk___ZNKO34UnpinStructWithRefQualifiedMethods32const_rvalue_ref_qualified_get_iEv(self) - } + self::unpin_struct_with_ref_qualified_methods::const_rvalue_ref_qualified_get_i(self) } } @@ -103,6 +87,75 @@ impl Default for UnpinStructWithRefQualifiedMethods { } } +pub mod unpin_struct_with_ref_qualified_methods { + #[allow(unused_imports)] + use super::*; + + /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=12 + #[inline(always)] + pub fn increment_i<'a>(__this: &'a mut crate::UnpinStructWithRefQualifiedMethods) { + unsafe { + crate::detail::__rust_thunk___ZN34UnpinStructWithRefQualifiedMethods11increment_iEv( + __this, + ) + } + } + /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=13 + #[inline(always)] + pub fn unqualified_get_i<'a>( + __this: &'a mut crate::UnpinStructWithRefQualifiedMethods, + ) -> ::ffi_11::c_int { + unsafe { + crate::detail::__rust_thunk___ZN34UnpinStructWithRefQualifiedMethods17unqualified_get_iEv(__this) + } + } + /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=14 + #[inline(always)] + pub fn const_qualified_get_i<'a>( + __this: &'a crate::UnpinStructWithRefQualifiedMethods, + ) -> ::ffi_11::c_int { + unsafe { + crate::detail::__rust_thunk___ZNK34UnpinStructWithRefQualifiedMethods21const_qualified_get_iEv(__this) + } + } + /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=15 + #[inline(always)] + pub fn lvalue_ref_qualified_get_i<'a>( + __this: &'a mut crate::UnpinStructWithRefQualifiedMethods, + ) -> ::ffi_11::c_int { + unsafe { + crate::detail::__rust_thunk___ZNR34UnpinStructWithRefQualifiedMethods26lvalue_ref_qualified_get_iEv(__this) + } + } + /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=16 + #[inline(always)] + pub fn const_lvalue_ref_qualified_get_i<'a>( + __this: &'a crate::UnpinStructWithRefQualifiedMethods, + ) -> ::ffi_11::c_int { + unsafe { + crate::detail::__rust_thunk___ZNKR34UnpinStructWithRefQualifiedMethods32const_lvalue_ref_qualified_get_iEv(__this) + } + } + /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=17 + #[inline(always)] + pub fn rvalue_ref_qualified_get_i<'a>( + __this: ::ctor::RvalueReference<'a, crate::UnpinStructWithRefQualifiedMethods>, + ) -> ::ffi_11::c_int { + unsafe { + crate::detail::__rust_thunk___ZNO34UnpinStructWithRefQualifiedMethods26rvalue_ref_qualified_get_iEv(__this) + } + } + /// Generated from: rs_bindings_from_cc/test/struct/methods_qualifiers/methods_qualifiers.h;l=18 + #[inline(always)] + pub fn const_rvalue_ref_qualified_get_i<'a>( + __this: ::ctor::ConstRvalueReference<'a, crate::UnpinStructWithRefQualifiedMethods>, + ) -> ::ffi_11::c_int { + unsafe { + crate::detail::__rust_thunk___ZNKO34UnpinStructWithRefQualifiedMethods32const_rvalue_ref_qualified_get_iEv(__this) + } + } +} + mod detail { #[allow(unused_imports)] use super::*; diff --git a/rs_bindings_from_cc/test/templates/type_alias/type_alias_rs_api.rs b/rs_bindings_from_cc/test/templates/type_alias/type_alias_rs_api.rs index cd35747cc..38da4ddf6 100644 --- a/rs_bindings_from_cc/test/templates/type_alias/type_alias_rs_api.rs +++ b/rs_bindings_from_cc/test/templates/type_alias/type_alias_rs_api.rs @@ -44,18 +44,12 @@ impl __CcTemplateInst10MyTemplateIiE { /// Generated from: rs_bindings_from_cc/test/templates/type_alias/type_alias.h;l=13 #[inline(always)] pub fn Create(value: ::ffi_11::c_int) -> crate::__CcTemplateInst10MyTemplateIiE { - unsafe { - let mut __return = ::core::mem::MaybeUninit::::uninit(); - crate::detail::__rust_thunk___ZN10MyTemplateIiE6CreateEi__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias(&raw mut __return as*mut::core::ffi::c_void,value); - __return.assume_init() - } + self::cc_template_inst10_my_template_ii_e::Create(value) } /// Generated from: rs_bindings_from_cc/test/templates/type_alias/type_alias.h;l=19 #[inline(always)] pub fn value<'__this>(&'__this self) -> &'__this ::ffi_11::c_int { - unsafe { - crate::detail::__rust_thunk___ZNK10MyTemplateIiE5valueEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias(self) - } + self::cc_template_inst10_my_template_ii_e::value(self) } } @@ -71,6 +65,31 @@ impl Default for __CcTemplateInst10MyTemplateIiE { } } +pub mod cc_template_inst10_my_template_ii_e { + #[allow(unused_imports)] + use super::*; + + /// Generated from: rs_bindings_from_cc/test/templates/type_alias/type_alias.h;l=13 + #[inline(always)] + pub fn Create(value: ::ffi_11::c_int) -> crate::__CcTemplateInst10MyTemplateIiE { + unsafe { + let mut __return = + ::core::mem::MaybeUninit::::uninit(); + crate::detail::__rust_thunk___ZN10MyTemplateIiE6CreateEi__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias(&raw mut __return as*mut::core::ffi::c_void,value); + __return.assume_init() + } + } + /// Generated from: rs_bindings_from_cc/test/templates/type_alias/type_alias.h;l=19 + #[inline(always)] + pub fn value<'__this>( + __this: &'__this crate::__CcTemplateInst10MyTemplateIiE, + ) -> &'__this ::ffi_11::c_int { + unsafe { + crate::detail::__rust_thunk___ZNK10MyTemplateIiE5valueEv__2f_2fthird_5fparty_2fcrubit_2frs_5fbindings_5ffrom_5fcc_2ftest_2ftemplates_2ftype_5falias_3atype_5falias(__this) + } + } +} + mod detail { #[allow(unused_imports)] use super::*;