]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-insert-during-each.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-insert-during-each.rs
1 use std::collections::HashSet;
2
3 struct Foo {
4   n: HashSet<isize>,
5 }
6
7 impl Foo {
8     pub fn foo<F>(&mut self, mut fun: F) where F: FnMut(&isize) {
9         for f in &self.n {
10             fun(f);
11         }
12     }
13 }
14
15 fn bar(f: &mut Foo) {
16     f.foo(
17     //~^ ERROR cannot borrow `*f` as mutable
18         |a| { //~ ERROR closure requires unique access to `f`
19             f.n.insert(*a);
20         })
21 }
22
23 fn main() {
24   let mut f = Foo { n: HashSet::new() };
25   bar(&mut f);
26 }