Add from_over_into replace for type in Self reference

This commit is contained in:
MarcusGrass 2023-05-31 17:46:05 +02:00
parent 423f081089
commit d4b388eb43
No known key found for this signature in database
GPG key ID: B3F995FE064E3AA9
4 changed files with 108 additions and 2 deletions

View file

@ -88,4 +88,14 @@ impl Into<Opaque> for IntoOpaque {
fn into(self) -> Opaque {}
}
pub struct Lval<T>(T);
pub struct Rval<T>(T);
impl<T> From<Lval<T>> for Rval<Lval<T>> {
fn from(val: Lval<T>) -> Self {
Rval(val)
}
}
fn main() {}

View file

@ -88,4 +88,14 @@ impl Into<Opaque> for IntoOpaque {
fn into(self) -> Opaque {}
}
pub struct Lval<T>(T);
pub struct Rval<T>(T);
impl<T> Into<Rval<Self>> for Lval<T> {
fn into(self) -> Rval<Self> {
Rval(self)
}
}
fn main() {}

View file

@ -71,5 +71,18 @@ LL ~ fn from(val: Vec<T>) -> Self {
LL ~ FromOverInto(val)
|
error: aborting due to 5 previous errors
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
--> $DIR/from_over_into.rs:95:1
|
LL | impl<T> Into<Rval<Self>> for Lval<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: replace the `Into` implementation with `From<Lval<T>>`
|
LL ~ impl<T> From<Lval<T>> for Rval<Lval<T>> {
LL ~ fn from(val: Lval<T>) -> Self {
LL ~ Rval(val)
|
error: aborting due to 6 previous errors