Skip to main content

trait_uses_self_operand

Function trait_uses_self_operand 

Source
pub fn trait_uses_self_operand(trait_info: &TraitDeclInfo) -> bool
Expand description

True if any of trait_info’s methods reference Self in a (non-receiver) parameter type or in the return type.

A trait with a Self-typed operand — fn compare(self, other: Self) -> Ordering — cannot be encoded as a plain Go interface used as a generic bound: the interface method would have to be Compare(Self), but a Go interface cannot name the implementing type. The Go backend instead encodes such a trait as an F-bounded generic interface (type Comparable[T any] interface { Compare(T) Ordering }), satisfied by func (Key) Compare(Key), and lowers a bound [T: Comparable] to [T Comparable[T]]. This predicate selects the traits that need that treatment; a trait with no Self operand (only self) stays a plain interface.