1 fn borrow(_v: &isize) {}
2 fn borrow_mut(_v: &mut isize) {}
3 fn cond() -> bool { panic!() }
4 fn produce<T>() -> T { panic!(); }
7 fn inc(v: &mut Box<isize>) {
8 *v = Box::new(**v + 1);
12 fn loop_overarching_alias_mut() {
13 // In this instance, the borrow ends on the line before the loop
15 let mut v: Box<_> = Box::new(3);
23 fn block_overarching_alias_mut() {
24 // In this instance, the borrow encompasses the entire closure call.
26 let mut v: Box<_> = Box::new(3);
29 borrow(&*v); //~ ERROR cannot borrow
33 fn loop_aliased_mut() {
34 // In this instance, the borrow ends right after each assignment to _x
36 let mut v: Box<_> = Box::new(3);
37 let mut w: Box<_> = Box::new(4);
40 borrow_mut(&mut *v); // OK
45 fn while_aliased_mut() {
46 // In this instance, the borrow ends right after each assignment to _x
48 let mut v: Box<_> = Box::new(3);
49 let mut w: Box<_> = Box::new(4);
52 borrow_mut(&mut *v); // OK
58 fn loop_aliased_mut_break() {
59 // In this instance, the borrow ends right after each assignment to _x
61 let mut v: Box<_> = Box::new(3);
62 let mut w: Box<_> = Box::new(4);
69 borrow_mut(&mut *v); // OK
72 fn while_aliased_mut_break() {
73 // In this instance, the borrow ends right after each assignment to _x
75 let mut v: Box<_> = Box::new(3);
76 let mut w: Box<_> = Box::new(4);
83 borrow_mut(&mut *v); // OK
86 fn while_aliased_mut_cond(cond: bool, cond2: bool) {
87 let mut v: Box<_> = Box::new(3);
88 let mut w: Box<_> = Box::new(4);
92 borrow(&*v); //~ ERROR cannot borrow
98 fn loop_break_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F) where
99 F: FnMut(&'r mut usize) -> bool,
101 // Here we check that when you break out of an inner loop, the
102 // borrows that go out of scope as you exit the inner loop are
103 // removed from the bitset.
107 // this borrow is limited to the scope of `r`...
108 let r: &'r mut usize = produce();
110 break; // ...so it is not live as exit the `while` loop here
116 fn loop_loop_pops_scopes<'r, F>(_v: &'r mut [usize], mut f: F)
117 where F: FnMut(&'r mut usize) -> bool
119 // Similar to `loop_break_pops_scopes` but for the `loop` keyword
123 // this borrow is limited to the scope of `r`...
124 let r: &'r mut usize = produce();
126 continue; // ...so it is not live as exit (and re-enter) the `while` loop here