]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | use std::cell::RefCell; |
2 | ||
3 | fn main() { | |
c34b1796 | 4 | let mut y = 1; |
1a4d82fc | 5 | let c = RefCell::new(vec![]); |
c34b1796 AL |
6 | c.push(Box::new(|| y = 0)); |
7 | c.push(Box::new(|| y = 0)); | |
1a4d82fc JJ |
8 | //~^ ERROR cannot borrow `y` as mutable more than once at a time |
9 | } | |
10 | ||
11 | fn ufcs() { | |
c34b1796 | 12 | let mut y = 1; |
1a4d82fc | 13 | let c = RefCell::new(vec![]); |
1a4d82fc | 14 | |
c34b1796 AL |
15 | Push::push(&c, Box::new(|| y = 0)); |
16 | Push::push(&c, Box::new(|| y = 0)); | |
85aaf69f | 17 | //~^ ERROR cannot borrow `y` as mutable more than once at a time |
1a4d82fc JJ |
18 | } |
19 | ||
20 | trait Push<'c> { | |
dc9dc135 | 21 | fn push<'f: 'c>(&self, push: Box<dyn FnMut() + 'f>); |
1a4d82fc JJ |
22 | } |
23 | ||
dc9dc135 XL |
24 | impl<'c> Push<'c> for RefCell<Vec<Box<dyn FnMut() + 'c>>> { |
25 | fn push<'f: 'c>(&self, fun: Box<dyn FnMut() + 'f>) { | |
1a4d82fc JJ |
26 | self.borrow_mut().push(fun) |
27 | } | |
28 | } |