{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreibddrias5dkkg6pxsank6o5d2ty2zyhvvn6m6ki2k25xsytlxdqy4",
"uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mnqvwtu3ths2"
},
"path": "/t/named-impl-with-implementation-selection-variant/24374#post_4",
"publishedAt": "2026-06-08T03:47:49.000Z",
"site": "https://internals.rust-lang.org",
"textContent": "Let me explain the Prohibition Rules\n\n 1. Named-impl must be forbidden for Copy, Drop, Send, Sync, Unpin, etc\n\n\n\n\n let a = Box::new(42);\n let b = a as Box<i32> + Copy use BadCopy;\n let c = b; // copy, not move\n drop(b);\n drop(c); // double free\n\n\n 2. Named-impl must be forbidden for Hash, Ord, PartialOrd, Eq, PartialEq, etc. at least when a default implementation exists.\n\n\n\n\n struct SortedList<T: PartialOrd> {} // always keeps elements in order defined by T: PartialOrd\n let sl_org = SortedList::new((1,2),(2,3),(3,1)); // invariant: (1,2), (2,3), (3,1)\n let sl_alt = SortedList::<(i32,i32) + PartialOrd use SortBy1>::new((1,2),(2,3),(3,1)); // uses different ordering, yields (3,1), (1,2), (2,3)\n // Dangerous: converting an existing collection to a variant with a different comparator\n let sl_bad = s1 as SortedList<(i32,i32) + PartialOrd use SortBy1>; // breaks the internal invariant\n\n\nAnd so, custom comparator also breaks `BTreeMap`, custom `Hash` will break `HashMap`.",
"title": "Named impl with Implementation Selection Variant"
}