]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-18783.rs
Rollup merge of #53030 - Aaronepower:master, r=Mark-Simulacrum
[rust.git] / src / test / ui / issues / issue-18783.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use std::cell::RefCell;
12
13 fn main() {
14     let mut y = 1;
15     let c = RefCell::new(vec![]);
16     c.push(Box::new(|| y = 0));
17     c.push(Box::new(|| y = 0));
18 //~^ ERROR cannot borrow `y` as mutable more than once at a time
19 }
20
21 fn ufcs() {
22     let mut y = 1;
23     let c = RefCell::new(vec![]);
24
25     Push::push(&c, Box::new(|| y = 0));
26     Push::push(&c, Box::new(|| y = 0));
27 //~^ ERROR cannot borrow `y` as mutable more than once at a time
28 }
29
30 trait Push<'c> {
31     fn push<'f: 'c>(&self, push: Box<FnMut() + 'f>);
32 }
33
34 impl<'c> Push<'c> for RefCell<Vec<Box<FnMut() + 'c>>> {
35     fn push<'f: 'c>(&self, fun: Box<FnMut() + 'f>) {
36         self.borrow_mut().push(fun)
37     }
38 }