mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-15 01:55:03 +00:00
d92dd3d915
This is done using a pretty terribad hack, introducing an extra function parameter and some code duplication. Unfortunately, there seem to be few alternatives.
51 lines
937 B
Rust
51 lines
937 B
Rust
// rustfmt-single_line_if_else: true
|
|
|
|
// Format if-else expressions on a single line, when possible.
|
|
|
|
fn main() {
|
|
let a = if 1 > 2 {
|
|
unreachable!()
|
|
} else {
|
|
10
|
|
};
|
|
|
|
let a = if x { 1 } else if y { 2 } else { 3 };
|
|
|
|
let b = if cond() {
|
|
5
|
|
} else {
|
|
// Brief comment.
|
|
10
|
|
};
|
|
|
|
let c = if cond() {
|
|
statement();
|
|
|
|
5
|
|
} else {
|
|
10
|
|
};
|
|
|
|
let d = if let Some(val) = turbo
|
|
{ "cool" } else {
|
|
"beans" };
|
|
|
|
if cond() { statement(); } else { other_statement(); }
|
|
|
|
if true {
|
|
do_something()
|
|
}
|
|
|
|
let x = if veeeeeeeeery_loooooong_condition() { aaaaaaaaaaaaaaaaaaaaaaaaaaa } else { bbbbbbbbbb };
|
|
|
|
let x = if veeeeeeeeery_loooooong_condition() { aaaaaaaaaaaaaaaaaaaaaaaaa } else {
|
|
bbbbbbbbbb };
|
|
|
|
funk(if test() {
|
|
1
|
|
} else {
|
|
2
|
|
},
|
|
arg2);
|
|
}
|