Skip to content

Commit f0dc979

Browse files
Darth-Revanflip1995
authored andcommitted
Corrections for PR review.
1 parent 0513202 commit f0dc979

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

clippy_lints/src/inherent_to_string.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ declare_clippy_lint! {
1717
///
1818
/// ** Example:**
1919
///
20-
/// ```rust,ignore
20+
/// ```rust
2121
/// // Bad
2222
/// pub struct A;
2323
///
@@ -26,6 +26,9 @@ declare_clippy_lint! {
2626
/// "I am A".to_string()
2727
/// }
2828
/// }
29+
/// ```
30+
///
31+
/// ```rust
2932
/// // Good
3033
/// use std::fmt;
3134
///
@@ -39,19 +42,19 @@ declare_clippy_lint! {
3942
/// ```
4043
pub INHERENT_TO_STRING,
4144
style,
42-
"type implements inherent method 'to_string()', but should instead implement the 'Display' trait"
45+
"type implements inherent method `to_string()`, but should instead implement the `Display` trait"
4346
}
4447

4548
declare_clippy_lint! {
4649
/// **What id does:** Checks for the definition of inherent methods with a signature of `to_string(&self) -> String` and if the type implementing this method also implements the `Display` trait.
4750
///
48-
/// **Why is this bad?** This method is also implicitly defined if a type implements the 'Display' trait. The less versatile inherent method will then shadow the implementation introduced by `Display`.
51+
/// **Why is this bad?** This method is also implicitly defined if a type implements the `Display` trait. The less versatile inherent method will then shadow the implementation introduced by `Display`.
4952
///
50-
/// **Known problems:** The inherent method will shadow the implementation by `Display`. If they behave differently, this may lead to confusing situations for users of the respective type.
53+
/// **Known problems:** None
5154
///
5255
/// ** Example:**
5356
///
54-
/// ```rust,ignore
57+
/// ```rust
5558
/// // Bad
5659
/// use std::fmt;
5760
///
@@ -68,6 +71,9 @@ declare_clippy_lint! {
6871
/// write!(f, "I am A, too")
6972
/// }
7073
/// }
74+
/// ```
75+
///
76+
/// ```rust
7177
/// // Good
7278
/// use std::fmt;
7379
///
@@ -81,7 +87,7 @@ declare_clippy_lint! {
8187
/// ```
8288
pub INHERENT_TO_STRING_SHADOW_DISPLAY,
8389
correctness,
84-
"type implements inherent method 'to_string()', which gets shadowed by the implementation of the 'Display' trait "
90+
"type implements inherent method `to_string()`, which gets shadowed by the implementation of the `Display` trait "
8591
}
8692

8793
declare_lint_pass!(InherentToString => [INHERENT_TO_STRING, INHERENT_TO_STRING_SHADOW_DISPLAY]);
@@ -114,7 +120,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InherentToString {
114120

115121
fn show_lint(cx: &LateContext<'_, '_>, item: &ImplItem) {
116122
let display_trait_id =
117-
get_trait_def_id(cx, &["core", "fmt", "Display"]).expect("Failed to get trait ID of 'Display'!");
123+
get_trait_def_id(cx, &["core", "fmt", "Display"]).expect("Failed to get trait ID of `Display`!");
118124

119125
// Get the real type of 'self'
120126
let fn_def_id = cx.tcx.hir().local_def_id(item.hir_id);
@@ -128,21 +134,21 @@ fn show_lint(cx: &LateContext<'_, '_>, item: &ImplItem) {
128134
INHERENT_TO_STRING_SHADOW_DISPLAY,
129135
item.span,
130136
&format!(
131-
"type '{}' implements inherent method 'to_string() -> String' which shadows the implementation of 'Display'",
137+
"type `{}` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`",
132138
self_type.to_string()
133139
),
134-
&format!("remove the inherent method from type '{}'", self_type.to_string())
140+
&format!("remove the inherent method from type `{}`", self_type.to_string())
135141
);
136142
} else {
137143
span_help_and_lint(
138144
cx,
139145
INHERENT_TO_STRING,
140146
item.span,
141147
&format!(
142-
"implementation of inherent method 'to_string() -> String' for type '{}'",
148+
"implementation of inherent method `to_string(&self) -> String` for type `{}`",
143149
self_type.to_string()
144150
),
145-
&format!("implement trait 'Display' for type '{}' instead", self_type.to_string()),
151+
&format!("implement trait `Display` for type `{}` instead", self_type.to_string()),
146152
);
147153
}
148154
}

tests/ui/inherent_to_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![warn(clippy::inherent_to_string)]
2-
//#![deny(clippy::inherent_to_string_shadow)]
2+
#![deny(clippy::inherent_to_string_shadow)]
33

44
use std::fmt;
55

tests/ui/inherent_to_string.stderr

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: implementation of inherent method 'to_string() -> String' for type 'A'
1+
error: implementation of inherent method `to_string(&self) -> String` for type `A`
22
--> $DIR/inherent_to_string.rs:18:5
33
|
44
LL | / fn to_string(&self) -> String {
@@ -7,9 +7,9 @@ LL | | }
77
| |_____^
88
|
99
= note: `-D clippy::inherent-to-string` implied by `-D warnings`
10-
= help: implement trait 'Display' for type 'A' instead
10+
= help: implement trait `Display` for type `A` instead
1111

12-
error: type 'C' implements inherent method 'to_string() -> String' which shadows the implementation of 'Display'
12+
error: type `C` implements inherent method `to_string(&self) -> String` which shadows the implementation of `Display`
1313
--> $DIR/inherent_to_string.rs:42:5
1414
|
1515
LL | / fn to_string(&self) -> String {
@@ -18,7 +18,15 @@ LL | | }
1818
| |_____^
1919
|
2020
= note: #[deny(clippy::inherent_to_string_shadow_display)] on by default
21-
= help: remove the inherent method from type 'C'
21+
= help: remove the inherent method from type `C`
2222

23-
error: aborting due to 2 previous errors
23+
error: unknown clippy lint: clippy::inherent_to_string_shadow
24+
--> $DIR/inherent_to_string.rs:2:9
25+
|
26+
LL | #![deny(clippy::inherent_to_string_shadow)]
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
|
29+
= note: `-D clippy::unknown-clippy-lints` implied by `-D warnings`
30+
31+
error: aborting due to 3 previous errors
2432

0 commit comments

Comments
 (0)