Skip to content

Commit a939d61

Browse files
committed
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
2 parents f6c752b + 2366661 commit a939d61

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

clippy_lints/src/inherent_to_string.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InherentToString {
104104
if impl_item.ident.name.as_str() == "to_string";
105105
let decl = &signature.decl;
106106
if decl.implicit_self.has_implicit_self();
107+
if decl.inputs.len() == 1;
107108

108109
// Check if return type is String
109110
if match_type(cx, return_ty(cx, impl_item.hir_id), &paths::STRING);

doc/adding_lints.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ test. That allows us to check if the output is turning into what we want.
8686

8787
Once we are satisfied with the output, we need to run
8888
`tests/ui/update-all-references.sh` to update the `.stderr` file for our lint.
89+
Please note that, we should run `TESTNAME=ui/foo_functions cargo uitest`
90+
every time before running `tests/ui/update-all-references.sh`.
8991
Running `TESTNAME=ui/foo_functions cargo uitest` should pass then. When we
9092
commit our lint, we need to commit the generated `.stderr` files, too.
9193

tests/ui/inherent_to_string.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(clippy::inherent_to_string)]
22
#![deny(clippy::inherent_to_string_shadow_display)]
3+
#![allow(clippy::many_single_char_names)]
34

45
use std::fmt;
56

@@ -12,6 +13,7 @@ struct B;
1213
struct C;
1314
struct D;
1415
struct E;
16+
struct F;
1517

1618
impl A {
1719
// Should be detected; emit warning
@@ -64,6 +66,13 @@ impl E {
6466
}
6567
}
6668

69+
impl F {
70+
// Should not be detected, as it does not match the function signature
71+
fn to_string(&self, _i: i32) -> String {
72+
"F.to_string()".to_string()
73+
}
74+
}
75+
6776
fn main() {
6877
let a = A;
6978
a.to_string();
@@ -81,4 +90,7 @@ fn main() {
8190
d.to_string();
8291

8392
E::to_string();
93+
94+
let f = F;
95+
f.to_string(1);
8496
}

tests/ui/inherent_to_string.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: implementation of inherent method `to_string(&self) -> String` for type `A`
2-
--> $DIR/inherent_to_string.rs:18:5
2+
--> $DIR/inherent_to_string.rs:20:5
33
|
44
LL | / fn to_string(&self) -> String {
55
LL | | "A.to_string()".to_string()
@@ -10,7 +10,7 @@ LL | | }
1010
= help: implement trait `Display` for type `A` instead
1111

1212
error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`
13-
--> $DIR/inherent_to_string.rs:42:5
13+
--> $DIR/inherent_to_string.rs:44:5
1414
|
1515
LL | / fn to_string(&self) -> String {
1616
LL | | "C.to_string()".to_string()

0 commit comments

Comments
 (0)