Skip to content

Commit

Permalink
Auto merge of #61892 - rijenkii:master, r=Centril
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jun 16, 2019
2 parents 4edff84 + 7c84efd commit 70456a6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/test/run-pass/weird-exprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ fn i_yield() {
};
}

fn match_nested_if() {
let val = match () {
() if if if if true {true} else {false} {true} else {false} {true} else {false} => true,
_ => false,
};
assert!(val);
}

pub fn main() {
strange();
funny();
Expand All @@ -166,4 +174,5 @@ pub fn main() {
punch_card();
r#match();
i_yield();
match_nested_if();
}

0 comments on commit 70456a6

Please sign in to comment.