Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow chains to condense to remove some single line ) #171

Open
TheBlueMatt opened this issue May 26, 2022 · 0 comments
Open

Allow chains to condense to remove some single line ) #171

TheBlueMatt opened this issue May 26, 2022 · 0 comments

Comments

@TheBlueMatt
Copy link

One common complaint I've seen (and made myself) coming to rust-guide-formatted code from many other languages is the vertical-ness of a lot of common rust code. This leads to less context when viewing diffs (or functions entirely in smaller editor windows) which can be a common source of bugs. There's good reason for the vertical layout in many cases, of course - it can substantially improve scan-ability of code layout, and like all things, there is a balance to be had.

One common pattern in Rust is a somewhat long line causing a closing ) to be on its own line. While this can improve scan-ability, it can generate some very awkward looking chains, especially with a trailing unwrap(), which is also exceedingly common.

For example, we have some code which is formatted as

        let data = Vec::<u8>::from_hex(
            "02020202020202020202 longish hex constant",
        )
        .unwrap();

according to https://github.com/rust-dev-tools/fmt-rfcs/blob/master/guide/expressions.md#multi-line-elements

At the risk of starting a long discussion and flame-war on the topic of chains, I don't believe scan-ability of the code is substantially impacted (or arguably positively impacted by a change to allow the unwrap to appear on the same line as the ), as follows:

        let data = Vec::<u8>::from_hex(
            "02020202020202020202 longish hex constant",
        ).unwrap();

As a general principle, though its totally reasonable to have it be of the lowest priority, having a "provide more context in diffs and during editing by making things single-line where it does not at all impact scan-ability" principle would serve to avoid some bugs which, in my experience, are not entirely uncommon, though arguably scan-ability can sometimes avoid more/other bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant