mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 05:03:21 +00:00
Add test cases for replace with Default::default()
This commit is contained in:
parent
8db319f957
commit
2a75241c1a
3 changed files with 9 additions and 1 deletions
|
@ -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() {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue