Open
Description
I tried this code:
#![feature(try_trait_v2)]
struct Flip<T>(T);
impl<T> std::ops::FromResidual<Flip<T>> for Option<T>
{
fn from_residual(residual: Flip<T>) -> Self {
Some(residual.0)
}
}
I expected to see this happen: Code compiles successfully
Instead, this happened:
error[[E0119]](https://doc.rust-lang.org/nightly/error-index.html#E0119): conflicting implementations of trait `std::ops::FromResidual<Flip<_>>` for type `std::option::Option<_>`
--> src/lib.rs:3:1
|
3 | impl<T> std::ops::FromResidual<Flip<T>> for Option<T>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T> FromResidual for Option<T>;
As you you see, the stdlib has
impl<T> FromResidual for Option<T> {}
Which makes use of a default type arg on FromResidual
- <Self as Try>::Residual
. For Option<T>
, that is Option<Infallible>
.
So apparently, FromResidual<Option<Infallible>>
conflicts with FromResidual<Flip<T>>
.
Playing devil's advocate, we could assume that FromResidual
is being conservative with its conflicts because Try::Residual
could change, but it could never change to a type I own.
Meta
rustc --version --verbose
:
rustc 1.64.0-nightly (3924dac7b 2022-07-29)
binary: rustc
commit-hash: 3924dac7bb29bc8eb348059c901e8f912399c857
commit-date: 2022-07-29
host: aarch64-apple-darwin
release: 1.64.0-nightly
LLVM version: 14.0.6