From ffb53e74571f4b179f265b846cfa443e527621fb Mon Sep 17 00:00:00 2001 From: HMPerson1 Date: Thu, 17 Oct 2019 12:41:45 -0400 Subject: [PATCH] Add `run-rustfix` to `inefficient_to_string` --- tests/ui/inefficient_to_string.fixed | 32 +++++++++++++++++++++++++++ tests/ui/inefficient_to_string.rs | 1 + tests/ui/inefficient_to_string.stderr | 14 ++++++------ 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 tests/ui/inefficient_to_string.fixed diff --git a/tests/ui/inefficient_to_string.fixed b/tests/ui/inefficient_to_string.fixed new file mode 100644 index 000000000..32bc7574a --- /dev/null +++ b/tests/ui/inefficient_to_string.fixed @@ -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(); +} diff --git a/tests/ui/inefficient_to_string.rs b/tests/ui/inefficient_to_string.rs index a9f8f244c..2741565e5 100644 --- a/tests/ui/inefficient_to_string.rs +++ b/tests/ui/inefficient_to_string.rs @@ -1,3 +1,4 @@ +// run-rustfix #![deny(clippy::inefficient_to_string)] use std::borrow::Cow; diff --git a/tests/ui/inefficient_to_string.stderr b/tests/ui/inefficient_to_string.stderr index 70e3c1e82..3c2f64c80 100644 --- a/tests/ui/inefficient_to_string.stderr +++ b/tests/ui/inefficient_to_string.stderr @@ -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()`