diff options
| author | bors <bors@rust-lang.org> | 2019-08-28 11:11:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-08-28 11:11:43 +0000 |
| commit | a939d61cf7feac0f328aec07f050c4ac96c51d2c (patch) | |
| tree | 2b4db20bf664096cc6d7c7120cdf66d0229f46a8 | |
| parent | f6c752b271cd427e1a0e3c68722ec2c0a34f3016 (diff) | |
| parent | 236666138fa15fdd48b1c12180b2c9dc936441b4 (diff) | |
| download | rust-a939d61cf7feac0f328aec07f050c4ac96c51d2c.tar.gz rust-a939d61cf7feac0f328aec07f050c4ac96c51d2c.zip | |
Auto merge of #4463 - flip1995:rollup-240kr2c, r=flip1995
Rollup of 2 pull requests Successful merges: - #4459 (Add note to avoid confusing) - #4460 (Fix `inherent_to_string` false positive) Failed merges: r? @ghost changelog: none
| -rw-r--r-- | clippy_lints/src/inherent_to_string.rs | 1 | ||||
| -rw-r--r-- | doc/adding_lints.md | 2 | ||||
| -rw-r--r-- | tests/ui/inherent_to_string.rs | 12 | ||||
| -rw-r--r-- | tests/ui/inherent_to_string.stderr | 4 |
4 files changed, 17 insertions, 2 deletions
diff --git a/clippy_lints/src/inherent_to_string.rs b/clippy_lints/src/inherent_to_string.rs index eb29a6d436a..26b9657589f 100644 --- a/clippy_lints/src/inherent_to_string.rs +++ b/clippy_lints/src/inherent_to_string.rs @@ -104,6 +104,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InherentToString { 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); diff --git a/doc/adding_lints.md b/doc/adding_lints.md index c9816911a82..1fb26c66d9f 100644 --- a/doc/adding_lints.md +++ b/doc/adding_lints.md @@ -86,6 +86,8 @@ test. That allows us to check if the output is turning into what we want. Once we are satisfied with the output, we need to run `tests/ui/update-all-references.sh` to update the `.stderr` file for our lint. +Please note that, we should run `TESTNAME=ui/foo_functions cargo uitest` +every time before running `tests/ui/update-all-references.sh`. Running `TESTNAME=ui/foo_functions cargo uitest` should pass then. When we commit our lint, we need to commit the generated `.stderr` files, too. diff --git a/tests/ui/inherent_to_string.rs b/tests/ui/inherent_to_string.rs index fc21b5cbc3f..e6cf337d1bb 100644 --- a/tests/ui/inherent_to_string.rs +++ b/tests/ui/inherent_to_string.rs @@ -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 @@ struct B; struct C; struct D; struct E; +struct F; impl A { // Should be detected; emit warning @@ -64,6 +66,13 @@ impl E { } } +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); } diff --git a/tests/ui/inherent_to_string.stderr b/tests/ui/inherent_to_string.stderr index 5252a168830..76d1bb873eb 100644 --- a/tests/ui/inherent_to_string.stderr +++ b/tests/ui/inherent_to_string.stderr @@ -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() |
