5 clippy::blacklisted_name,
7 clippy::redundant_clone,
22 let mut bar = Bar { a: 1, b: 2 };
28 let mut baz = vec![bar.clone(), bar.clone()];
44 let foo = &mut [1, 2];
52 fn unswappable_slice() {
53 let foo = &mut [vec![1, 2], vec![3, 4]];
55 foo[0][1] = foo[1][0];
58 // swap(foo[0][1], foo[1][0]) would fail
59 // this could use split_at_mut and mem::swap, but that is not much simpler.
63 let mut foo = vec![1, 2];
71 fn xor_swap_locals() {
72 // This is an xor-based swap of local variables.
81 // This is an xor-based swap of fields in a struct.
82 let mut bar = Bar { a: 0, b: 1 };
89 // This is an xor-based swap of a slice
90 let foo = &mut [1, 2];
97 // This is a sequence of xor-assignment statements that doesn't result in a swap.
107 fn xor_unswappable_slice() {
108 let foo = &mut [vec![1, 2], vec![3, 4]];
109 foo[0][1] ^= foo[1][0];
110 foo[1][0] ^= foo[0][0];
111 foo[0][1] ^= foo[1][0];
113 // swap(foo[0][1], foo[1][0]) would fail
114 // this could use split_at_mut and mem::swap, but that is not much simpler.
117 fn distinct_slice() {
118 let foo = &mut [vec![1, 2], vec![3, 4]];
119 let bar = &mut [vec![1, 2], vec![3, 4]];
120 let temp = foo[0][1];
121 foo[0][1] = bar[1][0];
154 struct S3<'a, 'b>(&'a mut &'b mut S1);
156 impl std::ops::Deref for S2 {
158 fn deref(&self) -> &Self::Target {
162 impl std::ops::DerefMut for S2 {
163 fn deref_mut(&mut self) -> &mut Self::Target {
168 // Don't lint. `s.0` is mutably borrowed by `s.x` and `s.y` via the deref impl.
169 let mut s = S2(S1 { x: 0, y: 0 });
174 // Accessing through a mutable reference is fine
175 let mut s = S1 { x: 0, y: 0 };