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

Propagate never type #337

Open
adeschamps opened this issue Dec 7, 2019 · 0 comments
Open

Propagate never type #337

adeschamps opened this issue Dec 7, 2019 · 0 comments

Comments

@adeschamps
Copy link
Contributor

The following fails to compile:

use failure::Error;

fn main() -> Result<(), Error> {
    let success: Result<(), !> = Ok(());
    success?;
    Ok(())
}
error[E0277]: the trait bound `(): std::error::Error` is not satisfied
 --> src/main.rs:8:12
  |
8 |     success?;
  |            ^ the trait `std::error::Error` is not implemented for `()`
  |
  = note: required because of the requirements on the impl of `failure::Fail` for `()`
  = note: required because of the requirements on the impl of `std::convert::From<()>` for `failure::error::Error`
  = note: required by `std::convert::From::from`

It can be made to compile by mapping the error type:

success.map_err(|e| format_err!("never: {}", e))?;

... but that results in a warning for unreachable code, since the error type is !.

Is there a workaround for this? Right now I'm calling unwrap(), and I put some explicit type annotations so if the error type ever changes, It'll fail to compile.

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

1 participant