Skip to content

Commit 6c1daec

Browse files
author
chansuke
committed
Allow inherent_to_string_shadow_display for testing
1 parent 13c6bb4 commit 6c1daec

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

tests/ui/to_string_in_display.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![warn(clippy::to_string_in_display)]
2+
#![deny(clippy::inherent_to_string_shadow_display)]
23

34
use std::fmt;
45

@@ -29,11 +30,11 @@ fn fmt(a: A) {
2930
a.to_string();
3031
}
3132

32-
pub struct C;
33+
struct C;
3334

3435
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"
3738
}
3839
}
3940

tests/ui/to_string_in_display.stderr

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,16 @@
11
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
33
|
44
LL | write!(f, "{}", self.to_string())
55
| ^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::to-string-in-display` implied by `-D warnings`
88

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-
209
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
2211
|
2312
LL | write!(f, "{}", self.to_string())
2413
| ^^^^^^^^^^^^^^^^
2514

26-
error: aborting due to 3 previous errors
15+
error: aborting due to 2 previous errors
2716

0 commit comments

Comments
 (0)