]> git.lizzy.rs Git - rust.git/commitdiff
Fix `inherent_to_string` false positive
authorYuki Okushi <huyuumi.dev@gmail.com>
Tue, 27 Aug 2019 19:23:26 +0000 (04:23 +0900)
committerYuki Okushi <huyuumi.dev@gmail.com>
Tue, 27 Aug 2019 21:46:26 +0000 (06:46 +0900)
clippy_lints/src/inherent_to_string.rs
tests/ui/inherent_to_string.rs
tests/ui/inherent_to_string.stderr

index eb29a6d436ab098c35db531fb07668403afab5d3..26b9657589f38eee3870d25162190ee7fda6e6ea 100644 (file)
@@ -104,6 +104,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, impl_item: &'tcx ImplI
             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);
index fc21b5cbc3f10b9f887f1624c48444d6c11831c2..e6cf337d1bb1baa932b13f3665cdc8d7764395ee 100644 (file)
@@ -1,5 +1,6 @@
 #![warn(clippy::inherent_to_string)]
 #![deny(clippy::inherent_to_string_shadow_display)]
+#![allow(clippy::many_single_char_names)]
 
 use std::fmt;
 
@@ -12,6 +13,7 @@ trait FalsePositive {
 struct C;
 struct D;
 struct E;
+struct F;
 
 impl A {
     // Should be detected; emit warning
@@ -64,6 +66,13 @@ fn to_string() -> String {
     }
 }
 
+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();
@@ -81,4 +90,7 @@ fn main() {
     d.to_string();
 
     E::to_string();
+
+    let f = F;
+    f.to_string(1);
 }
index 5252a168830a418ec706895176f4ace48eef8ad5..76d1bb873ebebd18fdd909324a71e1d49ccdf65d 100644 (file)
@@ -1,5 +1,5 @@
 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()
@@ -10,7 +10,7 @@ LL | |     }
    = 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()