]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/swap.rs
1 //@aux-build: macro_rules.rs
5 clippy
::disallowed_names
,
7 clippy
::redundant_clone
,
12 clippy
::let_and_return
,
14 clippy
::redundant_locals
26 let mut bar
= Bar { a: 1, b: 2 }
;
32 let mut baz
= vec
![bar
.clone(), bar
.clone()];
48 let foo
= &mut [1, 2];
56 fn unswappable_slice() {
57 let foo
= &mut [vec
![1, 2], vec
![3, 4]];
59 foo
[0][1] = foo
[1][0];
62 // swap(foo[0][1], foo[1][0]) would fail
63 // this could use split_at_mut and mem::swap, but that is not much simpler.
67 let mut foo
= vec
![1, 2];
75 fn xor_swap_locals() {
76 // This is an xor-based swap of local variables.
85 // This is an xor-based swap of fields in a struct.
86 let mut bar
= Bar { a: 0, b: 1 }
;
93 // This is an xor-based swap of a slice
94 let foo
= &mut [1, 2];
101 // This is a sequence of xor-assignment statements that doesn't result in a swap.
111 fn xor_unswappable_slice() {
112 let foo
= &mut [vec
![1, 2], vec
![3, 4]];
113 foo
[0][1] ^
= foo
[1][0];
114 foo
[1][0] ^
= foo
[0][0];
115 foo
[0][1] ^
= foo
[1][0];
117 // swap(foo[0][1], foo[1][0]) would fail
118 // this could use split_at_mut and mem::swap, but that is not much simpler.
121 fn distinct_slice() {
122 let foo
= &mut [vec
![1, 2], vec
![3, 4]];
123 let bar
= &mut [vec
![1, 2], vec
![3, 4]];
124 let temp
= foo
[0][1];
125 foo
[0][1] = bar
[1][0];
184 struct S3
<'a
, 'b
>(&'a
mut &'b
mut S1
);
186 impl std
::ops
::Deref
for S2
{
188 fn deref(&self) -> &Self::Target
{
192 impl std
::ops
::DerefMut
for S2
{
193 fn deref_mut(&mut self) -> &mut Self::Target
{
198 // Don't lint. `s.0` is mutably borrowed by `s.x` and `s.y` via the deref impl.
199 let mut s
= S2(S1 { x: 0, y: 0 }
);
204 // Accessing through a mutable reference is fine
205 let mut s
= S1 { x: 0, y: 0 }
;
213 const fn issue_9864(mut u
: u32) -> u32 {
223 extern crate macro_rules
;
225 const fn issue_10421(x
: u32) -> u32 {