External Publication
Visit Post

Too strict orphan rules E0117

Rust Internals [Unofficial] May 5, 2026
Source

Code:

use std::collections::VecDeque;

struct MyVec<T>(Vec<T>);

impl<T> From<Option<Vec<T>>> for Option<MyVec<T>> {
    fn from(value: Option<Vec<T>>) -> Self {
        Some(MyVec(value?))
    }
}

impl From<Option<Vec<i32>>> for Option<MyVec<i32>> {
    fn from(value: Option<Vec<i32>>) -> Self {
        Some(MyVec(value?))
    }
}

struct Node<T> {
    val: T,
    next: Option<Box<Node<T>>>,
}

impl<T> From<VecDeque<Box<Node<T>>>> for Option<Box<Node<T>>> {
    fn from(mut value: VecDeque<Box<Node<T>>>) -> Self {
        let mut head = value.pop_front()?;
        let mut current = &mut head;
        for node in value {
            current.next = Some(node);
            current = current.next.as_mut().unwrap()
        }
        Some(head)
    }
}

fn main() {}

And the result:

   Checking explore v0.1.0 (/home/PC-Killer/projects/explore)
error[E0119]: conflicting implementations of trait `From<Option<Vec<i32>>>` for type `Option<MyVec<i32>>`
 --> src/main.rs:11:1
  |
5 | impl<T> From<Option<Vec<T>>> for Option<MyVec<T>> {
  | ------------------------------------------------- first implementation here
...
11 | impl From<Option<Vec<i32>>> for Option<MyVec<i32>> {
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Option<MyVec<i32>>`

error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
--> src/main.rs:5:1
 |
5 | impl<T> From<Option<Vec<T>>> for Option<MyVec<T>> {
 | ^^^^^^^^--------------------^^^^^----------------
 |         |                        |
 |         |                        `Option` is not defined in the current crate
 |         `Option` is not defined in the current crate
 |
 = note: impl doesn't have any local type before any uncovered type parameters
 = note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
 = note: define and implement a trait or new type instead

error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
 --> src/main.rs:11:1
  |
11 | impl From<Option<Vec<i32>>> for Option<MyVec<i32>> {
  | ^^^^^----------------------^^^^^------------------
  |      |                          |
  |      |                          `Option` is not defined in the current crate
  |      `Option` is not defined in the current crate
  |
  = note: impl doesn't have any local type before any uncovered type parameters
  = note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
  = note: define and implement a trait or new type instead

error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
 --> src/main.rs:22:1
  |
22 | impl<T> From<VecDeque<Box<Node<T>>>> for Option<Box<Node<T>>> {
  | ^^^^^^^^----------------------------^^^^^--------------------
  |         |                                |
  |         |                                `Option` is not defined in the current crate
  |         `VecDeque` is not defined in the current crate
  |
  = note: impl doesn't have any local type before any uncovered type parameters
  = note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules
  = note: define and implement a trait or new type instead

Some errors have detailed explanations: E0117, E0119.
For more information about an error, try `rustc --explain E0117`.
error: could not compile `explore` (bin "explore") due to 4 previous errors

Divide this into three parts:

  1. struct MyVec(Vec);

    impl<T> From<Option<Vec<T>>> for Option<MyVec<T>> {
        fn from(value: Option<Vec<T>>) -> Self {
            Some(MyVec(value?))
        }
    }
    

Here 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. 2. impl From<Option<Vec>> for Option<MyVec> { fn from(value: Option<Vec>) -> Self { Some(MyVec(value?)) } }

Since 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. 3. struct Node { val: T, next: Option<Box<Node>>, }

     impl<T> From<VecDeque<Box<Node<T>>>> for Option<Box<Node<T>>> {
         fn from(mut value: VecDeque<Box<Node<T>>>) -> Self {
             let mut head = value.pop_front()?;
             let mut current = &mut head;
             for node in value {
                 current.next = Some(node);
                 current = current.next.as_mut().unwrap()
             }
             Some(head)
         }
     }

This proves that similar case does make sense, while still being rejected by the compiler.

Is it possible to correct the behavior?

Discussion in the ATmosphere

Loading comments...