Skip to content

struct_variant_width should not override the max line width #1802

@radix

Description

@radix

let's set tab_spaces = 2, max_width = 10 and struct_variant_width = 10. I would like for this to format some code like this:

enum F {
  X {
    a: d,
    b: e,
  },
}

however what it ends up doing is this:

enum F {
  X { a: d, b: e },
}

and printing a warning about how it accidentally formatted the X line too long.

even though the X line is longer than 10 spaces. This is because struct_variant_width is really only applying to the fields of the struct (the a: d, b: e part, not counting wrapping spaces or braces), not the entire line.

Now technically it's documented to match the current behavior: (from Configurations.md):

Maximum width in the body of a struct variant before falling back to vertical formatting

but this seems not very useful IMO. I'm not sure if other "width" settings act like this but I have never run into it anywhere else.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugPanic, non-idempotency, invalid code, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions