RS.CLIPPY.TO_STRING_TRAIT_IMPL

Check for direct implementations of `ToString`

This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: to_string_trait_impl. Copyright ©2025 The Rust Team. All rights reserved.

What it does

Checks for direct implementations of ToString.

Why is this bad?

This trait is automatically implemented for any type which implements the Display trait. As such, ToString shouldn't be implemented directly: Display should be implemented instead, and you get the ToString implementation for free.

Example

struct Point {
  x: usize,
  y: usize,
}

impl ToString for Point {
  fn to_string(&self) -> String {
    format!("({}, {})", self.x, self.y)
  }
}

Use instead:

struct Point {
  x: usize,
  y: usize,
}

impl std::fmt::Display for Point {
  fn fmt(&self, f: &mut std::fmt::Formatter<\'_>) -> std::fmt::Result {
    write!(f, "({}, {})", self.x, self.y)
  }
}