Skip to content

Option to preserve match alignment #894

Open
@azerupi

Description

@azerupi

Some people like to align match arms for readability

match val {
    &TOMLValue::Integer(_)        => ArrayType::Integer,
    &TOMLValue::Float(_)          => ArrayType::Float,
    &TOMLValue::Boolean(_)        => ArrayType::Boolean,
    &TOMLValue::DateTime(_)       => ArrayType::DateTime,
    &TOMLValue::Array(_)          => ArrayType::Array,
    &TOMLValue::String(_,_)       => ArrayType::String,
    &TOMLValue::InlineTable(_)    => ArrayType::InlineTable,
    &TOMLValue::Table             => panic!("Cannot have a table in an array"),
 }

And currently it gets reformatted like this

match val {
    &TOMLValue::Integer(_) => ArrayType::Integer,
    &TOMLValue::Float(_) => ArrayType::Float,
    &TOMLValue::Boolean(_) => ArrayType::Boolean,
    &TOMLValue::DateTime(_) => ArrayType::DateTime,
    &TOMLValue::Array(_) => ArrayType::Array,
    &TOMLValue::String(_, _) => ArrayType::String,
    &TOMLValue::InlineTable(_) => ArrayType::InlineTable,
    &TOMLValue::Table => panic!("Cannot have a table in an array"),
}

It would be nice if rustfmt offered an option like match_align_arms that can have multiple values:

  • Always: rustfmt will try to align all (non-block) match arms
  • Preserve: rustfmt will preserve alignment if it is already aligned manually. For matches that are not already aligned, current behavior will be used.
  • Never: current behavior

I think Preserve should be the default behavior.

/cc @joelself

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