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