mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-14 17:07:17 +00:00
Add test for MSRV checking for assigning_clones
This commit is contained in:
parent
21a97f0192
commit
8c866d36cc
3 changed files with 35 additions and 7 deletions
|
@ -128,6 +128,17 @@ fn ignore_generic_clone<T: Clone>(a: &mut T, b: &T) {
|
|||
*a = b.clone();
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.62"]
|
||||
fn msrv_1_62(mut a: String, b: &str) {
|
||||
// Should not be linted, as clone_into wasn't stabilized until 1.63
|
||||
a = b.to_owned();
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.63"]
|
||||
fn msrv_1_63(mut a: String, b: &str) {
|
||||
b.clone_into(&mut a);
|
||||
}
|
||||
|
||||
macro_rules! clone_inside {
|
||||
($a:expr, $b: expr) => {
|
||||
$a = $b.clone();
|
||||
|
|
|
@ -128,6 +128,17 @@ fn ignore_generic_clone<T: Clone>(a: &mut T, b: &T) {
|
|||
*a = b.clone();
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.62"]
|
||||
fn msrv_1_62(mut a: String, b: &str) {
|
||||
// Should not be linted, as clone_into wasn't stabilized until 1.63
|
||||
a = b.to_owned();
|
||||
}
|
||||
|
||||
#[clippy::msrv = "1.63"]
|
||||
fn msrv_1_63(mut a: String, b: &str) {
|
||||
a = b.to_owned();
|
||||
}
|
||||
|
||||
macro_rules! clone_inside {
|
||||
($a:expr, $b: expr) => {
|
||||
$a = $b.clone();
|
||||
|
|
|
@ -68,40 +68,46 @@ 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:145:5
|
||||
--> tests/ui/assigning_clones.rs:139:5
|
||||
|
|
||||
LL | a = b.to_owned();
|
||||
| ^^^^^^^^^^^^^^^^ help: use `clone_into()`: `b.clone_into(&mut a)`
|
||||
|
||||
error: assigning the result of `ToOwned::to_owned()` may be inefficient
|
||||
--> tests/ui/assigning_clones.rs:156: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:149:5
|
||||
--> tests/ui/assigning_clones.rs:160: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:170:5
|
||||
--> tests/ui/assigning_clones.rs:181: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:174:5
|
||||
--> tests/ui/assigning_clones.rs:185: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:178:5
|
||||
--> tests/ui/assigning_clones.rs:189: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:182:5
|
||||
--> tests/ui/assigning_clones.rs:193: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 17 previous errors
|
||||
error: aborting due to 18 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue