2012-12-11 01:32:48 +00:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
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;
|
|
|
|
|
2013-08-03 16:45:23 +00:00
|
|
|
for i in range(0u, 3) {
|
2012-07-26 15:51:57 +00:00
|
|
|
// ensure that the borrow in this alt
|
2013-05-03 23:25:04 +00:00
|
|
|
// does not inferfere with the swap
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|