Add test cases for replace with Default::default()

This commit is contained in:
Krishna Veera Reddy 2019-12-08 09:26:37 -08:00
parent 8db319f957
commit 2a75241c1a
3 changed files with 9 additions and 1 deletions

View file

@ -30,6 +30,7 @@ fn replace_with_default() {
let _ = std::mem::take(&mut s);
let s = &mut String::from("foo");
let _ = std::mem::take(s);
let _ = std::mem::take(s);
}
fn main() {

View file

@ -30,6 +30,7 @@ fn replace_with_default() {
let _ = std::mem::replace(&mut s, String::default());
let s = &mut String::from("foo");
let _ = std::mem::replace(s, String::default());
let _ = std::mem::replace(s, Default::default());
}
fn main() {

View file

@ -26,5 +26,11 @@ error: replacing a value of type `T` with `T::default()` is better expressed usi
LL | let _ = std::mem::replace(s, String::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)`
error: aborting due to 4 previous errors
error: replacing a value of type `T` with `T::default()` is better expressed using `std::mem::take`
--> $DIR/mem_replace.rs:33:13
|
LL | let _ = std::mem::replace(s, Default::default());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `std::mem::take(s)`
error: aborting due to 5 previous errors