Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

impl From<std::convert::Infallible> for Error #229

Open
CraZySacX opened this issue Oct 1, 2017 · 5 comments
Open

impl From<std::convert::Infallible> for Error #229

CraZySacX opened this issue Oct 1, 2017 · 5 comments

Comments

@CraZySacX
Copy link

rust-lang/rust#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?

@Yamakaky
Copy link
Contributor

Yamakaky commented Oct 1, 2017

I'm not sure I understand why this impl is needed?

@CraZySacX
Copy link
Author

CraZySacX commented Oct 1, 2017

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.

@CraZySacX
Copy link
Author

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`

@Yamakaky
Copy link
Contributor

Yamakaky commented Oct 1, 2017

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!()
    }
}

@KodrAus
Copy link
Contributor

KodrAus commented Oct 4, 2017

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants