mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
25 lines
605 B
Rust
25 lines
605 B
Rust
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) => {
|
|
x = X(Either::Left((0, 0)));
|
|
(*f)()
|
|
},
|
|
_ => panic!()
|
|
}
|
|
})
|
|
}
|