2014-12-07 09:22:06 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2015-01-07 20:53:58 -06:00
|
|
|
#![feature(box_syntax)]
|
|
|
|
|
2014-12-07 09:22:06 -06:00
|
|
|
use std::cell::RefCell;
|
|
|
|
|
|
|
|
fn main() {
|
2015-01-08 05:05:56 -06:00
|
|
|
let mut y = 1us;
|
2015-01-26 08:21:24 -06:00
|
|
|
let c = RefCell::new(vec![]);
|
2015-01-03 09:45:00 -06:00
|
|
|
c.push(box || y = 0);
|
|
|
|
c.push(box || y = 0);
|
2014-12-07 09:22:06 -06:00
|
|
|
//~^ ERROR cannot borrow `y` as mutable more than once at a time
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ufcs() {
|
2015-01-08 05:05:56 -06:00
|
|
|
let mut y = 1us;
|
2015-01-26 08:21:24 -06:00
|
|
|
let c = RefCell::new(vec![]);
|
2014-12-07 09:22:06 -06:00
|
|
|
|
2015-01-03 09:45:00 -06:00
|
|
|
Push::push(&c, box || y = 0);
|
|
|
|
Push::push(&c, box || y = 0);
|
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)
|
|
|
|
}
|
|
|
|
}
|