Stop handling specialization in clippy's to_string_trait_impl lint

ToString can no longer be specialized, so no need to account for it in
to_string_trait_impl either.
This commit is contained in:
bjorn3 2024-12-14 14:53:11 +00:00
parent f495cec548
commit bc410fc9f5
3 changed files with 1 additions and 59 deletions

View file

@ -30,46 +30,3 @@ impl Bar {
String::from("Bar")
}
}
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!()
}
}
}

View file

@ -12,17 +12,5 @@ LL | | }
= note: `-D clippy::to-string-trait-impl` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::to_string_trait_impl)]`
error: direct implementation of `ToString`
--> tests/ui/to_string_trait_impl.rs:56:5
|
LL | / impl ToString for S<i32> {
LL | | fn to_string(&self) -> String {
LL | | todo!()
LL | | }
LL | | }
| |_____^
|
= help: prefer implementing `Display` instead
error: aborting due to 2 previous errors
error: aborting due to 1 previous error