]>
Commit | Line | Data |
---|---|---|
c30ab7b3 SL |
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 | // Test where we change the body of a private method in an impl. | |
12 | // We then test what sort of functions must be rebuilt as a result. | |
13 | ||
abe05a73 | 14 | // revisions:cfail1 cfail2 |
c30ab7b3 | 15 | // compile-flags: -Z query-dep-graph |
abe05a73 | 16 | // must-compile-successfully |
c30ab7b3 SL |
17 | |
18 | #![feature(rustc_attrs)] | |
19 | #![feature(stmt_expr_attributes)] | |
20 | #![allow(dead_code)] | |
abe05a73 | 21 | #![crate_type = "rlib"] |
c30ab7b3 | 22 | |
abe05a73 | 23 | #![rustc_partition_translated(module="struct_point-point", cfg="cfail2")] |
c30ab7b3 | 24 | |
abe05a73 XL |
25 | #![rustc_partition_reused(module="struct_point-fn_calls_methods_in_same_impl", cfg="cfail2")] |
26 | #![rustc_partition_reused(module="struct_point-fn_calls_methods_in_another_impl", cfg="cfail2")] | |
27 | #![rustc_partition_reused(module="struct_point-fn_make_struct", cfg="cfail2")] | |
28 | #![rustc_partition_reused(module="struct_point-fn_read_field", cfg="cfail2")] | |
29 | #![rustc_partition_reused(module="struct_point-fn_write_field", cfg="cfail2")] | |
c30ab7b3 | 30 | |
abe05a73 | 31 | pub mod point { |
c30ab7b3 SL |
32 | pub struct Point { |
33 | pub x: f32, | |
34 | pub y: f32, | |
35 | } | |
36 | ||
37 | impl Point { | |
abe05a73 XL |
38 | pub fn distance_squared(&self) -> f32 { |
39 | #[cfg(cfail1)] | |
c30ab7b3 SL |
40 | return self.x + self.y; |
41 | ||
abe05a73 | 42 | #[cfg(cfail2)] |
c30ab7b3 SL |
43 | return self.x * self.x + self.y * self.y; |
44 | } | |
45 | ||
46 | pub fn distance_from_origin(&self) -> f32 { | |
47 | self.distance_squared().sqrt() | |
48 | } | |
49 | } | |
50 | ||
51 | impl Point { | |
52 | pub fn translate(&mut self, x: f32, y: f32) { | |
53 | self.x += x; | |
54 | self.y += y; | |
55 | } | |
56 | } | |
57 | ||
58 | } | |
59 | ||
60 | /// A fn item that calls (public) methods on `Point` from the same impl which changed | |
abe05a73 | 61 | pub mod fn_calls_methods_in_same_impl { |
c30ab7b3 SL |
62 | use point::Point; |
63 | ||
abe05a73 | 64 | #[rustc_clean(label="TypeckTables", cfg="cfail2")] |
c30ab7b3 SL |
65 | pub fn check() { |
66 | let x = Point { x: 2.0, y: 2.0 }; | |
67 | x.distance_from_origin(); | |
68 | } | |
69 | } | |
70 | ||
71 | /// A fn item that calls (public) methods on `Point` from another impl | |
abe05a73 | 72 | pub mod fn_calls_methods_in_another_impl { |
c30ab7b3 SL |
73 | use point::Point; |
74 | ||
abe05a73 | 75 | #[rustc_clean(label="TypeckTables", cfg="cfail2")] |
c30ab7b3 SL |
76 | pub fn check() { |
77 | let mut x = Point { x: 2.0, y: 2.0 }; | |
78 | x.translate(3.0, 3.0); | |
79 | } | |
80 | } | |
81 | ||
82 | /// A fn item that makes an instance of `Point` but does not invoke methods | |
abe05a73 | 83 | pub mod fn_make_struct { |
c30ab7b3 SL |
84 | use point::Point; |
85 | ||
abe05a73 | 86 | #[rustc_clean(label="TypeckTables", cfg="cfail2")] |
c30ab7b3 SL |
87 | pub fn make_origin() -> Point { |
88 | Point { x: 2.0, y: 2.0 } | |
89 | } | |
90 | } | |
91 | ||
92 | /// A fn item that reads fields from `Point` but does not invoke methods | |
abe05a73 | 93 | pub mod fn_read_field { |
c30ab7b3 SL |
94 | use point::Point; |
95 | ||
abe05a73 | 96 | #[rustc_clean(label="TypeckTables", cfg="cfail2")] |
c30ab7b3 SL |
97 | pub fn get_x(p: Point) -> f32 { |
98 | p.x | |
99 | } | |
100 | } | |
101 | ||
102 | /// A fn item that writes to a field of `Point` but does not invoke methods | |
abe05a73 | 103 | pub mod fn_write_field { |
c30ab7b3 SL |
104 | use point::Point; |
105 | ||
abe05a73 | 106 | #[rustc_clean(label="TypeckTables", cfg="cfail2")] |
c30ab7b3 SL |
107 | pub fn inc_x(p: &mut Point) { |
108 | p.x += 1.0; | |
109 | } | |
110 | } |