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