Stream: ideas

Topic: trailing backslash for multi-line collections


view this post on Zulip Luke Boswell (Aug 31 2025 at 23:20):

We talked brielfy about using \ to prevent editors from stripping whitespace from multi-line string literals.

Something else that I'd love to have is the ability to prevent the formatter from merging lines in other collections, and I thought it would be nice to use it there also.

# format the line, but keep the breaks
matrix =
    (
      1, 0, 0, \
      0, 1, 0, \
      0, 0, 1, \
    )

# keep the trailing spaces
multi-line-str =
    """Some thing       \
    """other line       \

view this post on Zulip Brendan Hansknecht (Aug 31 2025 at 23:25):

I feel like even without \ that it would be incorrect behaviour to strip trailing spaces from multiline strings.

view this post on Zulip Brendan Hansknecht (Aug 31 2025 at 23:25):

That just sounds highly bug prone.

view this post on Zulip Brendan Hansknecht (Aug 31 2025 at 23:26):

Probably would be fine for the formatter to insert the \ though

view this post on Zulip Luke Boswell (Aug 31 2025 at 23:27):

I think the problem is some editors will strip the trailing whitespace on save

view this post on Zulip Luke Boswell (Aug 31 2025 at 23:28):

Or maybe I misunderstood that previous conversation

view this post on Zulip Luke Boswell (Aug 31 2025 at 23:28):

I agree the roc formatter shouldn't do that

view this post on Zulip Brendan Hansknecht (Aug 31 2025 at 23:37):

I think the problem is some editors will strip the trailing whitespace on save

Oh...hmm... didn't realize that

view this post on Zulip Brendan Hansknecht (Aug 31 2025 at 23:38):

If that is the case, trailing \ makes sense as a solution

view this post on Zulip Richard Feldman (Sep 01 2025 at 00:58):

isn't # already a 1-character solution to this problem? :thinking:

view this post on Zulip Luke Boswell (Sep 01 2025 at 01:27):

I guess it could be, but current formatter does this (just tried it out)

matrix =
    (
        1,
        0,
        0, #
        0,
        1,
        0, #
        0,
        0,
        1, #
    )

view this post on Zulip Luke Boswell (Sep 01 2025 at 01:30):

I was a passing thought, I haven't really thought hard about it. It just felt like a similar thing to the multi-line string thing.

view this post on Zulip Richard Feldman (Sep 01 2025 at 01:38):

ah interesting

view this post on Zulip Fabian Schmalzried (Sep 01 2025 at 04:48):

I would always assume everything in the line after the multiline string starts is part of the string. Having to escape, trailing \ would be annoying for example when having a markdown string. That's probably more common than trailing spaces? And I don't know of any editor that removes trailing spaces without explicit configuration.

For collections using # makes a lot of sense to me. And its also more discoverable, if you want to annotate the lines.

view this post on Zulip Joshua Warner (Sep 01 2025 at 04:57):

And I don't know of any editor that removes trailing spaces without explicit configuration.

IIRC Zed was doing this a while ago at least, presumably because of auto-rustfmt on save (by out-of-the-box config). Ran into exactly this case when editing some test cases for the old compiler a while back, where editing anything in the file in zed would make the tests break because it stripped trailing spaces in the multi-line strings we were comparing our output to.


Last updated: Jun 16 2026 at 16:19 UTC