Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upMove `::std::error` to `::core::error` #33149
Conversation
rust-highfive
assigned
alexcrichton
Apr 22, 2016
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
The libs team has been very hesitant to make any more traits It is kinda unfortunate that |
alexcrichton
added
the
T-libs
label
Apr 22, 2016
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
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! |
alexcrichton
closed this
May 11, 2016
This comment has been minimized.
This comment has been minimized.
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-nursery/error-chain#157 My solution there was to vendor all of libstd's error.rs into error-chain for use in |
tarcieri
referenced this pull request
Jun 10, 2017
Closed
no_std support (via an enabled-by-default "std" feature) #157
This comment has been minimized.
This comment has been minimized.
|
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")]
pub trait ErrorOrStrMapper {
type Output;
fn from_error<E: Error>(self, e: E) -> Self::Output;
fn from_str(self, s: &str) -> Self::Output;
}
#[doc(hidden)]
#[unstable(feature="libstd_implementation_detail")]
trait ErrorOrStr {
fn convert<F: ErrorOrStrMapper>(self, f: F) -> F::Output;
}
impl<E: Error> ErrorOrStr for E {
fn to_error<F: ErrorOrStrMapper>(self, f: F) -> F::Output {
f.from_error(self)
}
}
// ok because libcore knows that `! &'a str : Error`
impl<'a> ErrorOrStr for &'a str {
fn to_error<F: ErrorOrStrMapper>(self, f: F) -> F::Output {
f.from_str(self)
}
}in liballoc ( struct StringError(Box<str>);
struct BoxErrorMapper;
impl ErrorOrStrMapper for BoxErrorMapper {
type Output = Box<Error + Send + Sync>;
fn from_error<E: Error>(self, e: E) -> Self::Output {
Box::new(e)
}
fn from_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> for Box<Error + Send + Sync> {
fn from(err: E) -> Self {
err.to_error(BoxErrorMapper)
}
}
impl<E: ErrorOrStr> From<E> for Box<Error> {
fn from(err: E) -> Self {
err.to_error(BoxErrorMapper)
}
}
impl From<Box<str>> for Box<Error + Send + Sync> {
fn from(s: Box<str>) -> Self {
Box::new(StringError(s))
}
}
// ok because String is local, so we know `!String: ErrorOrStr`
impl From<Box<str>> for Box<Error> {
fn from(s: String) -> Self {
Box::new(StringError(s))
}
}in libcollections: // ok because String is local, so we know `!String: ErrorOrStr`
impl From<String> for Box<Error + Send + Sync> {
fn from(s: String) -> Self {
Self::from(s.into_boxed_str())
}
}
// ok because String is local, so we know `!String: ErrorOrStr`
impl From<String> for Box<Error> {
fn from(s: String) -> Self {
Self::from(s.into_boxed_str())
}
}The downside is that the docs will have the |
This comment has been minimized.
This comment has been minimized.
Pratyush
commented
Jul 13, 2017
•
|
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 |
This comment has been minimized.
This comment has been minimized.
jbowens
commented
Nov 20, 2017
|
|
This comment has been minimized.
This comment has been minimized.
tarcieri
commented
Nov 20, 2017
|
@withoutboats' |
thepowersgang commentedApr 22, 2016
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.