]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/mut_mut.rs
Fix FP with `mut_mut` and `for` loops
[rust.git] / tests / compile-fail / mut_mut.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #![allow(unused, no_effect, unnecessary_operation)]
5 #![deny(mut_mut)]
6
7 //#![plugin(regex_macros)]
8 //extern crate regex;
9
10 fn fun(x : &mut &mut u32) -> bool { //~ERROR generally you want to avoid `&mut &mut
11     **x > 0
12 }
13
14 fn less_fun(x : *mut *mut u32) {
15   let y = x;
16 }
17
18 macro_rules! mut_ptr {
19     ($p:expr) => { &mut $p }
20     //~^ ERROR generally you want to avoid `&mut &mut
21 }
22
23 #[allow(unused_mut, unused_variables)]
24 fn main() {
25     let mut x = &mut &mut 1u32; //~ERROR generally you want to avoid `&mut &mut
26     {
27         let mut y = &mut x; //~ERROR this expression mutably borrows a mutable reference
28     }
29
30     if fun(x) {
31         let y : &mut &mut u32 = &mut &mut 2;
32         //~^ ERROR generally you want to avoid `&mut &mut
33         //~| ERROR generally you want to avoid `&mut &mut
34         //~| ERROR generally you want to avoid `&mut &mut
35         **y + **x;
36     }
37
38     if fun(x) {
39         let y : &mut &mut &mut u32 = &mut &mut &mut 2;
40         //~^ ERROR generally you want to avoid `&mut &mut
41         //~| ERROR generally you want to avoid `&mut &mut
42         //~| ERROR generally you want to avoid `&mut &mut
43         //~| ERROR generally you want to avoid `&mut &mut
44         //~| ERROR generally you want to avoid `&mut &mut
45         //~| ERROR generally you want to avoid `&mut &mut
46         ***y + **x;
47     }
48
49     let mut z = mut_ptr!(&mut 3u32);
50     //~^ NOTE in this expansion of mut_ptr!
51 }
52
53 fn issue939() {
54     let array = [5, 6, 7, 8, 9];
55     let mut args = array.iter().skip(2);
56     for &arg in &mut args {
57         println!("{}", arg);
58     }
59
60     let args = &mut args;
61     for arg in args {
62         println!(":{}", arg);
63     }
64 }