]> git.lizzy.rs Git - rust.git/blob - tests/ui/borrowck/borrowck-autoref-3261.rs
Rollup merge of #106726 - cmorin6:fix-comment-typos, r=Nilstrieb
[rust.git] / tests / ui / borrowck / borrowck-autoref-3261.rs
1 enum Either<T, U> { Left(T), Right(U) }
2
3 struct X(Either<(usize,usize), fn()>);
4
5 impl X {
6     pub fn with<F>(&self, blk: F) where F: FnOnce(&Either<(usize, usize), fn()>) {
7         let X(ref e) = *self;
8         blk(e)
9     }
10 }
11
12 fn main() {
13     let mut x = X(Either::Right(main as fn()));
14     (&mut x).with(
15         |opt| { //~ ERROR cannot borrow `x` as mutable more than once at a time
16             match opt {
17                 &Either::Right(ref f) => {
18                     x = X(Either::Left((0, 0)));
19                     (*f)()
20                 },
21                 _ => panic!()
22             }
23         })
24 }