mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
Add run-rustfix
to inefficient_to_string
This commit is contained in:
parent
106a72592c
commit
ffb53e7457
3 changed files with 40 additions and 7 deletions
32
tests/ui/inefficient_to_string.fixed
Normal file
32
tests/ui/inefficient_to_string.fixed
Normal file
|
@ -0,0 +1,32 @@
|
|||
// run-rustfix
|
||||
#![deny(clippy::inefficient_to_string)]
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::string::ToString;
|
||||
|
||||
fn main() {
|
||||
let rstr: &str = "hello";
|
||||
let rrstr: &&str = &rstr;
|
||||
let rrrstr: &&&str = &rrstr;
|
||||
let _: String = rstr.to_string();
|
||||
let _: String = (*rrstr).to_string();
|
||||
let _: String = (**rrrstr).to_string();
|
||||
|
||||
let string: String = String::from("hello");
|
||||
let rstring: &String = &string;
|
||||
let rrstring: &&String = &rstring;
|
||||
let rrrstring: &&&String = &rrstring;
|
||||
let _: String = string.to_string();
|
||||
let _: String = rstring.to_string();
|
||||
let _: String = (*rrstring).to_string();
|
||||
let _: String = (**rrrstring).to_string();
|
||||
|
||||
let cow: Cow<'_, str> = Cow::Borrowed("hello");
|
||||
let rcow: &Cow<'_, str> = &cow;
|
||||
let rrcow: &&Cow<'_, str> = &rcow;
|
||||
let rrrcow: &&&Cow<'_, str> = &rrcow;
|
||||
let _: String = cow.to_string();
|
||||
let _: String = rcow.to_string();
|
||||
let _: String = (*rrcow).to_string();
|
||||
let _: String = (**rrrcow).to_string();
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
// run-rustfix
|
||||
#![deny(clippy::inefficient_to_string)]
|
||||
|
||||
use std::borrow::Cow;
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
error: calling `to_string` on `&&str`
|
||||
--> $DIR/inefficient_to_string.rs:11:21
|
||||
--> $DIR/inefficient_to_string.rs:12:21
|
||||
|
|
||||
LL | let _: String = rrstr.to_string();
|
||||
| ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstr).to_string()`
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/inefficient_to_string.rs:1:9
|
||||
--> $DIR/inefficient_to_string.rs:2:9
|
||||
|
|
||||
LL | #![deny(clippy::inefficient_to_string)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= help: `&str` implements `ToString` through the blanket impl, but `str` specializes `ToString` directly
|
||||
|
||||
error: calling `to_string` on `&&&str`
|
||||
--> $DIR/inefficient_to_string.rs:12:21
|
||||
--> $DIR/inefficient_to_string.rs:13:21
|
||||
|
|
||||
LL | let _: String = rrrstr.to_string();
|
||||
| ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrstr).to_string()`
|
||||
|
@ -20,7 +20,7 @@ LL | let _: String = rrrstr.to_string();
|
|||
= help: `&&str` implements `ToString` through the blanket impl, but `str` specializes `ToString` directly
|
||||
|
||||
error: calling `to_string` on `&&std::string::String`
|
||||
--> $DIR/inefficient_to_string.rs:20:21
|
||||
--> $DIR/inefficient_to_string.rs:21:21
|
||||
|
|
||||
LL | let _: String = rrstring.to_string();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrstring).to_string()`
|
||||
|
@ -28,7 +28,7 @@ LL | let _: String = rrstring.to_string();
|
|||
= help: `&std::string::String` implements `ToString` through the blanket impl, but `std::string::String` specializes `ToString` directly
|
||||
|
||||
error: calling `to_string` on `&&&std::string::String`
|
||||
--> $DIR/inefficient_to_string.rs:21:21
|
||||
--> $DIR/inefficient_to_string.rs:22:21
|
||||
|
|
||||
LL | let _: String = rrrstring.to_string();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrstring).to_string()`
|
||||
|
@ -36,7 +36,7 @@ LL | let _: String = rrrstring.to_string();
|
|||
= help: `&&std::string::String` implements `ToString` through the blanket impl, but `std::string::String` specializes `ToString` directly
|
||||
|
||||
error: calling `to_string` on `&&std::borrow::Cow<'_, str>`
|
||||
--> $DIR/inefficient_to_string.rs:29:21
|
||||
--> $DIR/inefficient_to_string.rs:30:21
|
||||
|
|
||||
LL | let _: String = rrcow.to_string();
|
||||
| ^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(*rrcow).to_string()`
|
||||
|
@ -44,7 +44,7 @@ LL | let _: String = rrcow.to_string();
|
|||
= help: `&std::borrow::Cow<'_, str>` implements `ToString` through the blanket impl, but `std::borrow::Cow<'_, str>` specializes `ToString` directly
|
||||
|
||||
error: calling `to_string` on `&&&std::borrow::Cow<'_, str>`
|
||||
--> $DIR/inefficient_to_string.rs:30:21
|
||||
--> $DIR/inefficient_to_string.rs:31:21
|
||||
|
|
||||
LL | let _: String = rrrcow.to_string();
|
||||
| ^^^^^^^^^^^^^^^^^^ help: try dereferencing the receiver: `(**rrrcow).to_string()`
|
||||
|
|
Loading…
Reference in a new issue