Skip to content
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

impl Fail for NoneError? #59

Closed
Celti opened this Issue Nov 18, 2017 · 9 comments

Comments

Projects
None yet
6 participants
@Celti
Copy link

Celti commented Nov 18, 2017

Using the currently (but probably not for very much longer) unstable Try trait, one can use the question mark operator on Option<T> types, coercing them into a Result<T, NoneError>. Unfortunately, NoneError does not impl std::error::Error, meaning the Fail is not implemented for NoneError (and it being an external type, we can't implement it in our own crates).

I think this would be particularly useful in light of the pattern described in “Using the Error type” — throwing a NoneError fits right into the kind of rapid prototyping, "just show the user the error and exit" limited error handling that that exemplifies.

Would a PR with this change go amiss?

@Celti

This comment has been minimized.

Copy link
Author

Celti commented Nov 18, 2017

Oh, blast. I just realised this isn't actually possible, because NoneError doesn't implement Display (or in fact anything besides a stack of derives) — which Fail of course requires. Will have to go upstream to see if we can get std::error::Error implemented for NoneError.

@Emilgardis

This comment has been minimized.

Copy link

Emilgardis commented Nov 28, 2017

Why is this closed? This is something that I really want, and something other users of this crate will want.

@vitvakatu

This comment has been minimized.

Copy link

vitvakatu commented Nov 28, 2017

Yep, I'm voting for re-opening

@Celti

This comment has been minimized.

Copy link
Author

Celti commented Nov 28, 2017

As stated in the comment where I closed it, this isn't technically possible — implementing Fail requires an implementation of Display, which NoneError does not currently have. The change will have to happen, and is happening, upstream. You'll just have to wait a while.

@Emilgardis

This comment has been minimized.

Copy link

Emilgardis commented Nov 28, 2017

Then this issue should track that progress.

@Emilgardis

This comment has been minimized.

Copy link

Emilgardis commented Nov 28, 2017

FWIW Here are all the related links
rust-lang/rust#31436 (tracking for ´?´)
rust-lang/rust#42526 (impl Try for Option)

As far I can see, unlike @Celti mentioned, there haven't been any discussion about making std::option::NoneError: std::error::Error or Display , could you link that for us?

@withoutboats

This comment has been minimized.

Copy link
Collaborator

withoutboats commented Nov 28, 2017

Implementing Fail for NoneError would be an orphan rules violation because of the blanket impls for type that implement std::error::Error (this is also why Fail is not implemented for String, for example). There's no progress that can be made on this issue in failure, only in std.

@dvdplm

This comment has been minimized.

Copy link

dvdplm commented Jan 5, 2018

@withoutboats Thank you for weighing in. Do you think making the necessary changes in std for this to happen is a good idea or are there hidden downsides?

@xnorme

This comment has been minimized.

Copy link

xnorme commented Jul 10, 2018

What is the current state regarding this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.