Closed
Conversation
Contributor
|
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
Contributor
|
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...). |
Member
|
Triage: It seems further work on never type work will make this PR obsolete. I'll mark this as blocked for now. |
Member
The goal is that as part of the stabilization, |
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_okandResult::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 standardInfallibleone?I then tried
impl Into<!> for Infallibleinstead. 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 implementingIntois 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 correspondingFromdoes 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_okandinto_errmethods 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 wantInfallibleto be convertible to the real never type, I think this is cleaner and more useful forInfalliblein general.