if impl_item.ident.name.as_str() == "to_string";
let decl = &signature.decl;
if decl.implicit_self.has_implicit_self();
+ if decl.inputs.len() == 1;
// Check if return type is String
if match_type(cx, return_ty(cx, impl_item.hir_id), &paths::STRING);
#![warn(clippy::inherent_to_string)]
#![deny(clippy::inherent_to_string_shadow_display)]
+#![allow(clippy::many_single_char_names)]
use std::fmt;
struct C;
struct D;
struct E;
+struct F;
impl A {
// Should be detected; emit warning
}
}
+impl F {
+ // Should not be detected, as it does not match the function signature
+ fn to_string(&self, _i: i32) -> String {
+ "F.to_string()".to_string()
+ }
+}
+
fn main() {
let a = A;
a.to_string();
d.to_string();
E::to_string();
+
+ let f = F;
+ f.to_string(1);
}
error: implementation of inherent method `to_string(&self) -> String` for type `A`
- --> $DIR/inherent_to_string.rs:18:5
+ --> $DIR/inherent_to_string.rs:20:5
|
LL | / fn to_string(&self) -> String {
LL | | "A.to_string()".to_string()
= help: implement trait `Display` for type `A` instead
error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`
- --> $DIR/inherent_to_string.rs:42:5
+ --> $DIR/inherent_to_string.rs:44:5
|
LL | / fn to_string(&self) -> String {
LL | | "C.to_string()".to_string()