Closed
Description
I tried this code:
#![feature(never_type)]
fn no_fail() -> Result<(), !> {
Ok(())
}
fn main() -> Result<(), ()> {
no_fail()?;
Ok(())
}
I expected to see this happen: successful compilation because of the blanket impl<T> From<!> for T
Instead, this happened:
error[E0277]: `?` couldn't convert the error to `()`
--> src/main.rs:8:14
|
7 | fn main() -> Result<(), ()> {
| -------------- expected `()` because of this
8 | no_fail()?;
| ^ the trait `From<!>` is not implemented for `()`
|
= note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
= help: the following other types implement trait `FromResidual<R>`:
<Result<T, F> as FromResidual<Result<Infallible, E>>>
<Result<T, F> as FromResidual<Yeet<E>>>
= note: required for `Result<(), ()>` to implement `FromResidual<Result<Infallible, !>>`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `tmp` due to previous error
Meta
rustc --version --verbose
:
rustc 1.65.0-nightly (1120c5e01 2022-09-08)
binary: rustc
commit-hash: 1120c5e01df508de64fe6642f22fadeb574afd6d
commit-date: 2022-09-08
host: x86_64-unknown-linux-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0
I cannot really make sense of the error message, as it complains about a missing From
impl. Maybe this is an issue with the Try
implementation (try_trait_v2
does not change the error) but I cannot tell.