@@ -34,25 +34,26 @@ fn test_impl_annotation() {
3434const BRIDGE1 : & str = r#"
3535 #[cxx::bridge]
3636 mod ffi {
37- unsafe extern "C++" {
37+ extern "C++" {
3838 type CppType;
3939 }
4040
4141 extern "Rust" {
42- fn rust_method_cpp_context (self: Pin<&mut CppType>);
42+ fn rust_method_cpp_receiver (self: Pin<&mut CppType>);
4343 }
4444 }
4545"# ;
4646
47- // Ensure that implementing a Rust method on a C++ type only causes generation
48- // of the implementation.
47+ // Ensure that implementing a Rust method on an opaque C++ type only causes
48+ // generation of the member function definition, not a member function
49+ // declaration in a class definition.
4950//
50- // The header should be implemented in the C++ class definition and the Rust
51- // implementation in the usual way .
51+ // The member function declaration will come from whichever header provides the
52+ // C++ class definition .
5253//
53- // This allows for developers and crates that are generating both C++ and Rust
54- // code to have a C++ method implemented in Rust without having to use a
55- // free method and passing through the C++ "this" as an argument.
54+ // This allows for developers and crates that are producing both C++ and Rust
55+ // code to have a C++ method implemented in Rust without having to use a free
56+ // function and passing through the C++ "this" as an argument.
5657#[ test]
5758fn test_extern_rust_method_on_c_type ( ) {
5859 let opt = Opt :: default ( ) ;
@@ -61,17 +62,14 @@ fn test_extern_rust_method_on_c_type() {
6162 let header = str:: from_utf8 ( & generated. header ) . unwrap ( ) ;
6263 let implementation = str:: from_utf8 ( & generated. implementation ) . unwrap ( ) ;
6364
64- // To avoid continual breakage we won't test every byte.
65- // Let's look for the major features.
66-
67- // Check that the header doesn't have the Rust method
68- assert ! ( !header. contains( "rust_method_cpp_context" ) ) ;
65+ // Check that the header doesn't have the Rust method.
66+ assert ! ( !header. contains( "rust_method_cpp_receiver" ) ) ;
6967
70- // Check that there is a cxxbridge to the Rust method
68+ // Check that there is a generated C signature bridging to the Rust method.
7169 assert ! ( implementation
72- . contains( "void cxxbridge1$CppType$rust_method_cpp_context (::CppType &self) noexcept;" ) ) ;
70+ . contains( "void cxxbridge1$CppType$rust_method_cpp_receiver (::CppType &self) noexcept;" ) ) ;
7371
74- // Check that there is a implementation on the C++ class calling the Rust method
75- assert ! ( implementation. contains( "void CppType::rust_method_cpp_context () noexcept {" ) ) ;
76- assert ! ( implementation. contains( "cxxbridge1$CppType$rust_method_cpp_context (*this);" ) ) ;
72+ // Check that there is an implementation on the C++ class calling the Rust method.
73+ assert ! ( implementation. contains( "void CppType::rust_method_cpp_receiver () noexcept {" ) ) ;
74+ assert ! ( implementation. contains( "cxxbridge1$CppType$rust_method_cpp_receiver (*this);" ) ) ;
7775}
0 commit comments