Skip to content

Format the last statement as an expression #3624

Closed
@topecongiro

Description

@topecongiro

Replace ExprType::Statement with ExprType::SubExpression if the statement is the last statement within its enclosing block.

format_expr(ex, ExprType::Statement, context, shape).map(|s| s + suffix)

One way to implement this is to add a wrapper type over ast::Stmt which holds the information about whether it's the last statement or not:

struct Statement<'ast> {
    stmt: &'ast ast::Stmt,
    is_last: bool,
}

cc #3614.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssues up for grabs, also good candidates for new rustfmt contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions