about summary refs log tree commit diff
path: root/tests/ui/to_string_trait_impl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/to_string_trait_impl.rs')
-rw-r--r--tests/ui/to_string_trait_impl.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/ui/to_string_trait_impl.rs b/tests/ui/to_string_trait_impl.rs
new file mode 100644
index 00000000000..b0731632d45
--- /dev/null
+++ b/tests/ui/to_string_trait_impl.rs
@@ -0,0 +1,31 @@
+#![warn(clippy::to_string_trait_impl)]
+
+use std::fmt::{self, Display};
+
+struct Point {
+    x: usize,
+    y: usize,
+}
+
+impl ToString for Point {
+    fn to_string(&self) -> String {
+        format!("({}, {})", self.x, self.y)
+    }
+}
+
+struct Foo;
+
+impl Display for Foo {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        write!(f, "Foo")
+    }
+}
+
+struct Bar;
+
+impl Bar {
+    #[allow(clippy::inherent_to_string)]
+    fn to_string(&self) -> String {
+        String::from("Bar")
+    }
+}