Skip to content

transpile: return is emitted in final statement #1496

@Rua

Description

@Rua
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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions