Open
Description
I tried the following code (playground), following the examples for LUB coercion in the Reference, chapter 10.7.
The closure does not compile
let clo = || {
if true {
let x: *mut i32 = &mut 1;
x
} else if false {
let x: &i32 = &1;
x
} else {
let x: &mut i32 = &mut 1;
x
}
};
let _: *const i32 = clo();
with the error:
error[E0308]: `if` and `else` have incompatible types
A similar function does compile:
fn f() -> *const i32 {
if true {
let x: *mut i32 = &mut 1;
x
} else if false {
let x: &i32 = &1;
x
} else {
let x: &mut i32 = &mut 1;
x
}
}
According to the Reference, I expected that either both the closure and the function compiles or neither of them.