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