-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compile error with type mismatch in Fn() -> !
#129441
Comments
This is expected behavior. The type #![feature(never_type)]
fn main(){
let vec = vec!["0"];
let closure = || -> ! {
dbg!(&vec);
panic!()
};
let s = vec.get(0).unwrap_or_else(|| closure());
} Here, the |
@theemathas I see, but I don't understand why the closure type can't be converted automatically, why is that? |
@rustbot labels -C-bug
It's just not how Rust works today. Maybe it could someday. Someone would need to write up an RFC motivating it and working through all the many details and implications of it. |
I think it is for the same reason that you can't pass a closure |
I tried this code:
playground link
I expected these code to compile.
Instead, I got type can not assign:
The
closure
never return and we no need to care about it return and rust'snever
type can be assigned to any type in type theory.Meta
rustc --version --verbose
:There are no backtrace output with
RUST_BACKTRACE=1
Tracking:
!
to a type (RFC 1216) #35121The text was updated successfully, but these errors were encountered: