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 24, 2020
1 parent 9fb7405 commit 24b3a63
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 24b3a63

Please sign in to comment.