Closed
Description
Currently, given this program:
#[inline(never)]
fn get_bool(slot: &mut Option<bool>) -> &mut bool {
if slot.is_none() {
*slot = Some(true);
}
slot.as_mut().unwrap()
}
#[inline(never)]
fn get_uint(slot: &mut Option<uint>) -> &mut uint {
if slot.is_none() {
*slot = Some(1);
}
slot.as_mut().unwrap()
}
fn main() {
println!("{}", get_bool(&mut None));
println!("{}", get_uint(&mut None));
}
It generates this IR.
The "unfortunate" part here is that a call to failure is generated for the get_bool
function where no failure is generated for the get_uint
function.
There's a lot going on here so I'm not sure if it's our codegen or LLVM's codegen, but I would personally expect both cases to optimize down to never unwinding because it's known that neither Option
can ever be None
.