File tree 8 files changed +79
-0
lines changed
8 files changed +79
-0
lines changed Original file line number Diff line number Diff line change @@ -93,6 +93,7 @@ fn check_type_box(cx: &mut Check, ptr: &Ty1) {
93
93
fn check_type_rust_vec ( cx : & mut Check , ty : & Ty1 ) {
94
94
if let Type :: Ident ( ident) = & ty. inner {
95
95
if cx. types . cxx . contains ( & ident. rust )
96
+ && !cx. types . aliases . contains_key ( & ident. rust )
96
97
&& !cx. types . structs . contains_key ( & ident. rust )
97
98
&& !cx. types . enums . contains_key ( & ident. rust )
98
99
{
@@ -328,6 +329,7 @@ fn check_api_type(cx: &mut Check, ety: &ExternType) {
328
329
TrivialReason :: StructField ( strct) => format ! ( "a field of `{}`" , strct. name. rust) ,
329
330
TrivialReason :: FunctionArgument ( efn) => format ! ( "an argument of `{}`" , efn. name. rust) ,
330
331
TrivialReason :: FunctionReturn ( efn) => format ! ( "a return value of `{}`" , efn. name. rust) ,
332
+ TrivialReason :: VecElement => format ! ( "a vector element in Vec<{}>" , ety. name. rust) ,
331
333
} ;
332
334
let msg = format ! (
333
335
"needs a cxx::ExternType impl in order to be used as {}" ,
Original file line number Diff line number Diff line change @@ -201,6 +201,12 @@ impl<'a> Types<'a> {
201
201
_ => { }
202
202
}
203
203
}
204
+ for ty in & all {
205
+ if let Type :: RustVec ( ty) = ty {
206
+ let reason = TrivialReason :: VecElement ;
207
+ insist_alias_types_are_trivial ( & ty. inner , reason) ;
208
+ }
209
+ }
204
210
205
211
let mut types = Types {
206
212
all,
@@ -297,6 +303,7 @@ pub enum TrivialReason<'a> {
297
303
StructField ( & ' a Struct ) ,
298
304
FunctionArgument ( & ' a ExternFn ) ,
299
305
FunctionReturn ( & ' a ExternFn ) ,
306
+ VecElement ,
300
307
}
301
308
302
309
fn duplicate_name ( cx : & mut Errors , sp : impl ToTokens , ident : & Ident ) {
Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ cxx_library(
32
32
],
33
33
headers = {
34
34
"ffi/lib.rs.h" : ":bridge/header" ,
35
+ "ffi/module.rs.h" : ":module/header" ,
35
36
"ffi/tests.h" : "ffi/tests.h" ,
36
37
},
37
38
deps = ["//:core" ],
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ cc_library(
35
35
hdrs = ["ffi/tests.h" ],
36
36
deps = [
37
37
":bridge/include" ,
38
+ ":module/include" ,
38
39
"//:core" ,
39
40
],
40
41
)
Original file line number Diff line number Diff line change @@ -184,7 +184,10 @@ pub mod ffi {
184
184
}
185
185
186
186
extern "C++" {
187
+ include ! ( "tests/ffi/module.rs.h" ) ;
188
+
187
189
type COwnedEnum ;
190
+ type Job = crate :: module:: ffi:: Job ;
188
191
}
189
192
190
193
#[ repr( u32 ) ]
@@ -211,6 +214,7 @@ pub mod ffi {
211
214
fn r_return_unique_ptr_string ( ) -> UniquePtr < CxxString > ;
212
215
fn r_return_rust_vec ( ) -> Vec < u8 > ;
213
216
fn r_return_rust_vec_string ( ) -> Vec < String > ;
217
+ fn r_return_rust_vec_extern_struct ( ) -> Vec < Job > ;
214
218
fn r_return_ref_rust_vec ( shared : & Shared ) -> & Vec < u8 > ;
215
219
fn r_return_mut_rust_vec ( shared : & mut Shared ) -> & mut Vec < u8 > ;
216
220
fn r_return_identity ( _: usize ) -> usize ;
@@ -435,6 +439,10 @@ fn r_return_rust_vec_string() -> Vec<String> {
435
439
Vec :: new ( )
436
440
}
437
441
442
+ fn r_return_rust_vec_extern_struct ( ) -> Vec < ffi:: Job > {
443
+ Vec :: new ( )
444
+ }
445
+
438
446
fn r_return_ref_rust_vec ( shared : & ffi:: Shared ) -> & Vec < u8 > {
439
447
let _ = shared;
440
448
unimplemented ! ( )
Original file line number Diff line number Diff line change 1
1
#[ cxx:: bridge( namespace = "tests" ) ]
2
2
pub mod ffi {
3
+ struct Job {
4
+ raw : u32 ,
5
+ }
6
+
3
7
unsafe extern "C++" {
4
8
include ! ( "tests/ffi/tests.h" ) ;
5
9
Original file line number Diff line number Diff line change
1
+ #[ cxx:: bridge]
2
+ mod handle {
3
+ extern "C++" {
4
+ type Job ;
5
+ }
6
+ }
7
+
8
+ #[ cxx:: bridge]
9
+ mod ffi1 {
10
+ extern "C++" {
11
+ type Job ;
12
+ }
13
+
14
+ extern "Rust" {
15
+ fn f ( ) -> Vec < Job > ;
16
+ }
17
+ }
18
+
19
+ #[ cxx:: bridge]
20
+ mod ffi2 {
21
+ extern "C++" {
22
+ type Job = crate :: handle:: Job ;
23
+ }
24
+
25
+ extern "Rust" {
26
+ fn f ( ) -> Vec < Job > ;
27
+ }
28
+ }
29
+
30
+ fn f ( ) -> Vec < handle:: Job > {
31
+ unimplemented ! ( )
32
+ }
33
+
34
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: Rust Vec containing C++ type is not supported yet
2
+ --> $DIR/vec_opaque.rs:15:19
3
+ |
4
+ 15 | fn f() -> Vec<Job>;
5
+ | ^^^^^^^^
6
+
7
+ error: needs a cxx::ExternType impl in order to be used as a vector element in Vec<Job>
8
+ --> $DIR/vec_opaque.rs:11:9
9
+ |
10
+ 11 | type Job;
11
+ | ^^^^^^^^
12
+
13
+ error[E0271]: type mismatch resolving `<handle::Job as ExternType>::Kind == Trivial`
14
+ --> $DIR/vec_opaque.rs:22:9
15
+ |
16
+ 22 | type Job = crate::handle::Job;
17
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Trivial`, found enum `cxx::kind::Opaque`
18
+ |
19
+ ::: $WORKSPACE/src/extern_type.rs
20
+ |
21
+ | pub fn verify_extern_kind<T: ExternType<Kind = Kind>, Kind: self::Kind>() {}
22
+ | ----------- required by this bound in `verify_extern_kind`
You can’t perform that action at this time.
0 commit comments