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