{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreieeubccbl7ycd6h5xlac2rczlf6vcf33jgfwn7g4x3y755ir653za",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mlzidardr6d2"
  },
  "path": "/t/mutually-exclusive-traits/24337#post_2",
  "publishedAt": "2026-05-17T03:49:28.000Z",
  "site": "https://internals.rust-lang.org",
  "tags": [
    "Negative impls"
  ],
  "textContent": "Negative impls are particularly relevant to auto traits, but they are equally usable for all traits. I don’t know if there are any plans to make negative impls usable to enable otherwise conflicting impls.\n\nAnother way to express mutual exclusion is to define a single trait, and discriminate the two cases using an associated constant or associated type:\n\n\n    #![feature(min_generic_const_args)]\n\n    use std::marker::PhantomData;\n\n    trait C {}\n    trait AOrB: C {\n        type const IS_B: bool;\n    }\n\n    struct Example<T: C>{ _marker: PhantomData<T> }\n    impl<T: AOrB<IS_B = false>> Example<T> {\n      fn test() {}\n    }\n\n    impl<T: AOrB<IS_B = true>> Example<T> {\n      fn test() {}\n    }\n\n\nConceptually, this should already work (if you use an associated type instead of a const), because a single impl of `AOrB` can’t have two values of `IS_B`, but the compiler doesn’t currently recognize this type of non-conflict.",
  "title": "Mutually exclusive traits"
}