]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/borrowck/borrowck-mut-uniq.rs
Account for --remap-path-prefix in save-analysis
[rust.git] / src / test / run-pass / borrowck / borrowck-mut-uniq.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(unknown_features)]
12 #![feature(box_syntax)]
13
14 use std::mem::swap;
15
16 #[derive(Debug)]
17 struct Ints {sum: Box<isize>, values: Vec<isize> }
18
19 fn add_int(x: &mut Ints, v: isize) {
20     *x.sum += v;
21     let mut values = Vec::new();
22     swap(&mut values, &mut x.values);
23     values.push(v);
24     swap(&mut values, &mut x.values);
25 }
26
27 fn iter_ints<F>(x: &Ints, mut f: F) -> bool where F: FnMut(&isize) -> bool {
28     let l = x.values.len();
29     (0..l).all(|i| f(&x.values[i]))
30 }
31
32 pub fn main() {
33     let mut ints: Box<_> = box Ints {sum: box 0, values: Vec::new()};
34     add_int(&mut *ints, 22);
35     add_int(&mut *ints, 44);
36
37     iter_ints(&*ints, |i| {
38         println!("isize = {:?}", *i);
39         true
40     });
41
42     println!("ints={:?}", ints);
43 }