Skip to content

Commit 8c866d3

Browse files
committed
Add test for MSRV checking for assigning_clones
1 parent 21a97f0 commit 8c866d3

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

tests/ui/assigning_clones.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ fn ignore_generic_clone<T: Clone>(a: &mut T, b: &T) {
128128
*a = b.clone();
129129
}
130130

131+
#[clippy::msrv = "1.62"]
132+
fn msrv_1_62(mut a: String, b: &str) {
133+
// Should not be linted, as clone_into wasn't stabilized until 1.63
134+
a = b.to_owned();
135+
}
136+
137+
#[clippy::msrv = "1.63"]
138+
fn msrv_1_63(mut a: String, b: &str) {
139+
b.clone_into(&mut a);
140+
}
141+
131142
macro_rules! clone_inside {
132143
($a:expr, $b: expr) => {
133144
$a = $b.clone();

tests/ui/assigning_clones.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,17 @@ fn ignore_generic_clone<T: Clone>(a: &mut T, b: &T) {
128128
*a = b.clone();
129129
}
130130

131+
#[clippy::msrv = "1.62"]
132+
fn msrv_1_62(mut a: String, b: &str) {
133+
// Should not be linted, as clone_into wasn't stabilized until 1.63
134+
a = b.to_owned();
135+
}
136+
137+
#[clippy::msrv = "1.63"]
138+
fn msrv_1_63(mut a: String, b: &str) {
139+
a = b.to_owned();
140+
}
141+
131142
macro_rules! clone_inside {
132143
($a:expr, $b: expr) => {
133144
$a = $b.clone();

tests/ui/assigning_clones.stderr

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,40 +68,46 @@ LL | a = b.clone();
6868
| ^^^^^^^^^^^^^ help: use `clone_from()`: `a.clone_from(&b)`
6969

7070
error: assigning the result of `ToOwned::to_owned()` may be inefficient
71-
--> tests/ui/assigning_clones.rs:145:5
71+
--> tests/ui/assigning_clones.rs:139:5
72+
|
73+
LL | a = b.to_owned();
74+
| ^^^^^^^^^^^^^^^^ help: use `clone_into()`: `b.clone_into(&mut a)`
75+
76+
error: assigning the result of `ToOwned::to_owned()` may be inefficient
77+
--> tests/ui/assigning_clones.rs:156:5
7278
|
7379
LL | *mut_string = ref_str.to_owned();
7480
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(mut_string)`
7581

7682
error: assigning the result of `ToOwned::to_owned()` may be inefficient
77-
--> tests/ui/assigning_clones.rs:149:5
83+
--> tests/ui/assigning_clones.rs:160:5
7884
|
7985
LL | mut_string = ref_str.to_owned();
8086
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut mut_string)`
8187

8288
error: assigning the result of `ToOwned::to_owned()` may be inefficient
83-
--> tests/ui/assigning_clones.rs:170:5
89+
--> tests/ui/assigning_clones.rs:181:5
8490
|
8591
LL | **mut_box_string = ref_str.to_owned();
8692
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))`
8793

8894
error: assigning the result of `ToOwned::to_owned()` may be inefficient
89-
--> tests/ui/assigning_clones.rs:174:5
95+
--> tests/ui/assigning_clones.rs:185:5
9096
|
9197
LL | **mut_box_string = ref_str.to_owned();
9298
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ref_str.clone_into(&mut (*mut_box_string))`
9399

94100
error: assigning the result of `ToOwned::to_owned()` may be inefficient
95-
--> tests/ui/assigning_clones.rs:178:5
101+
--> tests/ui/assigning_clones.rs:189:5
96102
|
97103
LL | *mut_thing = ToOwned::to_owned(ref_str);
98104
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, mut_thing)`
99105

100106
error: assigning the result of `ToOwned::to_owned()` may be inefficient
101-
--> tests/ui/assigning_clones.rs:182:5
107+
--> tests/ui/assigning_clones.rs:193:5
102108
|
103109
LL | mut_thing = ToOwned::to_owned(ref_str);
104110
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_into()`: `ToOwned::clone_into(ref_str, &mut mut_thing)`
105111

106-
error: aborting due to 17 previous errors
112+
error: aborting due to 18 previous errors
107113

0 commit comments

Comments
 (0)