2014-12-07 15:22:06 +00:00
|
|
|
use std::cell::RefCell;
|
|
|
|
|
|
|
|
fn main() {
|
2015-03-03 08:42:26 +00:00
|
|
|
let mut y = 1;
|
2015-01-26 14:21:24 +00:00
|
|
|
let c = RefCell::new(vec![]);
|
2015-02-15 08:52:21 +00:00
|
|
|
c.push(Box::new(|| y = 0));
|
|
|
|
c.push(Box::new(|| y = 0));
|
2014-12-07 15:22:06 +00:00
|
|
|
//~^ ERROR cannot borrow `y` as mutable more than once at a time
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ufcs() {
|
2015-03-03 08:42:26 +00:00
|
|
|
let mut y = 1;
|
2015-01-26 14:21:24 +00:00
|
|
|
let c = RefCell::new(vec![]);
|
2014-12-07 15:22:06 +00:00
|
|
|
|
2015-02-15 08:52:21 +00:00
|
|
|
Push::push(&c, Box::new(|| y = 0));
|
|
|
|
Push::push(&c, Box::new(|| y = 0));
|
2015-02-12 15:29:52 +00:00
|
|
|
//~^ ERROR cannot borrow `y` as mutable more than once at a time
|
2014-12-07 15:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
trait Push<'c> {
|
2019-05-28 18:46:13 +00:00
|
|
|
fn push<'f: 'c>(&self, push: Box<dyn FnMut() + 'f>);
|
2014-12-07 15:22:06 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 18:46:13 +00:00
|
|
|
impl<'c> Push<'c> for RefCell<Vec<Box<dyn FnMut() + 'c>>> {
|
|
|
|
fn push<'f: 'c>(&self, fun: Box<dyn FnMut() + 'f>) {
|
2014-12-07 15:22:06 +00:00
|
|
|
self.borrow_mut().push(fun)
|
|
|
|
}
|
|
|
|
}
|