about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhumannum14916 <humannum14916@gmail.com>2024-03-20 14:07:53 -0400
committerhumannum14916 <humannum14916@gmail.com>2024-03-20 14:07:53 -0400
commitdb7c9feaa00dcc5adcbf6d345ddcfa54bcf3debf (patch)
treee57143387fde715bfec3bf8282fe24858c2bb21f
parent5f7b3c5eea02b697a0a45ba969b7b42b10aed528 (diff)
downloadrust-db7c9feaa00dcc5adcbf6d345ddcfa54bcf3debf.tar.gz
rust-db7c9feaa00dcc5adcbf6d345ddcfa54bcf3debf.zip
Add UI test for new MSRV check
-rw-r--r--tests/ui/assigning_clones.fixed10
-rw-r--r--tests/ui/assigning_clones.rs10
-rw-r--r--tests/ui/assigning_clones.stderr32
3 files changed, 34 insertions, 18 deletions
diff --git a/tests/ui/assigning_clones.fixed b/tests/ui/assigning_clones.fixed
index 771c7f6f56a..160f3b94663 100644
--- a/tests/ui/assigning_clones.fixed
+++ b/tests/ui/assigning_clones.fixed
@@ -129,14 +129,16 @@ fn ignore_generic_clone<T: Clone>(a: &mut T, b: &T) {
 }
 
 #[clippy::msrv = "1.62"]
-fn msrv_1_62(mut a: String, b: &str) {
+fn msrv_1_62(mut a: String, b: String, c: &str) {
+    a.clone_from(&b);
     // Should not be linted, as clone_into wasn't stabilized until 1.63
-    a = b.to_owned();
+    a = c.to_owned();
 }
 
 #[clippy::msrv = "1.63"]
-fn msrv_1_63(mut a: String, b: &str) {
-    b.clone_into(&mut a);
+fn msrv_1_63(mut a: String, b: String, c: &str) {
+    a.clone_from(&b);
+    c.clone_into(&mut a);
 }
 
 macro_rules! clone_inside {
diff --git a/tests/ui/assigning_clones.rs b/tests/ui/assigning_clones.rs
index 1320481322f..14ba1d4db9a 100644
--- a/tests/ui/assigning_clones.rs
+++ b/tests/ui/assigning_clones.rs
@@ -129,14 +129,16 @@ fn ignore_generic_clone<T: Clone>(a: &mut T, b: &T) {
 }
 
 #[clippy::msrv = "1.62"]
-fn msrv_1_62(mut a: String, b: &str) {
+fn msrv_1_62(mut a: String, b: String, c: &str) {
+    a = b.clone();
     // Should not be linted, as clone_into wasn't stabilized until 1.63
-    a = b.to_owned();
+    a = c.to_owned();
 }
 
 #[clippy::msrv = "1.63"]
-fn msrv_1_63(mut a: String, b: &str) {
-    a = b.to_owned();
+fn msrv_1_63(mut a: String, b: String, c: &str) {
+    a = b.clone();
+    a = c.to_owned();
 }
 
 macro_rules! clone_inside {
diff --git a/tests/ui/assigning_clones.stderr b/tests/ui/assigning_clones.stderr
index b8e20cee160..ba59f067431 100644
--- a/tests/ui/assigning_clones.stderr
+++ b/tests/ui/assigning_clones.stderr
@@ -67,47 +67,59 @@ error: assigning the result of `Clone::clone()` may be inefficient
 LL |         a = b.clone();
    |         ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)`
 
+error: assigning the result of `Clone::clone()` may be inefficient
+  --> tests/ui/assigning_clones.rs:133:5
+   |
+LL |     a = b.clone();
+   |     ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)`
+
+error: assigning the result of `Clone::clone()` may be inefficient
+  --> tests/ui/assigning_clones.rs:140:5
+   |
+LL |     a = b.clone();
+   |     ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)`
+
 error: assigning the result of `ToOwned::to_owned()` may be inefficient
-  --> tests/ui/assigning_clones.rs:139:5
+  --> tests/ui/assigning_clones.rs:141:5
    |
-LL |     a = b.to_owned();
-   |     ^^^^^^^^^^^^^^^^ help: use `clone_into()`: `b.clone_into(&mut a)`
+LL |     a = c.to_owned();
+   |     ^^^^^^^^^^^^^^^^ help: use `clone_into()`: `c.clone_into(&mut a)`
 
 error: assigning the result of `ToOwned::to_owned()` may be inefficient
-  --> tests/ui/assigning_clones.rs:156:5
+  --> tests/ui/assigning_clones.rs:158:5
    |
 LL |     *mut_string = ref_str.to_owned();
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(mut_string)`
 
 error: assigning the result of `ToOwned::to_owned()` may be inefficient
-  --> tests/ui/assigning_clones.rs:160:5
+  --> tests/ui/assigning_clones.rs:162:5
    |
 LL |     mut_string = ref_str.to_owned();
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut mut_string)`
 
 error: assigning the result of `ToOwned::to_owned()` may be inefficient
-  --> tests/ui/assigning_clones.rs:181:5
+  --> tests/ui/assigning_clones.rs:183:5
    |
 LL |     **mut_box_string = ref_str.to_owned();
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))`
 
 error: assigning the result of `ToOwned::to_owned()` may be inefficient
-  --> tests/ui/assigning_clones.rs:185:5
+  --> tests/ui/assigning_clones.rs:187:5
    |
 LL |     **mut_box_string = ref_str.to_owned();
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))`
 
 error: assigning the result of `ToOwned::to_owned()` may be inefficient
-  --> tests/ui/assigning_clones.rs:189:5
+  --> tests/ui/assigning_clones.rs:191:5
    |
 LL |     *mut_thing = ToOwned::to_owned(ref_str);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, mut_thing)`
 
 error: assigning the result of `ToOwned::to_owned()` may be inefficient
-  --> tests/ui/assigning_clones.rs:193:5
+  --> tests/ui/assigning_clones.rs:195:5
    |
 LL |     mut_thing = ToOwned::to_owned(ref_str);
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, &mut mut_thing)`
 
-error: aborting due to 18 previous errors
+error: aborting due to 20 previous errors