Uh oh!
There was an error while loading. Please reload this page.
Implement error interoperation (RFC 70) - #17753
Conversation
rust-highfive
commented
Oct 3, 2014
9b13971 to
4f22561CompareThere was a problem hiding this comment.
Here, the return type is Option<&str>, but in the actual definition of the trait, the return type is Option<String>
aturon
commented
Oct 3, 2014
@japaric Thanks, fixed. |
There was a problem hiding this comment.
Do we have a path forward for unifying these other than allowing &Error to be casted to &Any?
There was a problem hiding this comment.
That's the ideal path; I'm not sure how soon that's likely to happen.
Alternatively, we could probably define macros for this, but given visibility rules that seemed more pain than gain right now.
aturon
commented
Oct 3, 2014
@alexcrichton fixed, thanks. |
There was a problem hiding this comment.
I would actually expect inspection of errors to not fall under "an overwhelming majority of rust code does this", but rather just the tip of the stack is the one to inspect the error. Along those lines, I'm not sure I'd put this in the prelude to get access to the methods.
On the other hand, implementing the trait is always convenient if you don't have to import it (and it avoids the std::error::Error stutter).
The RFC doesn't look like it mentions any modifications to the prelude, so I'm curious, what was your rationale for placing this here?
There was a problem hiding this comment.
I was just writing a comment to get your opinion about this. You're right, it wasn't mentioned in the RFC and for that reason alone probably shouldn't happen here.
I also worry about having the name Error show up in the prelude. So maybe an explicit import makes more sense.
(My rationale was just that you'd generally expect methods like description to be available on error types without needing to import a trait, but that's pretty weak sauce.)
alexcrichton
commented
Oct 3, 2014
Do you think it may be best to wait for multidispatch to land before landing this? This is a pretty minimal change, so I don't think it's too susceptible to bitrot (ok on that front). I'd be more curious in going ahead and leveraging this trait throughout some examples in the stdlib/compiler/etc to give it a bit of usage and make sure the |
aturon
commented
Oct 3, 2014
@alexcrichton Addressed comments, removed from prelude. |
aturon
commented
Oct 3, 2014
@alexcrichton Sure, we can wait to land this until multidispatch, and I can add tests/examples to docs. |
4110531 to
5a7810eCompareaturon
commented
Oct 13, 2014
Just an update: I've tried rolling this out with multidispatch now being snapshotted. However, there are some problems with type inference. @nikomatsakis is looking into it. We can't land this change to In general, also, the two blanket |
nikomatsakis
commented
Oct 14, 2014
cc #18019 |
ghost
commented
Oct 23, 2014
@aturon Is this good to go after the next snapshot? |
alexcrichton
commented
Oct 24, 2014
cc #18259 for new snapshots |
aturon
commented
Oct 31, 2014
@alexcrichton I've updated with documentation and use of multidispatch. Building fine here. re-r? |
This PR: * Adds the error interoperation traits (`Error` and `FromError`) to a new module, `std::error`, as per [RFC 70](https://github.com/rust-lang/rfcs/blob/master/active/0070-error-chaining.md). Note that this module must live in `std` in order to refer to `String`. Note that, until multidispatch lands, the `FromError` trait cannot be usefully implemented outside of the blanket impl given here. * Incorporates `std::error::FromError` into the `try!` macro. * Implements `Error` for most existing error enumerations. Closes#17747
This PR: * Adds the error interoperation traits (`Error` and `FromError`) to a new module, `std::error`, as per [RFC 70](https://github.com/rust-lang/rfcs/blob/master/active/0070-error-chaining.md). Note that this module must live in `std` in order to refer to `String`. Note that, until multidispatch lands, the `FromError` trait cannot be usefully implemented outside of the blanket impl given here. * Incorporates `std::error::FromError` into the `try!` macro. * Implements `Error` for most existing error enumerations. Closes#17747
As per [RFC 70](https://github.com/rust-lang/rfcs/blob/master/active/0070-error-chaining.md) Closesrust-lang#17747 Note that the `error` module must live in `std` in order to refer to `String`. Note that, until multidispatch lands, the `FromError` trait cannot be usefully implemented outside of the blanket impl given here.
This PR: * Adds the error interoperation traits (`Error` and `FromError`) to a new module, `std::error`, as per [RFC 70](https://github.com/rust-lang/rfcs/blob/master/active/0070-error-chaining.md). Note that this module must live in `std` in order to refer to `String`. Note that, until multidispatch lands, the `FromError` trait cannot be usefully implemented outside of the blanket impl given here. * Incorporates `std::error::FromError` into the `try!` macro. * Implements `Error` for most existing error enumerations. Closes#17747
This PR:
Adds the error interoperation traits (
ErrorandFromError) to a new module,std::error, as per RFC 70. Note that this module must live instdin order to refer toString.Note that, until multidispatch lands, the
FromErrortrait cannot beusefully implemented outside of the blanket impl given here.
Incorporates
std::error::FromErrorinto thetry!macro.Implements
Errorfor most existing error enumerations.Closes#17747