Skip to content

Commit 9dbcc76

Browse files
michaelwunox
authored andcommitted
Generate better func decls for void returns
1 parent 6e33fbe commit 9dbcc76

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/gen.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -889,14 +889,10 @@ fn cfuncty_to_rs(ctx: &mut GenCtx,
889889
aty: &[(String, Type)],
890890
var: bool) -> ast::FnDecl {
891891

892-
let ret = P(match *rty {
893-
TVoid => ast::Ty {
894-
id: ast::DUMMY_NODE_ID,
895-
node: ast::TyTup(vec![]),
896-
span: ctx.span
897-
},
898-
_ => cty_to_rs(ctx, rty)
899-
});
892+
let ret = match *rty {
893+
TVoid => ast::DefaultReturn(ctx.span),
894+
_ => ast::Return(P(cty_to_rs(ctx, rty)))
895+
};
900896

901897
let mut unnamed: usize = 0;
902898
let args: Vec<ast::Arg> = aty.iter().map(|arg| {
@@ -937,7 +933,7 @@ fn cfuncty_to_rs(ctx: &mut GenCtx,
937933
let var = !args.is_empty() && var;
938934
return ast::FnDecl {
939935
inputs: args,
940-
output: ast::Return(ret),
936+
output: ret,
941937
variadic: var
942938
};
943939
}

tests/test_func.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn func_proto() {
4343
fn with_func_ptr_arg() {
4444
assert_bind_eq("headers/func_with_func_ptr_arg.h", "
4545
extern \"C\" {
46-
pub fn foo(bar: ::std::option::Option<extern \"C\" fn() -> () >) -> ();
46+
pub fn foo(bar: ::std::option::Option<extern \"C\" fn()>);
4747
}
4848
");
4949
}
@@ -52,7 +52,7 @@ fn with_func_ptr_arg() {
5252
fn with_array_arg() {
5353
assert_bind_eq("headers/func_with_array_arg.h", "
5454
extern \"C\" {
55-
pub fn f(x: *mut ::libc::c_int) -> ();
55+
pub fn f(x: *mut ::libc::c_int);
5656
}
5757
");
5858
}

0 commit comments

Comments
 (0)