1 // check that existing borrows due to a closure capture give a special note 2 move_while_borrowed(x: String)3fn move_while_borrowed(x: String) { 4 let f = || x.len(); 5 let y = x; //~ ERROR 6 f.use_ref(); 7 } 8 borrow_mut_while_borrowed(mut x: i32)9fn borrow_mut_while_borrowed(mut x: i32) { 10 let f = || x; 11 let y = &mut x; //~ ERROR 12 f.use_ref(); 13 } 14 drop_while_borrowed()15fn drop_while_borrowed() { 16 let f; 17 { 18 let x = 1; 19 f = || x; //~ ERROR 20 } 21 f.use_ref(); 22 } 23 assign_while_borrowed(mut x: i32)24fn assign_while_borrowed(mut x: i32) { 25 let f = || x; 26 x = 1; //~ ERROR 27 f.use_ref(); 28 } 29 copy_while_borrowed_mut(mut x: i32)30fn copy_while_borrowed_mut(mut x: i32) { 31 let f = || x = 0; 32 let y = x; //~ ERROR 33 f.use_ref(); 34 } 35 borrow_while_borrowed_mut(mut x: i32)36fn borrow_while_borrowed_mut(mut x: i32) { 37 let f = || x = 0; 38 let y = &x; //~ ERROR 39 f.use_ref(); 40 } 41 borrow_mut_while_borrowed_mut(mut x: i32)42fn borrow_mut_while_borrowed_mut(mut x: i32) { 43 let f = || x = 0; 44 let y = &mut x; //~ ERROR 45 f.use_ref(); 46 } 47 drop_while_borrowed_mut()48fn drop_while_borrowed_mut() { 49 let f; 50 { 51 let mut x = 1; 52 f = || x = 0; //~ ERROR 53 } 54 f.use_ref(); 55 } 56 assign_while_borrowed_mut(mut x: i32)57fn assign_while_borrowed_mut(mut x: i32) { 58 let f = || x = 0; 59 x = 1; //~ ERROR 60 f.use_ref(); 61 } 62 copy_while_borrowed_unique(x: &mut i32)63fn copy_while_borrowed_unique(x: &mut i32) { 64 let f = || *x = 0; 65 let y = x; //~ ERROR 66 f.use_ref(); 67 } 68 borrow_while_borrowed_unique(x: &mut i32)69fn borrow_while_borrowed_unique(x: &mut i32) { 70 let f = || *x = 0; 71 let y = &x; //~ ERROR 72 f.use_ref(); 73 } 74 borrow_mut_while_borrowed_unique(mut x: &mut i32)75fn borrow_mut_while_borrowed_unique(mut x: &mut i32) { 76 let f = || *x = 0; 77 let y = &mut x; //~ ERROR 78 f.use_ref(); 79 } 80 drop_while_borrowed_unique()81fn drop_while_borrowed_unique() { 82 let mut z = 1; 83 let f; 84 { 85 let x = &mut z; 86 f = || *x = 0; //~ ERROR 87 } 88 f.use_ref(); 89 } 90 assign_while_borrowed_unique(x: &mut i32)91fn assign_while_borrowed_unique(x: &mut i32) { 92 let f = || *x = 0; 93 *x = 1; //~ ERROR 94 f.use_ref(); 95 } 96 main()97fn main() {} 98 use_mut(&mut self)99trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } 100 impl<T> Fake for T { } 101