]> git.lizzy.rs Git - rust.git/blob - tests/ui/mut_mut.rs
Auto merge of #3603 - xfix:random-state-lint, r=phansch
[rust.git] / tests / ui / mut_mut.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 #![allow(unused, clippy::no_effect, clippy::unnecessary_operation)]
11 #![warn(clippy::mut_mut)]
12
13 fn fun(x: &mut &mut u32) -> bool {
14     **x > 0
15 }
16
17 fn less_fun(x: *mut *mut u32) {
18     let y = x;
19 }
20
21 macro_rules! mut_ptr {
22     ($p:expr) => {
23         &mut $p
24     };
25 }
26
27 #[allow(unused_mut, unused_variables)]
28 fn main() {
29     let mut x = &mut &mut 1u32;
30     {
31         let mut y = &mut x;
32     }
33
34     if fun(x) {
35         let y: &mut &mut u32 = &mut &mut 2;
36         **y + **x;
37     }
38
39     if fun(x) {
40         let y: &mut &mut &mut u32 = &mut &mut &mut 2;
41         ***y + **x;
42     }
43
44     let mut z = mut_ptr!(&mut 3u32);
45 }
46
47 fn issue939() {
48     let array = [5, 6, 7, 8, 9];
49     let mut args = array.iter().skip(2);
50     for &arg in &mut args {
51         println!("{}", arg);
52     }
53
54     let args = &mut args;
55     for arg in args {
56         println!(":{}", arg);
57     }
58 }