Skip to content

Commit

Permalink
Add impl From<!> for Infallible
Browse files Browse the repository at this point in the history
The reverse conversion unfortunately causes unexpected errors like:

```
error[E0277]: the trait bound `!: std::convert::From<()>` is not satisfied
   --> src/librustc_metadata/encoder.rs:105:9
    |
105 |         self.emit_usize(seq.len)?;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::convert::From<()>` is not implemented for `!`
    |
    = help: the following implementations were found:
              <! as std::convert::From<std::convert::Infallible>>
    = note: the trait is implemented for `()`. Possibly this error has been caused by changes to Rust's type-inference algorithm (see: #48950 for more info). Consider whether you meant to use the type `()` here instead.
    = note: required by `std::convert::From::from`
```

I don’t understand why this error happens.
If I’m reading the code correctly the return types of `emit_usize`
and of the method that contains line 105 are both `Result<(), !>`,
so the expansion of the `?` operator should involve `!: From<!>`,
not `From<()>`.

Is this a type inference bug?
  • Loading branch information
SimonSapin committed Feb 13, 2019
1 parent c80a8f5 commit b2cf9a0
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libcore/convert.rs
Expand Up @@ -596,3 +596,10 @@ impl PartialEq for Infallible {

#[stable(feature = "convert_infallible", since = "1.34.0")]
impl Eq for Infallible {}

#[stable(feature = "convert_infallible", since = "1.34.0")]

This comment has been minimized.

Copy link
@Centril

Centril Feb 22, 2019

Contributor

Not that this attribute has any effect, but... it isn't really stable :)

impl From<!> for Infallible {
fn from(x: !) -> Self {
x
}
}

0 comments on commit b2cf9a0

Please sign in to comment.