Skip to content

No opinion on the semicolon after items defined within functions? #4222

Closed
@iago-lito

Description

@iago-lito

I have noticed that rustfmt leaves those 2 equivalent functions unchanged, although they are differently formatted:

fn first_function() -> ReturnType {
    struct inner_item {
        field: u32,
    }; // <- With a semicolon.
    last_expression
}

fn second_function() -> ReturnType {
    struct inner_item {
        field: u32,
    } // <- Without a semicolon.
    last_expression
}

Is this something that rustfmt should have an opinion about?

I would like the answer to be yes, because I would not have to choose myself whether to write this semicolon or not.

But I would understand that the answer be no, because ; is an additional (empty) statement that does not appear in the second_function, so the two functions are somewhat different. However, if this is how rustfmt stands, then it should maybe reformat the first snippet to

fn first_function() -> ReturnType {
    struct inner_item {
        field: u32,
    }
    ; // <- Make it clear that this is additional, empty statement.
    last_expression
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions