match a.cmp(&b) {
Ordering::Equal => 0,
Ordering::Greater => 1,
Ordering::Less => -1
}
It's easy to see what the possible outputs are and what is produced in each case. The compiler even checks it to make sure you didn't forget any situations. fn leak() {
// Create a 1KiB heap-allocated vector
let b = Box::new(vec![0u8; 1024]);
// Turn it into a raw pointer
let p = Box::into_raw(b);
// Then leak the pointer
}
Obviously that's kind of blatant, but there are more subtle ways to leak memory. Memory leaks aren't considered unsafe, so even though they're undesirable the compiler doesn't guarantee you won't have any. foo.into_iter().map(|x| x+1)
.filter(|y| y > 2)
My working theory is that it's related to situations where there's multiple statements on the same source line (or inside a block inside a lambda).