Skip to content

Instantly share code, notes, and snippets.

@kracekumar
Created November 13, 2016 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kracekumar/3800fe67395acc5b8794c89e1597d830 to your computer and use it in GitHub Desktop.
Save kracekumar/3800fe67395acc5b8794c89e1597d830 to your computer and use it in GitHub Desktop.

user@user-ThinkPad-T400 ~/c/imon> cargo --explain E0117

This error indicates a violation of one of Rust's orphan rules for trait implementations. The rule prohibits any implementation of a foreign trait (a trait defined in another crate) where

  • the type that is implementing the trait is foreign
  • all of the parameters being passed to the trait (if there are any) are also foreign.

Here's one example of this error:

impl Drop for u32 {}

To avoid this kind of error, ensure that at least one local type is referenced by the impl:

pub struct Foo; // you define your type in your crate

impl Drop for Foo { // and you can implement the trait on it!
    // code of trait implementation here
}

impl From<Foo> for i32 { // or you use a type from your crate as
                         // a type parameter
    fn from(i: Foo) -> i32 {
        0
    }
}

Alternatively, define a trait locally and implement that instead:

trait Bar {
    fn get(&self) -> usize;
}

impl Bar for u32 {
    fn get(&self) -> usize { 0 }
}

For information on the design of the orphan rules, see RFC 1023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment