Skip to content

Commit 70456a6

Browse files
committed
Auto merge of #61892 - rijenkii:master, r=Centril
weird-exprs: if if if if The `if` keyword can be chained as long as there are enough `{...} else {...}` following, and they all return a `bool` (not required for the last one). `if` expression can be also put inside a `match` arm guard, thus making the whole thing a little bit more confusing. Discovered this clusterfunk while reading the reference because I have nothing better to do.
2 parents 4edff84 + 7c84efd commit 70456a6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/test/run-pass/weird-exprs.rs

+9
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ fn i_yield() {
149149
};
150150
}
151151

152+
fn match_nested_if() {
153+
let val = match () {
154+
() if if if if true {true} else {false} {true} else {false} {true} else {false} => true,
155+
_ => false,
156+
};
157+
assert!(val);
158+
}
159+
152160
pub fn main() {
153161
strange();
154162
funny();
@@ -166,4 +174,5 @@ pub fn main() {
166174
punch_card();
167175
r#match();
168176
i_yield();
177+
match_nested_if();
169178
}

0 commit comments

Comments
 (0)