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.
|
|
|
|
|
2013-04-03 08:28:36 -05:00
|
|
|
use core::hashmap::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-02-26 19:47:41 -06:00
|
|
|
pub impl Foo {
|
2013-03-07 16:38:38 -06:00
|
|
|
fn foo(&mut self, fun: &fn(&int)) {
|
2013-02-09 00:21:45 -06:00
|
|
|
for self.n.each |f| {
|
|
|
|
fun(f);
|
|
|
|
}
|
|
|
|
}
|
2012-10-22 01:02:02 -05:00
|
|
|
}
|
|
|
|
|
2013-02-09 00:21:45 -06:00
|
|
|
fn bar(f: &mut Foo) {
|
2013-03-15 14:24:24 -05:00
|
|
|
do f.foo |a| {
|
|
|
|
f.n.insert(*a); //~ ERROR cannot borrow
|
2013-02-09 00:21:45 -06:00
|
|
|
}
|
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
|
|
|
}
|