Indeed, you cannot implement irreducible control-flow graphs in Rust. How do you write this C snippet in Rust with labeled breaks? (a, b and c represent three states that loop in that sequence when returning false, and in reverse when true)
while(1) {
a: if(a()) goto c;
b: if(b()) goto a;
c: if(c()) goto b;
}
The best you can do is duplicate one of the states to transform it into a (reducible) CFG with 4 states. E.g.
loop {
loop {
if a() || !b() {
break;
}
}
loop {
if !c() || b() {
break;
}
}
}
This one does optimize perfectly, but that's relying on LLVM to find and merge identical code blocks.
For reference, here's the previous IRLO discussion where many of these points were discussed: [Pre-RFC] Safe goto with value
So maybe the topic should really be "Why does Rust not support proper tail calls / finite state machines / <insert any flavor of goto that isn't called 'goto'>?"
edit: Meant to reply to matklad. There doesn't seem to be a way to change that in editing.