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 {
|
2015-01-08 04:54:35 -06:00
|
|
|
n: HashSet<isize>,
|
2013-02-09 00:21:45 -06:00
|
|
|
}
|
|
|
|
|
2013-05-31 17:17:22 -05:00
|
|
|
impl Foo {
|
2015-01-08 04:54:35 -06:00
|
|
|
pub fn foo<F>(&mut self, mut fun: F) where F: FnMut(&isize) {
|
2015-01-31 11:20:46 -06:00
|
|
|
for f in &self.n {
|
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) {
|
2019-04-22 02:40:08 -05:00
|
|
|
f.foo(
|
|
|
|
//~^ ERROR cannot borrow `*f` as mutable
|
2014-02-10 06:44:03 -06:00
|
|
|
|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
|
|
|
}
|