]> git.lizzy.rs Git - rust.git/blob - tests/ui/mem_replace.rs
iterate List by value
[rust.git] / tests / ui / mem_replace.rs
1 // run-rustfix
2 #![allow(unused_imports)]
3 #![warn(
4     clippy::all,
5     clippy::style,
6     clippy::mem_replace_option_with_none,
7     clippy::mem_replace_with_default
8 )]
9
10 use std::mem;
11
12 fn replace_option_with_none() {
13     let mut an_option = Some(1);
14     let _ = mem::replace(&mut an_option, None);
15     let an_option = &mut Some(1);
16     let _ = mem::replace(an_option, None);
17 }
18
19 fn replace_with_default() {
20     let mut s = String::from("foo");
21     let _ = std::mem::replace(&mut s, String::default());
22     let s = &mut String::from("foo");
23     let _ = std::mem::replace(s, String::default());
24     let _ = std::mem::replace(s, Default::default());
25 }
26
27 fn main() {
28     replace_option_with_none();
29     replace_with_default();
30 }