Skip to content

Commit

Permalink
add test for &str
Browse files Browse the repository at this point in the history
  • Loading branch information
PunitLodha committed Nov 25, 2020
1 parent 739124c commit 9e0fdb4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion tests/ui/str_to_string.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(clippy::str_to_string)]

fn main() {
let _ = "hello world".to_string();
let hello = "hello world".to_string();
let msg = &hello[..];
msg.to_string();
}
16 changes: 12 additions & 4 deletions tests/ui/str_to_string.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
error: `to_string()` does a multitude of things to just clone a `&str`
--> $DIR/str_to_string.rs:4:13
--> $DIR/str_to_string.rs:4:17
|
LL | let _ = "hello world".to_string();
| ^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let hello = "hello world".to_string();
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::str-to-string` implied by `-D warnings`
= help: consider using `.to_owned()`

error: aborting due to previous error
error: `to_string()` does a multitude of things to just clone a `&str`
--> $DIR/str_to_string.rs:6:5
|
LL | msg.to_string();
| ^^^^^^^^^^^^^^^
|
= help: consider using `.to_owned()`

error: aborting due to 2 previous errors

0 comments on commit 9e0fdb4

Please sign in to comment.