]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/spike.rs
257699cd3fce15b53a2d61ec02271eb1584858d8
[rust.git] / src / test / incremental / spike.rs
1 // Copyright 2014 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 // A first "spike" for incremental compilation: here, we change the
12 // content of the `make` function, and we find that we can reuse the
13 // `y` module entirely (but not the `x` module).
14
15 // revisions:rpass1 rpass2
16
17 #![feature(rustc_attrs)]
18
19 #![rustc_partition_reused(module="spike", cfg="rpass2")]
20 #![rustc_partition_translated(module="spike-x", cfg="rpass2")]
21 #![rustc_partition_reused(module="spike-y", cfg="rpass2")]
22
23 mod x {
24     pub struct X {
25         x: u32, y: u32,
26     }
27
28     #[cfg(rpass1)]
29     fn make() -> X {
30         X { x: 22, y: 0 }
31     }
32
33     #[cfg(rpass2)]
34     fn make() -> X {
35         X { x: 11, y: 11 }
36     }
37
38     pub fn new() -> X {
39         make()
40     }
41
42     pub fn sum(x: &X) -> u32 {
43         x.x + x.y
44     }
45 }
46
47 mod y {
48     use x;
49
50     pub fn assert_sum() -> bool {
51         let x = x::new();
52         x::sum(&x) == 22
53     }
54 }
55
56 pub fn main() {
57     y::assert_sum();
58 }