@@ -4135,11 +4135,7 @@ impl CodeGenerator for Function {
4135
4135
if is_dynamic_function {
4136
4136
let args_identifiers =
4137
4137
utils:: fnsig_argument_identifiers ( ctx, signature) ;
4138
- let return_item = ctx. resolve_item ( signature. return_type ( ) ) ;
4139
- let ret_ty = match * return_item. kind ( ) . expect_type ( ) . kind ( ) {
4140
- TypeKind :: Void => quote ! { ( ) } ,
4141
- _ => return_item. to_rust_ty_or_opaque ( ctx, & ( ) ) ,
4142
- } ;
4138
+ let ret_ty = utils:: fnsig_return_ty ( ctx, signature) ;
4143
4139
result. dynamic_items ( ) . push (
4144
4140
ident,
4145
4141
abi,
@@ -4811,25 +4807,53 @@ pub mod utils {
4811
4807
} )
4812
4808
}
4813
4809
4814
- pub fn fnsig_return_ty (
4810
+ fn fnsig_return_ty_internal (
4815
4811
ctx : & BindgenContext ,
4816
4812
sig : & FunctionSig ,
4813
+ include_arrow : bool ,
4817
4814
) -> proc_macro2:: TokenStream {
4818
4815
if sig. is_divergent ( ) {
4819
- return quote ! { -> ! } ;
4816
+ return if include_arrow {
4817
+ quote ! { -> ! }
4818
+ } else {
4819
+ quote ! { ! }
4820
+ } ;
4820
4821
}
4821
4822
4822
- let return_item = ctx. resolve_item ( sig. return_type ( ) ) ;
4823
- if let TypeKind :: Void = * return_item. kind ( ) . expect_type ( ) . kind ( ) {
4824
- quote ! { }
4823
+ let canonical_type_kind = sig
4824
+ . return_type ( )
4825
+ . into_resolver ( )
4826
+ . through_type_refs ( )
4827
+ . through_type_aliases ( )
4828
+ . resolve ( ctx)
4829
+ . kind ( )
4830
+ . expect_type ( )
4831
+ . kind ( ) ;
4832
+
4833
+ if let TypeKind :: Void = canonical_type_kind {
4834
+ return if include_arrow {
4835
+ quote ! { }
4836
+ } else {
4837
+ quote ! { ( ) }
4838
+ } ;
4839
+ }
4840
+
4841
+ let ret_ty = sig. return_type ( ) . to_rust_ty_or_opaque ( ctx, & ( ) ) ;
4842
+ if include_arrow {
4843
+ quote ! { -> #ret_ty }
4825
4844
} else {
4826
- let ret_ty = return_item. to_rust_ty_or_opaque ( ctx, & ( ) ) ;
4827
- quote ! {
4828
- -> #ret_ty
4829
- }
4845
+ ret_ty
4830
4846
}
4831
4847
}
4832
4848
4849
+
4850
+ pub fn fnsig_return_ty (
4851
+ ctx : & BindgenContext ,
4852
+ sig : & FunctionSig ,
4853
+ ) -> proc_macro2:: TokenStream {
4854
+ fnsig_return_ty_internal ( ctx, sig, /* include_arrow = */ true )
4855
+ }
4856
+
4833
4857
pub fn fnsig_arguments (
4834
4858
ctx : & BindgenContext ,
4835
4859
sig : & FunctionSig ,
@@ -4942,14 +4966,7 @@ pub mod utils {
4942
4966
arg_item. to_rust_ty_or_opaque ( ctx, & ( ) )
4943
4967
} ) ;
4944
4968
4945
- let return_item = ctx. resolve_item ( sig. return_type ( ) ) ;
4946
- let ret_ty =
4947
- if let TypeKind :: Void = * return_item. kind ( ) . expect_type ( ) . kind ( ) {
4948
- quote ! { ( ) }
4949
- } else {
4950
- return_item. to_rust_ty_or_opaque ( ctx, & ( ) )
4951
- } ;
4952
-
4969
+ let ret_ty = fnsig_return_ty_internal ( ctx, sig, /* include_arrow = */ false ) ;
4953
4970
quote ! {
4954
4971
* const :: block:: Block <( #( #args, ) * ) , #ret_ty>
4955
4972
}
0 commit comments