about summary refs log tree commit diff
path: root/src/tools
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-12-15 04:45:24 +0000
committerbors <bors@rust-lang.org>2024-12-15 04:45:24 +0000
commit4790a435cbcb55c94ccdef51bf7a9b2e55824528 (patch)
tree742141865ec8c1b2fe10325b1983c0af7d83ea6b /src/tools
parent7caf35b2e5401d7740fdc567fdc388059208150b (diff)
parent3f3f27bb84b46be8294e27c6a2d64f0c918f3679 (diff)
Auto merge of #134258 - bjorn3:no_public_specialization, r=petrochenkov
Remove support for specializing ToString outside the standard library

This is the only trait specializable outside of the standard library. Before stabilizing specialization we will probably want to remove support for this. It was originally made specializable to allow a more efficient ToString in libproc_macro back when this way the only way to get any data out of a TokenStream. We now support getting individual tokens, so proc macros no longer need to call it as often.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/clippy/clippy_lints/src/to_string_trait_impl.rs3
-rw-r--r--src/tools/clippy/tests/ui/to_string_trait_impl.rs43
-rw-r--r--src/tools/clippy/tests/ui/to_string_trait_impl.stderr14
3 files changed, 1 insertions, 59 deletions
diff --git a/src/tools/clippy/clippy_lints/src/to_string_trait_impl.rs b/src/tools/clippy/clippy_lints/src/to_string_trait_impl.rs
index 0361836cdec..9596b85664b 100644
--- a/src/tools/clippy/clippy_lints/src/to_string_trait_impl.rs
+++ b/src/tools/clippy/clippy_lints/src/to_string_trait_impl.rs
@@ -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;
@@ -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,
diff --git a/src/tools/clippy/tests/ui/to_string_trait_impl.rs b/src/tools/clippy/tests/ui/to_string_trait_impl.rs
index 4c1202d4203..7be9f7994f0 100644
--- a/src/tools/clippy/tests/ui/to_string_trait_impl.rs
+++ b/src/tools/clippy/tests/ui/to_string_trait_impl.rs
@@ -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!()
-        }
-    }
-}
diff --git a/src/tools/clippy/tests/ui/to_string_trait_impl.stderr b/src/tools/clippy/tests/ui/to_string_trait_impl.stderr
index 304c9a5e1fb..fe8afc215f0 100644
--- a/src/tools/clippy/tests/ui/to_string_trait_impl.stderr
+++ b/src/tools/clippy/tests/ui/to_string_trait_impl.stderr
@@ -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