@@ -9,10 +9,9 @@ use syntax::map::UnorderedMap as Map;
9
9
use syntax:: set:: UnorderedSet ;
10
10
use syntax:: symbol:: { self , Symbol } ;
11
11
use syntax:: trivial:: { self , TrivialReason } ;
12
- use syntax:: Lang ;
13
12
use syntax:: {
14
- derive, mangle, Api , Doc , Enum , EnumRepr , ExternFn , ExternType , Pair , Signature , Struct , Trait ,
15
- Type , TypeAlias , Types , Var ,
13
+ derive, mangle, Api , Doc , Enum , EnumRepr , ExternFn , ExternType , Lang , Pair , Signature , Struct ,
14
+ Trait , Type , TypeAlias , Types , Var ,
16
15
} ;
17
16
18
17
pub fn gen ( apis : & [ Api ] , types : & Types , opt : & Opt , header : bool ) -> Vec < u8 > {
@@ -36,6 +35,7 @@ pub fn gen(apis: &[Api], types: &Types, opt: &Opt, header: bool) -> Vec<u8> {
36
35
fn write_forward_declarations ( out : & mut OutFile , apis : & [ Api ] ) {
37
36
let needs_forward_declaration = |api : & & Api | match api {
38
37
Api :: Struct ( _) | Api :: CxxType ( _) | Api :: RustType ( _) => true ,
38
+ Api :: TypeAlias ( ety) => ety. lang == Lang :: Rust ,
39
39
Api :: Enum ( enm) => !out. types . cxx . contains ( & enm. name . rust ) ,
40
40
_ => false ,
41
41
} ;
@@ -55,6 +55,7 @@ fn write_forward_declarations(out: &mut OutFile, apis: &[Api]) {
55
55
Api :: Enum ( enm) => write_enum_decl ( out, enm) ,
56
56
Api :: CxxType ( ety) => write_struct_using ( out, & ety. name ) ,
57
57
Api :: RustType ( ety) => write_struct_decl ( out, & ety. name ) ,
58
+ Api :: TypeAlias ( ety) => write_struct_decl ( out, & ety. name ) ,
58
59
_ => unreachable ! ( ) ,
59
60
}
60
61
}
@@ -129,8 +130,17 @@ fn write_data_structures<'a>(out: &mut OutFile<'a>, apis: &'a [Api]) {
129
130
out. next_section ( ) ;
130
131
for api in apis {
131
132
if let Api :: TypeAlias ( ety) = api {
132
- if let Some ( reasons) = out. types . required_trivial . get ( & ety. name . rust ) {
133
- check_trivial_extern_type ( out, ety, reasons) ;
133
+ match ety. lang {
134
+ Lang :: Cxx => {
135
+ if let Some ( reasons) = out. types . required_trivial . get ( & ety. name . rust ) {
136
+ check_trivial_extern_type ( out, ety, reasons) ;
137
+ }
138
+ }
139
+ Lang :: Rust => {
140
+ // nothing to write here, the alias is only used to generate
141
+ // forward declaration in C++ (so C++ shims for Rust functions
142
+ // using the type compile correctly).
143
+ }
134
144
}
135
145
}
136
146
}
@@ -1030,11 +1040,15 @@ fn write_rust_function_shim_impl(
1030
1040
return ;
1031
1041
}
1032
1042
writeln ! ( out, " {{" ) ;
1033
- sig. args . iter ( )
1034
- . filter ( |arg| {
1035
- matches ! ( arg. ty, Type :: Own ( _) )
1036
- } ) . for_each ( |arg_own| {
1037
- writeln ! ( out, " KJ_ASSERT({}.get() != nullptr, \" Cannot pass a null Own to Rust\" );" , arg_own. name. cxx) ;
1043
+ sig. args
1044
+ . iter ( )
1045
+ . filter ( |arg| matches ! ( arg. ty, Type :: Own ( _) ) )
1046
+ . for_each ( |arg_own| {
1047
+ writeln ! (
1048
+ out,
1049
+ " KJ_ASSERT({}.get() != nullptr, \" Cannot pass a null Own to Rust\" );" ,
1050
+ arg_own. name. cxx
1051
+ ) ;
1038
1052
} ) ;
1039
1053
for arg in & sig. args {
1040
1054
if arg. ty != RustString && out. types . needs_indirect_abi ( & arg. ty ) {
@@ -1634,7 +1648,7 @@ fn write_kj_own(out: &mut OutFile, key: NamedImplKey) {
1634
1648
let resolve = out. types . resolve ( ident) ;
1635
1649
let inner = resolve. name . to_fully_qualified ( ) ;
1636
1650
let instance = resolve. name . to_symbol ( ) ;
1637
-
1651
+
1638
1652
out. include . utility = true ;
1639
1653
out. include . kj_rs = true ;
1640
1654
0 commit comments