Closed
Description
Code
fn main() {
let x = if true {
&true
} else if false {
true
} else {
true
};
}
Current output
error[E0308]: `if` and `else` have incompatible types
--> src/main.rs:4:12
|
2 | let x = if true {
| ______________-
3 | | &true
| | ----- expected because of this
4 | | } else if false {
| | ____________^
5 | || true
6 | || } else {
7 | || true
8 | || };
| || ^
| ||_____|
| |_____`if` and `else` have incompatible types
| expected `&bool`, found `bool`
|
help: consider borrowing here
|
4 | } else &if false {
| +
Desired output
error[E0308]: `if` and `else` have incompatible types
--> src/main.rs:4:12
|
2 | let x = if true {
| ______________-
3 | | &true
| | ----- expected because of this
4 | | } else if false {
| | ____________^
5 | || true
6 | || } else {
7 | || true
8 | || };
| || ^
| ||_____|
| |_____`if` and `else` have incompatible types
| expected `&bool`, found `bool`
|
help: consider borrowing here
|
5 ~ &true
6 | } else {
7 ~ &true
|
Rationale and extra context
No response
Other cases
Rust Version
rustc 1.89.0-nightly (6f6971078 2025-05-28)
binary: rustc
commit-hash: 6f69710780d579b180ab38da4c1384d630f7bd31
commit-date: 2025-05-28
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
Anything else?
No response