-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lints
Description
When if
and else
arms have incompatible types, like below, the compiler should point at both arms with the evaluated type and also suggest removal of trailing semicolon if relevant.
fn main() {
let a = if false { "x" } else { "y"; };
}
error[E0308]: if and else have incompatible types
--> src/main.rs:2:13
|
2 | let a = if false { "x" } else { "y"; };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected &str, found ()
|
= note: expected type `&str`
found type `()`
Suggested:
error[E0308]: if and else have incompatible types
--> src/main.rs:2:13
|
2 | let a = if false { "x" } else { "y"; };
| --- ^^^- help: remove this semicolon
| | |
| | expected &str, found ()
| this arm evaluates to &str
= note: expected type `&str`
found type `()`
Example taken from lessons learned in Converting a Python library to Rust article
killercup, phansch, HadrienG2, frewsxcv, klesun and 1 more
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lints