{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreibtaxzm6zhvl4rzli74662g7tmni5islywuujkio5qzvaszylffhe",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mlzidk6fhhc2"
  },
  "path": "/t/mutually-exclusive-traits/24337#post_1",
  "publishedAt": "2026-05-17T02:33:20.000Z",
  "site": "https://internals.rust-lang.org",
  "textContent": "In current Rust, there doesn’t seem to be a way to declare two traits as mutually exclusive.\n\nFor example, suppose I have two traits `A` and `B` that are semantically mutually exclusive. I also have a struct `Example` that takes a generic parameter `T: C` , where both `A: C` and `B: C` .\n\n\n    trait C {}\n    trait A: C {}\n    trait B: C {}\n    // A and B are semantically mutually exclusive.\n    struct Example<T: C>{ _marker: PhantomData<T> }\n\n\nWriting `impl<T: C> Example<T> {}` is perfectly fine. Then writing `impl<T: A> Example<T> { fn test() {} }` also seems acceptable. However, when I try to also write `impl<T: B> Example<T> { fn test() {} }` , the compiler complains that the two implementations conflict.\n\n\n    impl<T: C> Example<T> {} // ok\n\n    impl<T: A> Example<T> {\n      fn test() {}\n    } // still ok\n\n    impl<T: B> Example<T> {\n      fn test() {}\n    }// currently not ok\n\n\nIn fact, the compiler is not wrong — there could conceivably be a weird type that implements both semantically exclusive traits, leaving the compiler uncertain how to proceed. But currently, there is no way to declare that two traits are mutually exclusive. I understand that there is currently an unstable feature called \"negative trait impls,\" but that seems to be intended for auto traits. Perhaps there is a better way to achieve this?",
  "title": "Mutually exclusive traits"
}