c2rust
c2rust copied to clipboard
`bool` `return` is silently lost in translation
I played with the demo site: https://c2rust.com/
It looks like any time I return a bool without including stdbool.h, the return statement is missing from the Rust translation.
When I include stdbool.h, the output looks reasonable. Shouldn't this be an error rather than a silent failure?
C:
bool foo() {
return true;
}
Rust:
#![allow(dead_code, mutable_transmutes, non_camel_case_types, non_snake_case,
non_upper_case_globals, unused_assignments, unused_mut)]
#![register_tool(c2rust)]
#![feature(register_tool)]
#[no_mangle]
pub unsafe extern "C" fn foo() -> libc::c_int {
panic!("Reached end of non-void function without returning");
}
C:
#include <stdbool.h>
bool foo() {
return true;
}
Rust:
#![allow(dead_code, mutable_transmutes, non_camel_case_types, non_snake_case,
non_upper_case_globals, unused_assignments, unused_mut)]
#![register_tool(c2rust)]
#![feature(register_tool)]
#[no_mangle]
pub unsafe extern "C" fn foo() -> bool { return 1 as libc::c_int != 0; }
I've confirmed this behavior. A few notes:
- This C code (without
stdbool.h) does not compile unmodified with GCC or Clang--the header really is needed for correctness. - Replacing
truewithasdfresults in the same output from c2rust.
We should indeed emit a translation-time error here.