2024-02-08 13:24:42 -06:00
|
|
|
#![warn(clippy::to_string_trait_impl)]
|
2024-02-27 08:25:18 -06:00
|
|
|
#![feature(min_specialization)]
|
2024-02-08 13:24:42 -06:00
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
}
|
2024-02-27 08:25:18 -06:00
|
|
|
|
|
|
|
mod issue12263 {
|
|
|
|
pub struct MyStringWrapper<'a>(&'a str);
|
|
|
|
|
|
|
|
impl std::fmt::Display for MyStringWrapper<'_> {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
self.0.fmt(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToString for MyStringWrapper<'_> {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
self.0.to_string()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct S<T>(T);
|
|
|
|
impl std::fmt::Display for S<String> {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// no specialization if the generics differ, so lint
|
|
|
|
impl ToString for S<i32> {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct S2<T>(T);
|
|
|
|
impl std::fmt::Display for S2<String> {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// also specialization if the generics don't differ
|
|
|
|
impl ToString for S2<String> {
|
|
|
|
fn to_string(&self) -> String {
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|