You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// trait Crypto is foreignpubstructMyAccountKey;pubstructMyCrypto;implCryptoforMyCrypto{typeAccountKey = MyAccountKey}// impl<'a> From<&'a <MyAccountKey as Crypto>::AccountKey> for ForeignFoo {// fn from(_: &'a <MyAccountKey as Crypto>::AccountKey) -> Self {// todo!()// }// }impl<'a>From<&'aAcmeEspAccountKey>forForeignFoo{fnfrom(_:&'aAcmeEspAccountKey) -> Self{todo!()}}
I expected to see this happen: both commented code and uncommented code should compile fine
Instead, this happened: orphan rule is triggered:
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
--> src/my_crypto.rs:95:1
|
95 | impl<'a> From<&'a ::AccountKey> for ForeignFoo {
| ^^^^^^^^^---------------------------------------------------^^^^^-------------
| | | |
| | | ForeignFoo is not defined in the current crate
| | <MyAccountKey as Crypto>::AccountKey is not defined in the current crate
| impl doesn't use only types from inside the current crate
|
= note: define and implement a trait or new type instead
your snippet fails the orphan check. the orphan check does not look into associated types as it has to run before we are able to do so.
It is therefore not able to tell that <MyAccountKey as Crypto>::AccountKey would be a local type and this is expected behavior. Opened #102734 to potentially improve the error message here
I tried this code:
I expected to see this happen: both commented code and uncommented code should compile fine
Instead, this happened: orphan rule is triggered:
error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
--> src/my_crypto.rs:95:1
|
95 | impl<'a> From<&'a ::AccountKey> for ForeignFoo {
| ^^^^^^^^^---------------------------------------------------^^^^^-------------
| | | |
| | |
ForeignFoo
is not defined in the current crate| |
<MyAccountKey as Crypto>::AccountKey
is not defined in the current crate| impl doesn't use only types from inside the current crate
|
= note: define and implement a trait or new type instead
Meta
rustc --version --verbose
:Backtrace
The text was updated successfully, but these errors were encountered: