-
Notifications
You must be signed in to change notification settings - Fork 13.4k
2024 edition regression: cannot write blanket implementation for closures that return the Never type #139610
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
Comments
We might be able to abuse the fact that EDIT: It's not clear that a workaround of this form will work for us, but we'd be happy to be proven wrong! |
No, that is not the never type. That is mod fn_ret {
pub trait FnRet {
type Output;
}
impl<R> FnRet for fn() -> R {
type Output = R;
}
}
pub type Never = <fn() -> ! as fn_ret::FnRet>::Output; (The |
That workaround should work for us! Would you like me to leave this issue open or close it? |
To my knowledge the never type is currently only really unstable to avoid people relying on So as long as you don't implement |
I think keeping this open as fine in case other people encounter this issue as well |
So, on the regression side -- I think this is entirely expected. The reason this worked before is incidental, there is nothing in the code that should force the closure to return For the workaround, I think @lcnr's assesment is correct -- the only thing stopping never type from being stabilized is our desire to make That being said you are still opting out of stability guarantees, so should is just that -- should. |
You can track our workaround PR here: bevyengine/bevy#18804. I've tried to leave copious warnings and explanations. I will be mildly annoyed if this hack breaks before the real From my perspective, this is primarily an "ease user pain in tests and prototypes" problem ( |
As laid out in the guide for the Never type fallback, closures which panic are now inferred to return
!
, rather than()
.In Bevy, we encountered this surprising breaking change in the form of bevyengine/bevy#18778. While individual users can work around this by writing
|my closure | -> ()
and explicitly specifying a return type or by using an ordinary function, we cannot work around this breakage ourselves by writing another blanket implementation because the Never type (!
) is not available on stable Rust.The text was updated successfully, but these errors were encountered: