]> git.lizzy.rs Git - rust.git/blob - tests/ui/swap.rs
Merge pull request #3265 from mikerite/fix-export
[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
11 #![feature(tool_lints)]
12
13
14 #![warn(clippy::all)]
15 #![allow(clippy::blacklisted_name, unused_assignments)]
16
17 struct Foo(u32);
18
19 fn array() {
20     let mut foo = [1, 2];
21     let temp = foo[0];
22     foo[0] = foo[1];
23     foo[1] = temp;
24
25     foo.swap(0, 1);
26 }
27
28 fn slice() {
29     let foo = &mut [1, 2];
30     let temp = foo[0];
31     foo[0] = foo[1];
32     foo[1] = temp;
33
34     foo.swap(0, 1);
35 }
36
37 fn vec() {
38     let mut foo = vec![1, 2];
39     let temp = foo[0];
40     foo[0] = foo[1];
41     foo[1] = temp;
42
43     foo.swap(0, 1);
44 }
45
46 fn main() {
47     array();
48     slice();
49     vec();
50
51     let mut a = 42;
52     let mut b = 1337;
53
54     a = b;
55     b = a;
56
57     ; let t = a;
58     a = b;
59     b = t;
60
61     let mut c = Foo(42);
62
63     c.0 = a;
64     a = c.0;
65
66     ; let t = c.0;
67     c.0 = a;
68     a = t;
69 }