Ruta graveolens  ·  notes from a language experiment  ·  cultivated since 2025

E0308: Opaque bounded operator

CodeCategoryStability
E0308SemanticPermanent

Explanation

A bounded comptime type parameter is opaque inside its own function body: it has exactly the members its bound requires and none of the built-in operators of chapters 4.2 and 4.3. Equality is not a universal operation, so == and != are unavailable on a value whose type is, or contains, such a parameter.

Likely cause

The body compares two values of its bounded parameter with == or !=. Require the comparison in the bound as a named method, such as fn equals(borrow self, borrow other: Self) -> bool, and call that instead.

Examples

Equality on an opaque bounded type

Requires --preview interfaces.

interface Show { fn show(borrow self) -> i64; }
fn same(comptime T: Show, borrow x: T, borrow y: T) -> bool { x == y }
fn main() {}

Require the comparison

Requires --preview interfaces.

interface Equatable { fn equals(borrow self, borrow other: Self) -> bool; }
fn same(comptime T: Equatable, borrow x: T, borrow y: T) -> bool { x.equals(borrow y) }
fn main() {}

References