{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreigpm4qo5qltuan3ati67zehjqmwbkcppjfnhslad2f5xbruujx4wa",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3ml3azkcws332"
  },
  "path": "/t/too-strict-orphan-rules-e0117/24221#post_1",
  "publishedAt": "2026-05-05T02:47:17.000Z",
  "site": "https://internals.rust-lang.org",
  "textContent": "Code:\n\n\n    use std::collections::VecDeque;\n\n    struct MyVec<T>(Vec<T>);\n\n    impl<T> From<Option<Vec<T>>> for Option<MyVec<T>> {\n        fn from(value: Option<Vec<T>>) -> Self {\n            Some(MyVec(value?))\n        }\n    }\n\n    impl From<Option<Vec<i32>>> for Option<MyVec<i32>> {\n        fn from(value: Option<Vec<i32>>) -> Self {\n            Some(MyVec(value?))\n        }\n    }\n\n    struct Node<T> {\n        val: T,\n        next: Option<Box<Node<T>>>,\n    }\n\n    impl<T> From<VecDeque<Box<Node<T>>>> for Option<Box<Node<T>>> {\n        fn from(mut value: VecDeque<Box<Node<T>>>) -> Self {\n            let mut head = value.pop_front()?;\n            let mut current = &mut head;\n            for node in value {\n                current.next = Some(node);\n                current = current.next.as_mut().unwrap()\n            }\n            Some(head)\n        }\n    }\n\n    fn main() {}\n\n\nAnd the result:\n\n\n       Checking explore v0.1.0 (/home/PC-Killer/projects/explore)\n    error[E0119]: conflicting implementations of trait `From<Option<Vec<i32>>>` for type `Option<MyVec<i32>>`\n     --> src/main.rs:11:1\n      |\n    5 | impl<T> From<Option<Vec<T>>> for Option<MyVec<T>> {\n      | ------------------------------------------------- first implementation here\n    ...\n    11 | impl From<Option<Vec<i32>>> for Option<MyVec<i32>> {\n      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Option<MyVec<i32>>`\n\n    error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate\n    --> src/main.rs:5:1\n     |\n    5 | impl<T> From<Option<Vec<T>>> for Option<MyVec<T>> {\n     | ^^^^^^^^--------------------^^^^^----------------\n     |         |                        |\n     |         |                        `Option` is not defined in the current crate\n     |         `Option` is not defined in the current crate\n     |\n     = note: impl doesn't have any local type before any uncovered type parameters\n     = note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules\n     = note: define and implement a trait or new type instead\n\n    error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate\n     --> src/main.rs:11:1\n      |\n    11 | impl From<Option<Vec<i32>>> for Option<MyVec<i32>> {\n      | ^^^^^----------------------^^^^^------------------\n      |      |                          |\n      |      |                          `Option` is not defined in the current crate\n      |      `Option` is not defined in the current crate\n      |\n      = note: impl doesn't have any local type before any uncovered type parameters\n      = note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules\n      = note: define and implement a trait or new type instead\n\n    error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate\n     --> src/main.rs:22:1\n      |\n    22 | impl<T> From<VecDeque<Box<Node<T>>>> for Option<Box<Node<T>>> {\n      | ^^^^^^^^----------------------------^^^^^--------------------\n      |         |                                |\n      |         |                                `Option` is not defined in the current crate\n      |         `VecDeque` is not defined in the current crate\n      |\n      = note: impl doesn't have any local type before any uncovered type parameters\n      = note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules\n      = note: define and implement a trait or new type instead\n\n    Some errors have detailed explanations: E0117, E0119.\n    For more information about an error, try `rustc --explain E0117`.\n    error: could not compile `explore` (bin \"explore\") due to 4 previous errors\n\n\nDivide this into three parts:\n\n  1. struct MyVec<T>(Vec<T>);\n\n         impl<T> From<Option<Vec<T>>> for Option<MyVec<T>> {\n             fn from(value: Option<Vec<T>>) -> Self {\n                 Some(MyVec(value?))\n             }\n         }\n\n\nHere we implement `From<Option<Vec<T>>` for `Option<MyVec<T>>`, and the compiler reports that we voilate the orphan rule. However, `MyVec` is defined in the scope, so there's no chance that a more specialized overload will be defined in any other modules.\n  2. impl From<Option<Vec<i32>>> for Option<MyVec<i32>> {\n             fn from(value: Option<Vec<i32>>) -> Self {\n                 Some(MyVec(value?))\n             }\n         }\n\n\nSince we all use concrete types like `Option<MyVec<i32>>`, which means it's impossible that there is a more specialized implementation than this. However the compiler just reports that `Option<MyVec<i32>>` is foreign, which is a little _stupid_.\n  3. struct Node<T> {\n             val: T,\n             next: Option<Box<Node<T>>>,\n         }\n\n         impl<T> From<VecDeque<Box<Node<T>>>> for Option<Box<Node<T>>> {\n             fn from(mut value: VecDeque<Box<Node<T>>>) -> Self {\n                 let mut head = value.pop_front()?;\n                 let mut current = &mut head;\n                 for node in value {\n                     current.next = Some(node);\n                     current = current.next.as_mut().unwrap()\n                 }\n                 Some(head)\n             }\n         }\n\n\nThis proves that similar case _does_ make sense, while still being rejected by the compiler.\n\n\n\nIs it possible to correct the behavior?",
  "title": "Too strict orphan rules E0117"
}