Skip to content

Commit 3f3f27b

Browse files
committed
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.
1 parent f7b1403 commit 3f3f27b

File tree

3 files changed

+1
-59
lines changed

3 files changed

+1
-59
lines changed

src/tools/clippy/clippy_lints/src/to_string_trait_impl.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::ty::implements_trait;
32
use rustc_hir::{Impl, Item, ItemKind};
43
use rustc_lint::{LateContext, LateLintPass};
54
use rustc_session::declare_lint_pass;
@@ -54,8 +53,6 @@ impl<'tcx> LateLintPass<'tcx> for ToStringTraitImpl {
5453
}) = it.kind
5554
&& let Some(trait_did) = trait_ref.trait_def_id()
5655
&& cx.tcx.is_diagnostic_item(sym::ToString, trait_did)
57-
&& let Some(display_did) = cx.tcx.get_diagnostic_item(sym::Display)
58-
&& !implements_trait(cx, cx.tcx.type_of(it.owner_id).instantiate_identity(), display_did, &[])
5956
{
6057
span_lint_and_help(
6158
cx,

src/tools/clippy/tests/ui/to_string_trait_impl.rs

-43
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,3 @@ impl Bar {
3030
String::from("Bar")
3131
}
3232
}
33-
34-
mod issue12263 {
35-
pub struct MyStringWrapper<'a>(&'a str);
36-
37-
impl std::fmt::Display for MyStringWrapper<'_> {
38-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39-
self.0.fmt(f)
40-
}
41-
}
42-
43-
impl ToString for MyStringWrapper<'_> {
44-
fn to_string(&self) -> String {
45-
self.0.to_string()
46-
}
47-
}
48-
49-
pub struct S<T>(T);
50-
impl std::fmt::Display for S<String> {
51-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52-
todo!()
53-
}
54-
}
55-
// no specialization if the generics differ, so lint
56-
impl ToString for S<i32> {
57-
fn to_string(&self) -> String {
58-
todo!()
59-
}
60-
}
61-
62-
pub struct S2<T>(T);
63-
impl std::fmt::Display for S2<String> {
64-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65-
todo!()
66-
}
67-
}
68-
69-
// also specialization if the generics don't differ
70-
impl ToString for S2<String> {
71-
fn to_string(&self) -> String {
72-
todo!()
73-
}
74-
}
75-
}

src/tools/clippy/tests/ui/to_string_trait_impl.stderr

+1-13
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,5 @@ LL | | }
1212
= note: `-D clippy::to-string-trait-impl` implied by `-D warnings`
1313
= help: to override `-D warnings` add `#[allow(clippy::to_string_trait_impl)]`
1414

15-
error: direct implementation of `ToString`
16-
--> tests/ui/to_string_trait_impl.rs:56:5
17-
|
18-
LL | / impl ToString for S<i32> {
19-
LL | | fn to_string(&self) -> String {
20-
LL | | todo!()
21-
LL | | }
22-
LL | | }
23-
| |_____^
24-
|
25-
= help: prefer implementing `Display` instead
26-
27-
error: aborting due to 2 previous errors
15+
error: aborting due to 1 previous error
2816

0 commit comments

Comments
 (0)