This is a simple recursive solution for the Euler Problem n.45 ( #45 Triangular, pentagonal, and hexagonal - Project Euler , adapted from euler-scala/Euler045.scala at master · samskivert/euler-scala · GitHub ):

```
fn findh(pent: u64, h: u64) -> u64 {
let hex = h * (2 * h - 1);
if hex > pent { findh(pent, h - 1)
} else if hex < pent { 0
} else { hex }
}
fn findp(tri: u64, p: u64) -> u64 {
let pent = p * (3 * p - 1 ) / 2;
if pent > tri { findp(tri, p - 1)
} else if pent < tri { 0
} else { findh(pent, p - 1) }
}
fn main() {
let e45 = (286 ..).map(|t| findp(t * (t + 1) / 2, t - 1)).find(|&t| t != 0).unwrap();
println!("{}", e45); // 1_533_776_805
}
```

The same code using a match:

```
use std::cmp::Ordering::*;
fn findh(pent: u64, h: u64) -> u64 {
let hex = h * (2 * h - 1);
match hex.cmp(&pent) {
Less => 0,
Equal => hex,
Greater => findh(pent, h - 1)
}
}
fn findp(tri: u64, p: u64) -> u64 {
let pent = p * (3 * p - 1 ) / 2;
match pent.cmp(&tri) {
Less => 0,
Equal => findh(pent, p - 1),
Greater => findp(tri, p - 1)
}
}
fn main() {
let e45 = (286 ..).map(|t| findp(t * (t + 1) / 2, t - 1)).find(|&t| t != 0).unwrap();
println!("{}", e45); // 1_533_776_805
}
```

On my system the if-based version, runs in about 0.35 seconds, while the match-based version runs in about 0.72 seconds, compiled with -O to remove the recursion from both.

If I compile using `#[inline(never)]`

on the if-based findh() function, I see the asm (rustc 1.9.0-nightly (b12b4e4e3 2016-03-17)):

```
_ZN5findh20h23cdf1eac3cc0c77eaaE:
leaq -1(%rdx,%rdx), %rax
.align 16, 0x90
.LBB0_1:
movq %rax, %r8
imulq %rdx, %r8
decq %rdx
addq $-2, %rax
cmpq %rcx, %r8
ja .LBB0_1
xorl %eax, %eax
cmpq %rcx, %r8
cmovaeq %r8, %rax
retq
```

While the match-based version gives:

```
_ZN5findh20hbde3eb7bf24af692faaE:
leaq -1(%rdx,%rdx), %r8
jmp .LBB0_1
.align 16, 0x90
.LBB0_7:
addq $-1, %rdx
addq $-2, %r8
.LBB0_1:
movq %r8, %rax
imulq %rdx, %rax
xorl %r9d, %r9d
cmpq %rcx, %rax
movb $-1, %r10b
jb .LBB0_3
movb $1, %r10b
.LBB0_3:
je .LBB0_5
movb %r10b, %r9b
.LBB0_5:
testb %r9b, %r9b
je .LBB0_9
movzbl %r9b, %eax
cmpl $1, %eax
je .LBB0_7
xorl %eax, %eax
.LBB0_9:
retq
```

I've also tried to compile the match-based code with `-C opt-level=3 -C target-cpu=native`

but the result is the same.

Can Rustc improve to compile the match-based version about as well as the if-based version, or do I have to expect this kind of match-induced pessimization?