5 clippy::blacklisted_name,
7 clippy::redundant_clone,
22 let mut bar = Bar { a: 1, b: 2 };
24 std::mem::swap(&mut bar.a, &mut bar.b);
26 let mut baz = vec![bar.clone(), bar.clone()];
40 let foo = &mut [1, 2];
46 fn unswappable_slice() {
47 let foo = &mut [vec![1, 2], vec![3, 4]];
49 foo[0][1] = foo[1][0];
52 // swap(foo[0][1], foo[1][0]) would fail
53 // this could use split_at_mut and mem::swap, but that is not much simpler.
57 let mut foo = vec![1, 2];
63 fn xor_swap_locals() {
64 // This is an xor-based swap of local variables.
67 std::mem::swap(&mut a, &mut b)
71 // This is an xor-based swap of fields in a struct.
72 let mut bar = Bar { a: 0, b: 1 };
73 std::mem::swap(&mut bar.a, &mut bar.b)
77 // This is an xor-based swap of a slice
78 let foo = &mut [1, 2];
83 // This is a sequence of xor-assignment statements that doesn't result in a swap.
93 fn xor_unswappable_slice() {
94 let foo = &mut [vec![1, 2], vec![3, 4]];
95 foo[0][1] ^= foo[1][0];
96 foo[1][0] ^= foo[0][0];
97 foo[0][1] ^= foo[1][0];
99 // swap(foo[0][1], foo[1][0]) would fail
100 // this could use split_at_mut and mem::swap, but that is not much simpler.
103 fn distinct_slice() {
104 let foo = &mut [vec![1, 2], vec![3, 4]];
105 let bar = &mut [vec![1, 2], vec![3, 4]];
106 std::mem::swap(&mut foo[0][1], &mut bar[1][0]);
115 std::mem::swap(&mut a, &mut b);
117 ; std::mem::swap(&mut a, &mut b);
121 std::mem::swap(&mut c.0, &mut a);
123 ; std::mem::swap(&mut c.0, &mut a);