rust/src/test/ui/issues/issue-18783.rs

29 lines
662 B
Rust
Raw Normal View History

2014-12-07 09:22:06 -06:00
use std::cell::RefCell;
fn main() {
let mut y = 1;
let c = RefCell::new(vec![]);
c.push(Box::new(|| y = 0));
c.push(Box::new(|| y = 0));
2014-12-07 09:22:06 -06:00
//~^ ERROR cannot borrow `y` as mutable more than once at a time
}
fn ufcs() {
let mut y = 1;
let c = RefCell::new(vec![]);
2014-12-07 09:22:06 -06:00
Push::push(&c, Box::new(|| y = 0));
Push::push(&c, Box::new(|| y = 0));
//~^ ERROR cannot borrow `y` as mutable more than once at a time
2014-12-07 09:22:06 -06:00
}
trait Push<'c> {
2015-01-03 09:45:00 -06:00
fn push<'f: 'c>(&self, push: Box<FnMut() + 'f>);
2014-12-07 09:22:06 -06:00
}
2015-01-03 09:45:00 -06:00
impl<'c> Push<'c> for RefCell<Vec<Box<FnMut() + 'c>>> {
fn push<'f: 'c>(&self, fun: Box<FnMut() + 'f>) {
2014-12-07 09:22:06 -06:00
self.borrow_mut().push(fun)
}
}