-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Drop the Sized
constraint on impl Error for Box<T>
#39792
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
Conversation
Because of the implicit `Sized` constraint, `Box<Error>` does not implement `Error`, which is potentially surprising when trying to pass to a type which requires `T: Error`.
r? @BurntSushi (rust_highfive has picked a reviewer for you, use r? to override) |
This was always a fairly clunky API. Its main upside was that type inference was able to figure out the error type in more cases than the current implementation does. It has much larger downsides though. The most common case is that you're just returning `diesel::result::Error` anyway, so this enum was just an annoyance. If you weren't returning that, you were probably returning an application specific error which has a variant for `diesel::result::Error`, and now also had to handle this additional type. It also turns out that [`TransactionError<Box<::std::error::Error>>` doesn't implement `::std::error::Error`](rust-lang/rust#39792). The new API might require explicitly stating the error type in a few more places (in particular `try!(conn.transaction(|| try!(query); Ok(()))); Ok(...)` stopped inferring), but I think that this will end up being more ergonomic for most uses.
This was always a fairly clunky API. Its main upside was that type inference was able to figure out the error type in more cases than the current implementation does. It has much larger downsides though. The most common case is that you're just returning `diesel::result::Error` anyway, so this enum was just an annoyance. If you weren't returning that, you were probably returning an application specific error which has a variant for `diesel::result::Error`, and now also had to handle this additional type. It also turns out that [`TransactionError<Box<::std::error::Error>>` doesn't implement `::std::error::Error`](rust-lang/rust#39792). The new API might require explicitly stating the error type in a few more places (in particular `try!(conn.transaction(|| try!(query); Ok(()))); Ok(...)` stopped inferring), but I think that this will end up being more ergonomic for most uses.
This was always a fairly clunky API. Its main upside was that type inference was able to figure out the error type in more cases than the current implementation does. It has much larger downsides though. The most common case is that you're just returning `diesel::result::Error` anyway, so this enum was just an annoyance. If you weren't returning that, you were probably returning an application specific error which has a variant for `diesel::result::Error`, and now also had to handle this additional type. It also turns out that [`TransactionError<Box<::std::error::Error>>` doesn't implement `::std::error::Error`](rust-lang/rust#39792). The new API might require explicitly stating the error type in a few more places (in particular `try!(conn.transaction(|| try!(query); Ok(()))); Ok(...)` stopped inferring), but I think that this will end up being more ergonomic for most uses.
I believe the coherence error is why we can't do this :( |
|
Wanna try it out? :) I vaguely remember this being a rabbit hole, but if travis is green and we can add this, then seems good to me. |
This attempts to address the coherence issues raised by 42e4007
Hm. It didn't help. I don't see an obvious reason why (maybe something to do with |
This was always a fairly clunky API. Its main upside was that type inference was able to figure out the error type in more cases than the current implementation does. It has much larger downsides though. The most common case is that you're just returning `diesel::result::Error` anyway, so this enum was just an annoyance. If you weren't returning that, you were probably returning an application specific error which has a variant for `diesel::result::Error`, and now also had to handle this additional type. It also turns out that [`TransactionError<Box<::std::error::Error>>` doesn't implement `::std::error::Error`](rust-lang/rust#39792). The new API might require explicitly stating the error type in a few more places (in particular `try!(conn.transaction(|| try!(query); Ok(()))); Ok(...)` stopped inferring), but I think that this will end up being more ergonomic for most uses.
This was always a fairly clunky API. Its main upside was that type inference was able to figure out the error type in more cases than the current implementation does. It has much larger downsides though. The most common case is that you're just returning `diesel::result::Error` anyway, so this enum was just an annoyance. If you weren't returning that, you were probably returning an application specific error which has a variant for `diesel::result::Error`, and now also had to handle this additional type. It also turns out that [`TransactionError<Box<::std::error::Error>>` doesn't implement `::std::error::Error`](rust-lang/rust#39792). The new API might require explicitly stating the error type in a few more places (in particular `try!(conn.transaction(|| try!(query); Ok(()))); Ok(...)` stopped inferring), but I think that this will end up being more ergonomic for most uses.
Because of the implicit
Sized
constraint,Box<Error>
does notimplement
Error
, which is potentially surprising when trying to passto a type which requires
T: Error
.