]> git.lizzy.rs Git - rust.git/blob - tests/ui/swap.rs
Merge branch 'master' into rustfmt_tests
[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 fn main() {
43     array();
44     slice();
45     vec();
46
47     let mut a = 42;
48     let mut b = 1337;
49
50     a = b;
51     b = a;
52
53 ;    let t = a;
54     a = b;
55     b = t;
56
57     let mut c = Foo(42);
58
59     c.0 = a;
60     a = c.0;
61
62 ;    let t = c.0;
63     c.0 = a;
64     a = t;
65 }