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
Rustfmt fails to format the following code.
Nothing is printed to the console. However, if I deliberately add a trailing whitespace somewhere, then it starts emitting the "left behind trailing whitespace" error, like in #2896
struct Foo;
impl Foo {
async fn foo(&mut self) {
if true {
async {
if true {
if true {
if true {
log::info!("A relatively long string 111111111111111111111111111111111111111111");
}
}
}
}
.await;
}
}
}
Commenting out either the log or the await line fixes the issue.
The .await makes this a chain. The deeply nested nature of this code is what makes it hard fro rustfmt to deal with. The line containing log::info!("A relatively long string 111111111111111111111111111111111111111111"); is 114 characters long, which exceeds the max width.
If you bump the max_width to some sufficiently high number (I tried 120), then the code reformats:
structFoo;implFoo{asyncfnfoo(&mutself){iftrue{async{iftrue{iftrue{iftrue{
log::info!("A relatively long string 111111111111111111111111111111111111111111");}}}}.await;}}}
Given that max_width is a hard constraint for rustfmt I'd recommend refactoring code so that it isn't as deeply nested if you can.
Rustfmt fails to format the following code.
Nothing is printed to the console. However, if I deliberately add a trailing whitespace somewhere, then it starts emitting the "left behind trailing whitespace" error, like in #2896
Commenting out either the
log
or theawait
line fixes the issue.My config:
Version:
The text was updated successfully, but these errors were encountered: