@@ -34,25 +34,26 @@ fn test_impl_annotation() {
34
34
const BRIDGE1 : & str = r#"
35
35
#[cxx::bridge]
36
36
mod ffi {
37
- unsafe extern "C++" {
37
+ extern "C++" {
38
38
type CppType;
39
39
}
40
40
41
41
extern "Rust" {
42
- fn rust_method_cpp_context (self: Pin<&mut CppType>);
42
+ fn rust_method_cpp_receiver (self: Pin<&mut CppType>);
43
43
}
44
44
}
45
45
"# ;
46
46
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.
49
50
//
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 .
52
53
//
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.
56
57
#[ test]
57
58
fn test_extern_rust_method_on_c_type ( ) {
58
59
let opt = Opt :: default ( ) ;
@@ -61,17 +62,14 @@ fn test_extern_rust_method_on_c_type() {
61
62
let header = str:: from_utf8 ( & generated. header ) . unwrap ( ) ;
62
63
let implementation = str:: from_utf8 ( & generated. implementation ) . unwrap ( ) ;
63
64
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" ) ) ;
69
67
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.
71
69
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;" ) ) ;
73
71
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);" ) ) ;
77
75
}
0 commit comments