Skip to content

Commit 3d2f57c

Browse files
committed
Merge pull request rust-lang#249 from nox/void-return
Generate better func decls for void returns
2 parents d1c7352 + 9dbcc76 commit 3d2f57c

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
@@ -955,14 +955,10 @@ fn cfuncty_to_rs(ctx: &mut GenCtx,
955955
aty: &[(String, Type)],
956956
var: bool) -> ast::FnDecl {
957957

958-
let ret = P(match *rty {
959-
TVoid => ast::Ty {
960-
id: ast::DUMMY_NODE_ID,
961-
node: ast::TyTup(vec![]),
962-
span: ctx.span
963-
},
964-
_ => cty_to_rs(ctx, rty)
965-
});
958+
let ret = match *rty {
959+
TVoid => ast::DefaultReturn(ctx.span),
960+
_ => ast::Return(P(cty_to_rs(ctx, rty)))
961+
};
966962

967963
let mut unnamed: usize = 0;
968964
let args: Vec<ast::Arg> = aty.iter().map(|arg| {
@@ -1003,7 +999,7 @@ fn cfuncty_to_rs(ctx: &mut GenCtx,
1003999
let var = !args.is_empty() && var;
10041000
return ast::FnDecl {
10051001
inputs: args,
1006-
output: ast::Return(ret),
1002+
output: ret,
10071003
variadic: var
10081004
};
10091005
}

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)