Uh oh!
There was an error while loading. Please reload this page.
Move ::std::error to ::core::error - #33149
Conversation
- Moved entire module to libcore - Apply `#[fundamental]` to the `Error` trait [breaking-change] - Move Box downcast methods to methods on `Box<Error>` [breaking-change]
rust-highfive
commented
Apr 22, 2016
(rust_highfive has picked a reviewer for you, use r? to override) |
alexcrichton
commented
Apr 22, 2016
The libs team has been very hesitant to make any more traits It is kinda unfortunate that |
bors
commented
May 8, 2016
☔ The latest upstream changes (presumably #33494) made this pull request unmergeable. Please resolve the merge conflicts. |
alexcrichton
commented
May 11, 2016
The libs team discussed this during triage the other day and the conclusion was that we don't want to do this. The We can perhaps do this eventually by informing coherence that specifically some times (e.g. those in libcore) won't implement Thanks though for the PR @thepowersgang! |
tarcieri
commented
Jun 10, 2017
@alexcrichton any chance your opinion has changed on this in the past year? This seems like something of a blocker for using things like error-chain in rust-lang-deprecated/error-chain#157 My solution there was to vendor all of libstd's error.rs into error-chain for use in |
arielb1
commented
Jun 12, 2017
The libcore PR was rejected because it made I think that can be bypassed with this hack (a combination of what I'll call the "exotic closure" trait and "predicate" trait): in libcore: #[doc(hidden)]#[unstable(feature="libstd_implementation_detail")]pubtraitErrorOrStrMapper{typeOutput;fnfrom_error<E:Error>(self,e:E) -> Self::Output;fnfrom_str(self,s:&str) -> Self::Output;}#[doc(hidden)]#[unstable(feature="libstd_implementation_detail")]traitErrorOrStr{fnconvert<F:ErrorOrStrMapper>(self,f:F) -> F::Output;}impl<E:Error>ErrorOrStrforE{fnto_error<F:ErrorOrStrMapper>(self,f:F) -> F::Output{
f.from_error(self)}}// ok because libcore knows that `! &'a str : Error`impl<'a>ErrorOrStrfor&'astr{fnto_error<F:ErrorOrStrMapper>(self,f:F) -> F::Output{
f.from_str(self)}}in liballoc ( structStringError(Box<str>);structBoxErrorMapper;implErrorOrStrMapperforBoxErrorMapper{typeOutput = Box<Error + Send + Sync>;fnfrom_error<E:Error>(self,e:E) -> Self::Output{Box::new(e)}fnfrom_str(self,s:&str) -> Self::Output{// I'm not sure on that `From` - we might want to return an// OomError here if we fail to allocate enough memory.Box::new(StringError(From::from(s)))}}impl<E:ErrorOrStr>From<E>forBox<Error + Send + Sync>{fnfrom(err:E) -> Self{
err.to_error(BoxErrorMapper)}}impl<E:ErrorOrStr>From<E>forBox<Error>{fnfrom(err:E) -> Self{
err.to_error(BoxErrorMapper)}}implFrom<Box<str>>forBox<Error + Send + Sync>{fnfrom(s:Box<str>) -> Self{Box::new(StringError(s))}}// ok because String is local, so we know `!String: ErrorOrStr`implFrom<Box<str>>forBox<Error>{fnfrom(s:String) -> Self{Box::new(StringError(s))}}in libcollections: // ok because String is local, so we know `!String: ErrorOrStr`implFrom<String>forBox<Error + Send + Sync>{fnfrom(s:String) -> Self{Self::from(s.into_boxed_str())}}// ok because String is local, so we know `!String: ErrorOrStr`implFrom<String>forBox<Error>{fnfrom(s:String) -> Self{Self::from(s.into_boxed_str())}}The downside is that the docs will have the |
This is probably relevant here: https://internals.rust-lang.org/t/crate-evaluation-for-2017-06-27-error-chain/5362/25 In short, there are plans to move |
jbowens
commented
Nov 20, 2017
😢 |
tarcieri
commented
Nov 20, 2017
@withoutboats' |
The idea of this is to move the
Errortrait intolibcore, where it can be used by more code, particularlyno_stdcode.It however has a few possibly breaking changes in it. The first is that the
downcastmethods were moved from being onError(the unsized type) to being onBox<Error>. This changes the UFCS paths, but doesn't change the method-call usage.Secondly, the
Errortrait has been marked with#[fundamental]to allow theFrom<&str> for Box<Error>impls to work. When raised on IRC, the tentative conclusion was that being an error is not an incidental aspect of a type, so this is acceptable.Feel free to reject this PR if it breaks existing code, it's more of a "nice to have" feature.