]> git.lizzy.rs Git - rust.git/blob - tests/compile-fail/mut_mut.rs
21c0dcee5115d939aaac47829a9309503db0e571
[rust.git] / tests / compile-fail / mut_mut.rs
1 #![feature(plugin)]
2 #![plugin(clippy)]
3
4 #![allow(unused, no_effect, unnecessary_operation)]
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     //~^ ERROR generally you want to avoid `&mut &mut
22 }
23
24 #[deny(mut_mut)]
25 #[allow(unused_mut, unused_variables)]
26 fn main() {
27     let mut x = &mut &mut 1u32; //~ERROR generally you want to avoid `&mut &mut
28     {
29         let mut y = &mut x; //~ERROR this expression mutably borrows a mutable reference
30     }
31
32     if fun(x) {
33         let y : &mut &mut &mut u32 = &mut &mut &mut 2;
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         //~| ERROR generally you want to avoid `&mut &mut
38         ***y + **x;
39     }
40
41     let mut z = mut_ptr!(&mut 3u32);
42     //~^ NOTE in this expansion of mut_ptr!
43 }