-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Coercion from non-capturing closure to fn ptr fails when return type is !
#66738
Comments
test closure-to-fn-ptr coercions a bit more Also add some commented-out failing tests, Cc rust-lang/rust#66738 #1075
This also works: I'm not surprised inference of |
Could this have a common root cause with #66757? They both compile if |
Actually the error happens even on stable, entirely independent of the |
I suspect this is not actually a bug, in some sense. Currently, the closure being passed into the function here doesn't get a return type of That means we basically end up with a situation where the return type of the closure is "unknown", and so falls back to |
Ah, I see, that makes sense... and indeed this variant works: #![feature(never_type)]
fn magic<F: FnOnce() -> !>(f: F) -> F { f }
fn main() {
let f2 = magic(|| loop {}) as fn() -> !;
} |
Usually, non-capturing closures can be coerced to
fn
ptrs. But somehow that seems to fail when the return type is!
:The error is
This fails even on nightly, where
!
should be stable as a type.Curiously, this works:
Cc @Centril
The text was updated successfully, but these errors were encountered: