Skip to content

if-else inside match arm always wraps #6707

@jesseschalken

Description

@jesseschalken

The following code

let prefix = match power {
    0 => "",
    1 => if binary { "K" } else { "k" },
    _ => &"MGTPEZYRQ"[power - 2..][..1],
};

is always formatting as the following

let prefix = match power {
    0 => "",
    1 => {
        if binary {
            "K"
        } else {
            "k"
        }
    }
    _ => &"MGTPEZYRQ"[power - 2..][..1],
};

There doesn't appear to be any option to keep the second match arm on a single line. (use_small_heuristics = "Max", max_width = 9999, match_arm_blocks = false and single_line_if_else_max_width = 9999 are not effective.)

I am testing with the following config with the nightly toolchain:

edition = "2024"
empty_item_single_line = true
fn_single_line = true
format_strings = true
group_imports = "StdExternalCrate"
hex_literal_case = "Lower"
imports_granularity = "Module"
match_arm_blocks = false
max_width = 9999
overflow_delimited_expr = true
reorder_impl_items = true
single_line_if_else_max_width = 9999
single_line_let_else_max_width = 9999
style_edition = "2024"
trailing_semicolon = false
unstable_features = true
use_field_init_shorthand = true
use_small_heuristics = "Max"
use_try_shorthand = true

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-matchesArea: match arms, patterns, blocks, etcneeds-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions