You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnreturns_closure(maybe:bool) -> implFn(i32) -> i32{if maybe {
|x| x + 1}else{
|y| y + 2}}
I expected that the compilation would fail because the closures have different types:
error[E0308]: `if` and `else` have incompatible types
--> src/main.rs:5:9
|
2 | / if maybe {
3 | | |x| x + 1
| | --------- expected because of this
4 | | } else {
5 | | |y| y + 2
| | ^^^^^^^^^ expected closure, found a different closure
6 | | }
| |_____- `if` and `else` have incompatible types
|
= note: expected type `[closure@src/main.rs:3:9: 3:18]`
found closure `[closure@src/main.rs:5:9: 5:18]`
I tried this code:
I expected that the compilation would fail because the closures have different types:
Instead, the code compiles.
Meta
Fails to compile (as expected)
rustc +1.44 --version --verbose
:Compiles (unexpectedly)
rustc +1.45 --version --verbose
:rustc +stable --version --verbose
rustc +nightly --version --verbose
The text was updated successfully, but these errors were encountered: