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

Propagate never type #337

Open
Open
@adeschamps

Description

@adeschamps

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions