Skip to content

Commit

Permalink
Stop handling specialization in clippy's to_string_trait_impl lint
Browse files Browse the repository at this point in the history
ToString can no longer be specialized, so no need to account for it in
to_string_trait_impl either.
  • Loading branch information
bjorn3 committed Dec 14, 2024
1 parent f7b1403 commit af94847
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 46 deletions.
3 changes: 0 additions & 3 deletions src/tools/clippy/clippy_lints/src/to_string_trait_impl.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::ty::implements_trait;
use rustc_hir::{Impl, Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass;
Expand Down Expand Up @@ -54,8 +53,6 @@ impl<'tcx> LateLintPass<'tcx> for ToStringTraitImpl {
}) = it.kind
&& let Some(trait_did) = trait_ref.trait_def_id()
&& cx.tcx.is_diagnostic_item(sym::ToString, trait_did)
&& let Some(display_did) = cx.tcx.get_diagnostic_item(sym::Display)
&& !implements_trait(cx, cx.tcx.type_of(it.owner_id).instantiate_identity(), display_did, &[])
{
span_lint_and_help(
cx,
Expand Down
43 changes: 0 additions & 43 deletions src/tools/clippy/tests/ui/to_string_trait_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!()
}
}
}

0 comments on commit af94847

Please sign in to comment.