]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/change_pub_inherent_method_sig/struct_point.rs
Unignore u128 test for stage 0,1
[rust.git] / src / test / incremental / change_pub_inherent_method_sig / struct_point.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 // Test where we change the *signature* of a public, inherent method.
12
13 // revisions:rpass1 rpass2
14 // compile-flags: -Z query-dep-graph
15
16 #![feature(rustc_attrs)]
17 #![feature(stmt_expr_attributes)]
18 #![feature(static_in_const)]
19 #![allow(dead_code)]
20
21 // These are expected to require translation.
22 #![rustc_partition_translated(module="struct_point-point", cfg="rpass2")]
23 #![rustc_partition_translated(module="struct_point-fn_calls_changed_method", cfg="rpass2")]
24
25 #![rustc_partition_reused(module="struct_point-fn_calls_another_method", cfg="rpass2")]
26 #![rustc_partition_reused(module="struct_point-fn_make_struct", cfg="rpass2")]
27 #![rustc_partition_reused(module="struct_point-fn_read_field", cfg="rpass2")]
28 #![rustc_partition_reused(module="struct_point-fn_write_field", cfg="rpass2")]
29
30 mod point {
31     pub struct Point {
32         pub x: f32,
33         pub y: f32,
34     }
35
36     impl Point {
37         #[cfg(rpass1)]
38         pub fn distance_from_point(&self, p: Option<Point>) -> f32 {
39             let p = p.unwrap_or(Point { x: 0.0, y: 0.0 });
40             let x_diff = self.x - p.x;
41             let y_diff = self.y - p.y;
42             return x_diff * x_diff + y_diff * y_diff;
43         }
44
45         #[cfg(rpass2)]
46         pub fn distance_from_point(&self, p: Option<&Point>) -> f32 {
47             const ORIGIN: &Point = &Point { x: 0.0, y: 0.0 };
48             let p = p.unwrap_or(ORIGIN);
49             let x_diff = self.x - p.x;
50             let y_diff = self.y - p.y;
51             return x_diff * x_diff + y_diff * y_diff;
52         }
53
54         pub fn x(&self) -> f32 {
55             self.x
56         }
57     }
58 }
59
60 /// A fn item that calls the method that was changed
61 mod fn_calls_changed_method {
62     use point::Point;
63
64     #[rustc_dirty(label="TypeckTables", cfg="rpass2")]
65     pub fn check() {
66         let p = Point { x: 2.0, y: 2.0 };
67         p.distance_from_point(None);
68     }
69 }
70
71 /// A fn item that calls a method that was not changed
72 mod fn_calls_another_method {
73     use point::Point;
74
75     #[rustc_clean(label="TypeckTables", cfg="rpass2")]
76     pub fn check() {
77         let p = Point { x: 2.0, y: 2.0 };
78         p.x();
79     }
80 }
81
82 /// A fn item that makes an instance of `Point` but does not invoke methods
83 mod fn_make_struct {
84     use point::Point;
85
86     #[rustc_clean(label="TypeckTables", cfg="rpass2")]
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
93 mod fn_read_field {
94     use point::Point;
95
96     #[rustc_clean(label="TypeckTables", cfg="rpass2")]
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
103 mod fn_write_field {
104     use point::Point;
105
106     #[rustc_clean(label="TypeckTables", cfg="rpass2")]
107     pub fn inc_x(p: &mut Point) {
108         p.x += 1.0;
109     }
110 }
111
112 fn main() {
113 }