error-chain
error-chain copied to clipboard
impl From<std::convert::Infallible> for Error
https://github.com/rust-lang/rust/pull/44174 landed in rust nightly and now I have to add
impl From<Infallible> for Error {
fn from(infallible: Infallible) -> Self {
match infallible {}
}
}
to my error chain Error. Can/Should this impl be included in the library?
I'm not sure I understand why this impl is needed?
I'm not really sure either, but it was triggered from the following:
let len: isize = isize::try_from(self.conn.num_app_context)?;
where I was converting from a u32 in a FFI binding to isize.
Here is the error if I comment out the impl.
error[E0277]: the trait bound `error::Error: std::convert::From<std::convert::Infallible>` is not satisfied
--> src/context/params.rs:312:26
|
312 | let len: isize = isize::try_from(self.conn.num_app_context)?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<std::convert::Infallible>` is not implemented for `error::Error`
|
= help: the following implementations were found:
<error::Error as std::convert::From<std::io::Error>>
<error::Error as std::convert::From<std::ffi::NulError>>
<error::Error as std::convert::From<std::env::VarError>>
<error::Error as std::convert::From<std::num::TryFromIntError>>
and 3 others
= note: required by `std::convert::From::from`
Oh, I see. Then yes, it would be good to add it to error-chain, maybe behind a feature until TryFrom comes to stable. I think this would be better:
impl From<Infallible> for Error {
fn from(_: Infallible) -> Self {
unreachable!()
}
}
Ah I see what this was all about now. Looks like right now we'd still need to convert from the infallible error type even if it was !, but maybe that will change in the future given the never type is a special snowflake.