Named impl with Implementation Selection Variant
Rust Internals [Unofficial]
June 8, 2026
Let me explain the Prohibition Rules
- Named-impl must be forbidden for Copy, Drop, Send, Sync, Unpin, etc
let a = Box::new(42);
let b = a as Box<i32> + Copy use BadCopy;
let c = b; // copy, not move
drop(b);
drop(c); // double free
- Named-impl must be forbidden for Hash, Ord, PartialOrd, Eq, PartialEq, etc. at least when a default implementation exists.
struct SortedList<T: PartialOrd> {} // always keeps elements in order defined by T: PartialOrd
let sl_org = SortedList::new((1,2),(2,3),(3,1)); // invariant: (1,2), (2,3), (3,1)
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)
// Dangerous: converting an existing collection to a variant with a different comparator
let sl_bad = s1 as SortedList<(i32,i32) + PartialOrd use SortBy1>; // breaks the internal invariant
And so, custom comparator also breaks BTreeMap, custom Hash will break HashMap.
Discussion in the ATmosphere