]> git.lizzy.rs Git - rust.git/blob - tests/ui/swap.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / swap.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 #![warn(clippy::all)]
11 #![allow(clippy::blacklisted_name, unused_assignments)]
12
13 struct Foo(u32);
14
15 fn array() {
16     let mut foo = [1, 2];
17     let temp = foo[0];
18     foo[0] = foo[1];
19     foo[1] = temp;
20
21     foo.swap(0, 1);
22 }
23
24 fn slice() {
25     let foo = &mut [1, 2];
26     let temp = foo[0];
27     foo[0] = foo[1];
28     foo[1] = temp;
29
30     foo.swap(0, 1);
31 }
32
33 fn vec() {
34     let mut foo = vec![1, 2];
35     let temp = foo[0];
36     foo[0] = foo[1];
37     foo[1] = temp;
38
39     foo.swap(0, 1);
40 }
41
42 #[rustfmt::skip]
43 fn main() {
44     array();
45     slice();
46     vec();
47
48     let mut a = 42;
49     let mut b = 1337;
50
51     a = b;
52     b = a;
53
54     ; let t = a;
55     a = b;
56     b = t;
57
58     let mut c = Foo(42);
59
60     c.0 = a;
61     a = c.0;
62
63     ; let t = c.0;
64     c.0 = a;
65     a = t;
66 }