2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2015-03-22 20:13:15 +00:00
|
|
|
|
2014-01-31 20:35:36 +00:00
|
|
|
use std::mem::swap;
|
2013-05-06 04:42:54 +00:00
|
|
|
|
2013-02-02 03:43:17 +00:00
|
|
|
pub fn main() {
|
2012-07-26 15:51:57 +00:00
|
|
|
let mut x = 4;
|
|
|
|
|
2015-02-18 10:42:01 +00:00
|
|
|
for i in 0_usize..3 {
|
2012-07-26 15:51:57 +00:00
|
|
|
// ensure that the borrow in this alt
|
2014-08-01 23:42:13 +00:00
|
|
|
// does not interfere with the swap
|
2013-05-03 23:25:04 +00:00
|
|
|
// below. note that it would it you
|
|
|
|
// naively borrowed &x for the lifetime
|
|
|
|
// of the variable x, as we once did
|
2012-08-06 19:34:08 +00:00
|
|
|
match i {
|
2013-05-03 23:25:04 +00:00
|
|
|
i => {
|
|
|
|
let y = &x;
|
|
|
|
assert!(i < *y);
|
|
|
|
}
|
2012-07-26 15:51:57 +00:00
|
|
|
}
|
|
|
|
let mut y = 4;
|
2014-01-31 20:35:36 +00:00
|
|
|
swap(&mut y, &mut x);
|
2012-07-26 15:51:57 +00:00
|
|
|
}
|
|
|
|
}
|