fmt-rfcs icon indicating copy to clipboard operation
fmt-rfcs copied to clipboard

Multi-line expressions on both sides of an assignment shouldn't wrap to the same indent level

Open joshtriplett opened this issue 1 year ago • 5 comments

I discovered this issue in some code I'm working on, and constructed this sample to match the issue I observed:

impl SomeType {
    fn method(&mut self) {
        self.array[array_index as usize]
            .as_mut()
            .expect("thing must exist")
            .extra_info = Some(ExtraInfo {
            parent,
            count: count as u16,
            children: children.into_boxed_slice(),
        });
    }
}

The fields of ExtraInfo should not be wrapping to the same indent level as the method chain. I can imagine a few ways to format this better, and don't feel strongly about which one, just that this definitely isn't the right formatting.

joshtriplett avatar Dec 28 '23 14:12 joshtriplett

This also happens with a simpler version:

impl SomeType {
    fn method(&mut self) {
        self.array[array_index as usize]
            .as_mut()
            .expect("thing must exist")
            .extra_info =
            long_long_long_long_long_long_long_long_long_long_long_long_long_long_long;
    }
}

joshtriplett avatar Jan 10 '24 20:01 joshtriplett

Turns out this happens with other binary operators like + too, not just =.

@compiler-errors came up with a concise rule for how to fix these cases:

The parent identation that we use to make any relative indent/deindent for binary operators should use the indentation level of the last line of the LHS, not the first.

joshtriplett avatar Jan 10 '24 21:01 joshtriplett

We discussed this in the T-style meeting today, and the consensus was that we should adopt the rule that Josh just mentioned:

The parent indentation that we use to make any relative indent/deindent for binary operators should use the indentation level of the last line of the LHS, not the first.

(Credit to @compiler-errors for this rule.)

traviscross avatar Jan 10 '24 21:01 traviscross

@rustbot claim

johnhuichen avatar Aug 31 '24 14:08 johnhuichen

Error: Malformed triagebot.toml in default branch. TOML parse error at line 5, column 7 | 5 | "*" = "style" | ^^^^^^^ invalid type: string "style", expected a sequence

Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #t-infra on Zulip.

rustbot avatar Aug 31 '24 14:08 rustbot