2024-02-16 20:02:50 +00:00
|
|
|
//@ run-pass
|
2015-03-22 13:13:15 -07:00
|
|
|
|
2014-02-01 04:35:36 +08:00
|
|
|
use std::mem::swap;
|
2013-05-06 00:42:54 -04:00
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2012-07-26 08:51:57 -07:00
|
|
|
let mut x = 4;
|
|
|
|
|
|
2015-02-18 05:42:01 -05:00
|
|
|
for i in 0_usize..3 {
|
2012-07-26 08:51:57 -07:00
|
|
|
// ensure that the borrow in this alt
|
2014-08-01 19:42:13 -04:00
|
|
|
// does not interfere with the swap
|
2013-05-03 19:25:04 -04: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 12:34:08 -07:00
|
|
|
match i {
|
2013-05-03 19:25:04 -04:00
|
|
|
i => {
|
|
|
|
|
let y = &x;
|
|
|
|
|
assert!(i < *y);
|
|
|
|
|
}
|
2012-07-26 08:51:57 -07:00
|
|
|
}
|
|
|
|
|
let mut y = 4;
|
2014-02-01 04:35:36 +08:00
|
|
|
swap(&mut y, &mut x);
|
2012-07-26 08:51:57 -07:00
|
|
|
}
|
|
|
|
|
}
|