Skip to content

Commit ffb53e7

Browse files
committed
Add run-rustfix to inefficient_to_string
1 parent 106a725 commit ffb53e7

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

tests/ui/inefficient_to_string.fixed

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// run-rustfix
2+
#![deny(clippy::inefficient_to_string)]
3+
4+
use std::borrow::Cow;
5+
use std::string::ToString;
6+
7+
fn main() {
8+
let rstr: &str = "hello";
9+
let rrstr: &&str = &rstr;
10+
let rrrstr: &&&str = &rrstr;
11+
let _: String = rstr.to_string();
12+
let _: String = (*rrstr).to_string();
13+
let _: String = (**rrrstr).to_string();
14+
15+
let string: String = String::from("hello");
16+
let rstring: &String = &string;
17+
let rrstring: &&String = &rstring;
18+
let rrrstring: &&&String = &rrstring;
19+
let _: String = string.to_string();
20+
let _: String = rstring.to_string();
21+
let _: String = (*rrstring).to_string();
22+
let _: String = (**rrrstring).to_string();
23+
24+
let cow: Cow<'_, str> = Cow::Borrowed("hello");
25+
let rcow: &Cow<'_, str> = &cow;
26+
let rrcow: &&Cow<'_, str> = &rcow;
27+
let rrrcow: &&&Cow<'_, str> = &rrcow;
28+
let _: String = cow.to_string();
29+
let _: String = rcow.to_string();
30+
let _: String = (*rrcow).to_string();
31+
let _: String = (**rrrcow).to_string();
32+
}

tests/ui/inefficient_to_string.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// run-rustfix
12
#![deny(clippy::inefficient_to_string)]
23

34
use std::borrow::Cow;

tests/ui/inefficient_to_string.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
error: calling `to_string` on `&&str`
2-
--> $DIR/inefficient_to_string.rs:11:21
2+
--> $DIR/inefficient_to_string.rs:12:21
33
|
44
LL | let _: String = rrstr.to_string();
55
| ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstr).to_string()`
66
|
77
note: lint level defined here
8-
--> $DIR/inefficient_to_string.rs:1:9
8+
--> $DIR/inefficient_to_string.rs:2:9
99
|
1010
LL | #![deny(clippy::inefficient_to_string)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212
= help: `&str` implements `ToString` through the blanket impl, but `str` specializes `ToString` directly
1313

1414
error: calling `to_string` on `&&&str`
15-
--> $DIR/inefficient_to_string.rs:12:21
15+
--> $DIR/inefficient_to_string.rs:13:21
1616
|
1717
LL | let _: String = rrrstr.to_string();
1818
| ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrstr).to_string()`
1919
|
2020
= help: `&&str` implements `ToString` through the blanket impl, but `str` specializes `ToString` directly
2121

2222
error: calling `to_string` on `&&std::string::String`
23-
--> $DIR/inefficient_to_string.rs:20:21
23+
--> $DIR/inefficient_to_string.rs:21:21
2424
|
2525
LL | let _: String = rrstring.to_string();
2626
| ^^^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstring).to_string()`
2727
|
2828
= help: `&std::string::String` implements `ToString` through the blanket impl, but `std::string::String` specializes `ToString` directly
2929

3030
error: calling `to_string` on `&&&std::string::String`
31-
--> $DIR/inefficient_to_string.rs:21:21
31+
--> $DIR/inefficient_to_string.rs:22:21
3232
|
3333
LL | let _: String = rrrstring.to_string();
3434
| ^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrstring).to_string()`
3535
|
3636
= help: `&&std::string::String` implements `ToString` through the blanket impl, but `std::string::String` specializes `ToString` directly
3737

3838
error: calling `to_string` on `&&std::borrow::Cow<'_, str>`
39-
--> $DIR/inefficient_to_string.rs:29:21
39+
--> $DIR/inefficient_to_string.rs:30:21
4040
|
4141
LL | let _: String = rrcow.to_string();
4242
| ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrcow).to_string()`
4343
|
4444
= help: `&std::borrow::Cow<'_, str>` implements `ToString` through the blanket impl, but `std::borrow::Cow<'_, str>` specializes `ToString` directly
4545

4646
error: calling `to_string` on `&&&std::borrow::Cow<'_, str>`
47-
--> $DIR/inefficient_to_string.rs:30:21
47+
--> $DIR/inefficient_to_string.rs:31:21
4848
|
4949
LL | let _: String = rrrcow.to_string();
5050
| ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrcow).to_string()`

0 commit comments

Comments
 (0)