You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(the specific content of the string literal does not seen to matter, but the length does).
Run rustfmt filename.rs
Get:
> rustfmt stuff.rs
error[internal]: left behind trailing whitespace
--> \\?\D:\path\to\stuff.rs:2:2:17
|
2 | let results =
| ^
|
warning:rustfmt has failed to format.See previous 1errors.
Note that the mere presence of the string literal anywhere in the file breaks formatting for the entire file, not just for the containing block (but that might be WAI)
Expected behavior
no [internal error]; other lines get formatted just fine, even if this one cannot
Thank you for reaching out @moxian. This is a duplicate (#3863) of a known/existing issues with formatting chains when one or more of the chain elements would exceed max_width when formatted. In these cases, rustfmt leaves the original formatting in place and defers to the developer to properly format, because any formatting rustfmt would apply would violate a rule (max width in this case)
Your snippet above contains a chain due to the foo.bar(... on line 3, and the string arg exceeds the max_width value of 100. Your original snippet has a trailing space after the = on line 2, so when rustfmt bails on formatting the chain and reverts to the original snippet, your original trailing space is maintained which triggers the trailing whitespace warning.
To get rid of the warning, you should remove the trailing whitespace after the =. To allow rustfmt to be able to format the chain, you could try moving the raw string lit out of the chain foo.bar(some_new_var) or if you don't need a raw string lit, use a regular string and try setting format_strings = true in your rustfmt config file to allow rustfmt to split the string to stay within the max_width limit.
Note that the mere presence of the string literal anywhere in the file breaks formatting for the entire file, not just for the containing block (but that might be WAI)
Hmmm. I'm not able to reproduce this locally (although I do observe this behavior on the Playground).
Describe the bug
Have a file with the following contents:
(the specific content of the string literal does not seen to matter, but the length does).
Run
rustfmt filename.rs
Get:
Note that the mere presence of the string literal anywhere in the file breaks formatting for the entire file, not just for the containing block (but that might be WAI)
Expected behavior
no [internal error]; other lines get formatted just fine, even if this one cannot
Meta
rustfmt path\to\file.rs
and the vscode integration observe the same result)The text was updated successfully, but these errors were encountered: