Single line if (without else) statement #6369
Replies: 1 comment
|
There is no rustfmt option that keeps a standalone if items.is_empty() { return Ok(()); }The similarly named stable option So the idiomatic, rustfmt-stable form is the expanded block. If you must preserve the compact guard locally, the available escape hatch is: #[rustfmt::skip]
fn add_cached(items: &[Item]) -> Result<(), Error> {
if items.is_empty() { return Ok(()); }
// ...
}but If this answers which setting applies, please mark the reply as accepted. |
Uh oh!
There was an error while loading. Please reload this page.
Hello all, I was working on a project of mine when I found that
rustfmtwas always expanding shortifstatements.For example, I have a function that adds cached items into a redis server, which would always fail if the items list is empty, so the following code snippet is used:
However, by default,
rustfmtalways expand it to:which takes 2 extra lines.
Is there an option I can use to compact it into the first snippet?
All reactions