Propagate never type
adeschamps opened this issue · 0 comments
adeschamps commented
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.