Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error conversion with ! #101608

Closed
y86-dev opened this issue Sep 9, 2022 · 2 comments
Closed

Error conversion with ! #101608

y86-dev opened this issue Sep 9, 2022 · 2 comments
Labels
C-bug Category: This is a bug.

Comments

@y86-dev
Copy link
Contributor

y86-dev commented Sep 9, 2022

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.

@y86-dev y86-dev added the C-bug Category: This is a bug. label Sep 9, 2022
@Jules-Bertholet
Copy link
Contributor

Jules-Bertholet commented Sep 9, 2022

blanket impl<T> From<!> for T

This doesn't exist. It would conflict with impl<T> From<T> for T

@y86-dev
Copy link
Contributor Author

y86-dev commented Sep 9, 2022

I thought this was the impl: https://doc.rust-lang.org/src/core/convert/mod.rs.html#574-578

However I did not see the #[rustc_reservation_impl] (this was not visible in the rustdoc, leading to my confusion). #64715 is the related issue, if anyone is interested.

Going to close this as this should be tracked by the other issue.

@y86-dev y86-dev closed this as completed Sep 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants