Skip to content
Playground(another site)

bynk.generics.missing_ord_bound

Error A type parameter is ordered (<, <=, >, >=, an ordering kernel key), or passed to an Ord-bounded parameter of another generic, but is not declared Ord ([T: Ord], or where A: Ord for a receiver type's parameter). The diagnostic carries a machine-applicable fix that declares Ord, replacing an existing Eq, which Ord implies (constrained-generics slice 1).

<, <=, > and >= work on a type parameter only if the function says so with an Ord bound. A type parameter stands for any type, and many types have no total order: a function, an Effect, a Bool, a record that does not derives Ord. The bound puts the requirement in the signature, where a caller, hover and signature help can see it, and a call must instantiate it with an orderable type. The same rule covers an ordering key and a parameter passed on to an Ord-bounded parameter of another generic, so the bound appears at every link of a chain of calls. Declare T: Ord; it implies Eq, so an existing Eq is replaced (T: Eq + Ord is only a warning). The diagnostic's fix adds the bound, and bynk check --fix applies it across a project.

Example

fn bigger[T](a: T, b: T) -> Bool {
a > b // ✗ `T` has no order
}
fn bigger[T: Ord](a: T, b: T) -> Bool {
a > b // ✓ the bound is in the signature
}

In the Book

See also

  • The grammar rule it governs: fn_decl.
  • Every code in its category, Generics, on the diagnostic index.
  • bynk explain bynk.generics.missing_ord_bound shows the same from the installed toolchain, without a network.