rust/tests/ui/borrowck/borrowck-autoref-3261.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

25 lines
605 B
Rust
Raw Normal View History

2013-12-25 23:55:05 -06:00
enum Either<T, U> { Left(T), Right(U) }
struct X(Either<(usize,usize), fn()>);
impl X {
pub fn with<F>(&self, blk: F) where F: FnOnce(&Either<(usize, usize), fn()>) {
let X(ref e) = *self;
blk(e)
}
}
fn main() {
let mut x = X(Either::Right(main as fn()));
(&mut x).with(
|opt| { //~ ERROR cannot borrow `x` as mutable more than once at a time
match opt {
&Either::Right(ref f) => {
2015-01-03 09:45:00 -06:00
x = X(Either::Left((0, 0)));
(*f)()
},
_ => panic!()
}
})
}