-
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
Add impl Into<!> for Infallible
#83493
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
I'm tagging this as T-lang too because of the interaction with the never type fallback story (which btw we plan to try and advance soon...). |
Triage: It seems further work on never type work will make this PR obsolete. I'll mark this as blocked for now. |
The goal is that as part of the stabilization, |
It's currently possible to convert a never (
!
) type instance intoInfallible
(impl From<!> for Infallible
). But not the other way around. That means that the (unstable) methodsResult::into_ok
andResult::into_err
(tracking issue: #61695) that use the trait boundsInto<!>
will currently not work when you have aResult<Infallible, _>
orResult<_, Infallible>
.I tried to implement
impl From<Infallible> for !
and ended up with a number of compilation errors like these:I found in the git history that this was attempted previously, in commit b2cf9a0 in PR #58302 by @SimonSapin. And the problem is brought up in comment #58302 (comment) but no solution or discussion followed. I also don't understand the error. Is this the same inference problem that is currently preventing the never type from becoming stable? Clearly, custom never tokens can implement conversion into
!
, just not the standardInfallible
one?I then tried
impl Into<!> for Infallible
instead. And it seems to work. In the future when!
is (hopefully) stabilized, this impl can just be removed, as it will be covered by by the blanket implementationimpl<T> From<T> for T
. I know that manually implementingInto
is not recommended. But as far as I know it's also not forbidden? This might be a legitimate case where we need it, since the correspondingFrom
does not work?I'm not sure if this could complicate the stabilization of the never type maybe? If so, we should likely not merge this. As I'm really hoping to get the proper never type on stable sometime. Ping @nikomatsakis, since I think you are still looking into that?
I tagged it as
#[stable]
directly. My understanding is that trait impls can't be unstable? Please advice on how to proceed here if this is wrong. Is an RFC needed?Alternative solution (for Result::{into_ok, into_err} specifically)
For the
into_ok
andinto_err
methods specifically there is another way to make them work on stable before!
is stabilized. The trait bounds can be changed fromInto<!>
toInto<Infallible
. Since the conversion between the types work that way it will continue to be usable on nightly for the real never type, and it will allow stable to use the methods withInfallible
. But unless there are reasons we don't wantInfallible
to be convertible to the real never type, I think this is cleaner and more useful forInfallible
in general.