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

rustfmt gives up on entire closure if it contains a long string #5528

Closed
acshi opened this issue Sep 2, 2022 · 3 comments
Closed

rustfmt gives up on entire closure if it contains a long string #5528

acshi opened this issue Sep 2, 2022 · 3 comments

Comments

@acshi
Copy link

acshi commented Sep 2, 2022

I'm sure this is a variation on many previous issues, but it is also a little different and worse (in my humble opinion).

If we have a long string in a structure, that structure is not formatted: #4800

If we have a long string in a chain of function calls, that chain is not formatted: #3863

However, if we have a long string somewhere in a closure, the entire closure is not formatted! This is a much worse user experience, and does not give any errors by default to even guide why rustfmt fails.

I took the example from #4800 and wrapped it in a closure. rustfmt does nothing and doesn't complain either:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=1193f5482e94bfbdfbdb6a5a0c93866b

@ytmimi
Copy link
Contributor

ytmimi commented Sep 2, 2022

Setting error_on_unformatted=true and error_on_line_overflow=true will give you feedback on the long string that's preventing formatting. Although not a fix, that can help you more quickly track down what's going on.

error[internal]: line formatted, but exceeded maximum width (maximum: 100 (see `max_width` option), found: 121)
 --> <stdin>:9:101
  |
9 |               foo: "long_long_long_long_long_long_long_lo_long_long_long_long_long_long__long_long_long_long_long_long_",
  |                                                                                                     ^^^^^^^^^^^^^^^^^^^^^
  |
  = note: set `error_on_unformatted = false` to suppress the warning against comments or string literals

error[internal]: line formatted, but exceeded maximum width (maximum: 100 (see `max_width` option), found: 133)
  --> <stdin>:10:101
   |
10 | bar: "long_long_long_long_long_long_long_long_long_long_lo_long_long_lolong_long_long_lo_long_long_lolong_long_long_lo_long_long_lo",
   |                                                                                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: set `error_on_unformatted = false` to suppress the warning against comments or string literals

warning: rustfmt has failed to format. See previous 2 errors.

@calebcartwright
Copy link
Member

I'm closing as a duplicate of #3863. The closure is a red herring; it's the .map call on the opening line, for which the closure is an argument, which makes the entire element a chain.

@calebcartwright calebcartwright closed this as not planned Won't fix, can't repro, duplicate, stale Sep 3, 2022
@calebcartwright
Copy link
Member

This is a much worse user experience, and does not give any errors by default to even guide why rustfmt fails.

From #3863 (comment):

try running with --config error_on_line_overflow=true which exists for precisely this purpose (make sure you're on nightly), it's just disabled by default. If you'd like to make a case for that being enabled by default then #3391 would be the place to do so

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

3 participants