Closed
Description
Consider the following example (using clap, as it's one of the easiest builders to demonstrate with):
use clap::{Arg, Command};
fn main() {
let matches = Command::new("app")
.arg(Arg::new("debug").long("debug").short('d').help("Enable additional debugging.").takes_value(false))
.about("This string is really super long and rustfmt refuses to wrap it, so long that it isn't even suitable on a line of its own.")
.arg(Arg::new("debug").long("debug").short('d').help("Enable additional debugging.").takes_value(false))
.get_matches();
}
rustfmt does nothing (tested on current playground, 1.4.38-nightly (2022-05-05 30f3860)).
Whereas the following example, without the exceedingly long string:
use clap::{Arg, Command};
fn main() {
let matches = Command::new("app")
.arg(Arg::new("debug").long("debug").short('d').help("Enable additional debugging.").takes_value(false))
.about("This is a short string.")
.arg(Arg::new("debug").long("debug").short('d').help("Enable additional debugging.").takes_value(false))
.get_matches();
}
Formats to the following (what I would expect):
use clap::{Arg, Command};
fn main() {
let matches = Command::new("app")
.arg(
Arg::new("debug")
.long("debug")
.short('d')
.help("Enable additional debugging.")
.takes_value(false),
)
.about("This is a short string.")
.arg(
Arg::new("debug")
.long("debug")
.short('d')
.help("Enable additional debugging.")
.takes_value(false),
)
.get_matches();
}
It seems like rustfmt gives up on the entire statement if any part won't satisfy the width heuristic in the output, rather than still doing its best. The ideal formatting for the long string version would be the final output of the short string version, with the short string substituted. With extremely long builder chains this leads to horrible formatting, as it must all be done manually.