c2rust icon indicating copy to clipboard operation
c2rust copied to clipboard

transpile: `return` is emitted in final statement

Open Rua opened this issue 3 weeks ago • 0 comments

int foo() {
    return 6 * 7;
}

generates

pub unsafe extern "C" fn foo() -> ::core::ffi::c_int {
    return 6 as ::core::ffi::c_int * 7 as ::core::ffi::c_int;
}

While semantically fine, this code is unidiomatic because it uses return in the final statement. It would be cleaner to use a tail expression instead.

I don't know if any attempts have been made before to implement it. A few CFG related things have an in_tail parameter, so it looks like someone tried before and got part of the way there?

Rua avatar Dec 06 '25 16:12 Rua