File tree 2 files changed +7
-17
lines changed 2 files changed +7
-17
lines changed Original file line number Diff line number Diff line change 1
1
#![ warn( clippy:: to_string_in_display) ]
2
+ #![ deny( clippy:: inherent_to_string_shadow_display) ]
2
3
3
4
use std:: fmt;
4
5
@@ -29,11 +30,11 @@ fn fmt(a: A) {
29
30
a. to_string ( ) ;
30
31
}
31
32
32
- pub struct C ;
33
+ struct C ;
33
34
34
35
impl C {
35
- pub fn to_string ( & self ) -> String {
36
- "I am C" . to_string ( )
36
+ fn to_string ( & self ) -> & str {
37
+ "I am C"
37
38
}
38
39
}
39
40
Original file line number Diff line number Diff line change 1
1
error: Using to_string in fmt::Display implementation might lead to infinite recursion
2
- --> $DIR/to_string_in_display.rs:24 :25
2
+ --> $DIR/to_string_in_display.rs:25 :25
3
3
|
4
4
LL | write!(f, "{}", self.to_string())
5
5
| ^^^^^^^^^^^^^^^^
6
6
|
7
7
= note: `-D clippy::to-string-in-display` implied by `-D warnings`
8
8
9
- error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`
10
- --> $DIR/to_string_in_display.rs:35:5
11
- |
12
- LL | / pub fn to_string(&self) -> String {
13
- LL | | "I am C".to_string()
14
- LL | | }
15
- | |_____^
16
- |
17
- = note: `#[deny(clippy::inherent_to_string_shadow_display)]` on by default
18
- = help: remove the inherent method from type `C`
19
-
20
9
error: Using to_string in fmt::Display implementation might lead to infinite recursion
21
- --> $DIR/to_string_in_display.rs:42 :25
10
+ --> $DIR/to_string_in_display.rs:43 :25
22
11
|
23
12
LL | write!(f, "{}", self.to_string())
24
13
| ^^^^^^^^^^^^^^^^
25
14
26
- error: aborting due to 3 previous errors
15
+ error: aborting due to 2 previous errors
27
16
You can’t perform that action at this time.
0 commit comments