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

Vertical sprawl #5565

Closed
kornelski opened this issue Oct 19, 2022 · 1 comment
Closed

Vertical sprawl #5565

kornelski opened this issue Oct 19, 2022 · 1 comment

Comments

@kornelski
Copy link

kornelski commented Oct 19, 2022

Rustfmt has formatted this:

    assert_eq!(1, srv.state.metrics.unique.lock().unwrap().unique_request_urls.get());
    assert_eq!(1, srv.state.metrics.unique.lock().unwrap().unique_request_etags.get());

as

   assert_eq!(
        1,
        srv.state
            .metrics
            .unique
            .lock()
            .unwrap()
            .unique_request_urls
            .get()
    );
    assert_eq!(
        1,
        srv.state
            .metrics
            .unique
            .lock()
            .unwrap()
            .unique_request_etags
            .get()
    );

This
  vertical
  explosion
  is
  absurd.

This
  is
  not
  readable.

This
  is
  not
  a
  sensible
  formatting
  for
  such
  code.

There is no max line length setting that avoids this. If I set it to long lines, then rustfmt will unwrap well-formatted multi-line code into long spaghetti lines. If I set it to short, I get vertical sprawl like this. It's broken both ways.

Please, change rustfmt to behave like gofmt. Instead of being a canonicalizer designed for rewrapping worst-case machine-generated code, it should be a style-corrector designed to gently cooperate on human-written code.

The essential difference is that gofmt preserves line breaks inserted by the author. If a construct has been written in a single line, it will stay as a one-liner. If a construct has been written in multiple lines, it won't be unwrapped to a long line, regardless of max line setting. Without this behavior rustfmt's token-based heuristics are doomed to make absurd formatting mistakes like this.

@ytmimi
Copy link
Contributor

ytmimi commented Oct 19, 2022

@kornelski I understand that you might be frustrated, but please be mindful of your tone. The approach you've taken above is not constructive, and not conducive to a respectful discussion.

Have you considered setting chain_width=100? doing so would format your input as follows:

assert_eq!(
    1,
    srv.state.metrics.unique.lock().unwrap().unique_request_urls.get()
);
assert_eq!(
    1,
    srv.state.metrics.unique.lock().unwrap().unique_request_etags.get()
);

Going to close this as a duplicate of #4306

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants