Skip to content

Commit 24b3a63

Browse files
committed
add test for &str
1 parent 9fb7405 commit 24b3a63

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

tests/ui/str_to_string.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![warn(clippy::str_to_string)]
22

33
fn main() {
4-
let _ = "hello world".to_string();
4+
let hello = "hello world".to_string();
5+
let msg = &hello[..];
6+
msg.to_string();
57
}

tests/ui/str_to_string.stderr

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
error: `to_string()` does a multitude of things to just clone a `&str`
2-
--> $DIR/str_to_string.rs:4:13
2+
--> $DIR/str_to_string.rs:4:17
33
|
4-
LL | let _ = "hello world".to_string();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | let hello = "hello world".to_string();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::str-to-string` implied by `-D warnings`
88
= help: consider using `.to_owned()`
99

10-
error: aborting due to previous error
10+
error: `to_string()` does a multitude of things to just clone a `&str`
11+
--> $DIR/str_to_string.rs:6:5
12+
|
13+
LL | msg.to_string();
14+
| ^^^^^^^^^^^^^^^
15+
|
16+
= help: consider using `.to_owned()`
17+
18+
error: aborting due to 2 previous errors
1119

0 commit comments

Comments
 (0)