]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/mut_mut.rs
0db9cb3bdef803dd1f903de63b65b5264df862d9
[rust.git] / tests / compile-fail / mut_mut.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #![allow(unused, no_effect)]
5
6 //#![plugin(regex_macros)]
7 //extern crate regex;
8
9 #[deny(mut_mut)]
10 fn fun(x : &mut &mut u32) -> bool { //~ERROR generally you want to avoid `&mut &mut
11     **x > 0
12 }
13
14 #[deny(mut_mut)]
15 fn less_fun(x : *mut *mut u32) {
16   let y = x;
17 }
18
19 macro_rules! mut_ptr {
20     ($p:expr) => { &mut $p }
21 }
22
23 #[deny(mut_mut)]
24 #[allow(unused_mut, unused_variables)]
25 fn main() {
26     let mut x = &mut &mut 1u32; //~ERROR generally you want to avoid `&mut &mut
27     {
28         let mut y = &mut x; //~ERROR this expression mutably borrows a mutable reference
29     }
30
31     if fun(x) {
32         let y : &mut &mut &mut u32 = &mut &mut &mut 2;
33                  //~^ ERROR generally you want to avoid `&mut &mut
34                       //~^^ ERROR generally you want to avoid `&mut &mut
35                                       //~^^^ ERROR generally you want to avoid `&mut &mut
36                                            //~^^^^ ERROR generally you want to avoid `&mut &mut
37         ***y + **x;
38     }
39
40     let mut z = mut_ptr!(&mut 3u32); //~ERROR generally you want to avoid `&mut &mut
41 }