2012-12-10 17:32:48 -08:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2014-02-19 19:29:58 -08:00
|
|
|
extern crate collections;
|
|
|
|
use collections::HashSet;
|
2013-02-08 22:21:45 -08:00
|
|
|
|
2012-10-21 23:02:02 -07:00
|
|
|
struct Foo {
|
2013-04-03 09:28:36 -04:00
|
|
|
n: HashSet<int>,
|
2013-02-08 22:21:45 -08:00
|
|
|
}
|
|
|
|
|
2013-05-31 15:17:22 -07:00
|
|
|
impl Foo {
|
2013-11-19 16:34:19 -08:00
|
|
|
pub fn foo(&mut self, fun: |&int|) {
|
2013-08-03 12:45:23 -04:00
|
|
|
for f in self.n.iter() {
|
2013-05-31 15:17:22 -07:00
|
|
|
fun(f);
|
|
|
|
}
|
2013-02-08 22:21:45 -08:00
|
|
|
}
|
2012-10-21 23:02:02 -07:00
|
|
|
}
|
|
|
|
|
2013-02-08 22:21:45 -08:00
|
|
|
fn bar(f: &mut Foo) {
|
2014-02-10 07:44:03 -05:00
|
|
|
f.foo(
|
|
|
|
|a| { //~ ERROR closure requires unique access to `f`
|
|
|
|
f.n.insert(*a);
|
|
|
|
})
|
2012-10-21 23:02:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2013-04-03 09:28:36 -04:00
|
|
|
let mut f = Foo { n: HashSet::new() };
|
2013-02-08 22:21:45 -08:00
|
|
|
bar(&mut f);
|
2013-02-14 11:47:00 -08:00
|
|
|
}
|