Skip to content
TE825 · Type · error

Incomplete trait impl: missing required method

An `impl Trait for Type` is missing one or more required methods (those without a default body). Method and operator dispatch would otherwise fail at runtime.

Why this fires

An impl Trait for Type (or the compact-struct nested impl Trait { … }) is missing one or more required methods of the trait. A trait method is required unless the trait gives it a default body. Without the method, operator and method dispatch would fail at runtime (e.g. < on an Ord type whose cmp was never implemented).

struct Money { cents: int }

impl core::cmp::Ord for Money { }
//   ^ error[TE825]: incomplete impl of trait `core::cmp::Ord` for `Money`:
//                   missing required method(s) `cmp`

The same applies to a bare trait name and to the compact-struct nested form:

impl Eq for Tag { }
//   ^ error[TE825]: ... missing required method(s) `eq`

struct Money(cents: int) {
  impl core::cmp::Ord { }   // error[TE825]: ... missing required method(s) `cmp`
}

Fix it

Implement every required method of the trait:

impl core::cmp::Ord for Money {
  fn cmp(self, other: Money) -> int {
    if self.cents < other.cents { 0 - 1 } else { self.cents > other.cents && 1 || 0 }
  }
}

Required methods of the common std traits: Ordcmp, Eqeq, Addadd, Subsub, Mulmul, Divdiv, Modmod_, Negneg, Displayto_string, Hashhash.

Notes

  • A trait method with a default body is not required — an empty impl of a default-only trait is complete.
  • Methods marked @native/@plugin, impls inside declaration modules (.d.zolo), and impls in scope of a use plugin …::* glob are exempt (their bodies may be supplied externally).
  • This checks for missing required methods only; extra methods not declared by the trait are not flagged.

See also

See also

Search Zolo

9 results

en