]> git.lizzy.rs Git - rust.git/blob - src/test/incremental/change_pub_inherent_method_sig/struct_point.rs
Rollup merge of #39604 - est31:i128_tests, r=alexcrichton
[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 #![allow(dead_code)]
19
20 // These are expected to require translation.
21 #![rustc_partition_translated(module="struct_point-point", cfg="rpass2")]
22 #![rustc_partition_translated(module="struct_point-fn_calls_changed_method", cfg="rpass2")]
23
24 #![rustc_partition_reused(module="struct_point-fn_calls_another_method", cfg="rpass2")]
25 #![rustc_partition_reused(module="struct_point-fn_make_struct", cfg="rpass2")]
26 #![rustc_partition_reused(module="struct_point-fn_read_field", cfg="rpass2")]
27 #![rustc_partition_reused(module="struct_point-fn_write_field", cfg="rpass2")]
28
29 mod point {
30     pub struct Point {
31         pub x: f32,
32         pub y: f32,
33     }
34
35     impl Point {
36         #[cfg(rpass1)]
37         pub fn distance_from_point(&self, p: Option<Point>) -> f32 {
38             let p = p.unwrap_or(Point { x: 0.0, y: 0.0 });
39             let x_diff = self.x - p.x;
40             let y_diff = self.y - p.y;
41             return x_diff * x_diff + y_diff * y_diff;
42         }
43
44         #[cfg(rpass2)]
45         pub fn distance_from_point(&self, p: Option<&Point>) -> f32 {
46             const ORIGIN: &Point = &Point { x: 0.0, y: 0.0 };
47             let p = p.unwrap_or(ORIGIN);
48             let x_diff = self.x - p.x;
49             let y_diff = self.y - p.y;
50             return x_diff * x_diff + y_diff * y_diff;
51         }
52
53         pub fn x(&self) -> f32 {
54             self.x
55         }
56     }
57 }
58
59 /// A fn item that calls the method that was changed
60 mod fn_calls_changed_method {
61     use point::Point;
62
63     #[rustc_dirty(label="TypeckTables", cfg="rpass2")]
64     pub fn check() {
65         let p = Point { x: 2.0, y: 2.0 };
66         p.distance_from_point(None);
67     }
68 }
69
70 /// A fn item that calls a method that was not changed
71 mod fn_calls_another_method {
72     use point::Point;
73
74     #[rustc_clean(label="TypeckTables", cfg="rpass2")]
75     pub fn check() {
76         let p = Point { x: 2.0, y: 2.0 };
77         p.x();
78     }
79 }
80
81 /// A fn item that makes an instance of `Point` but does not invoke methods
82 mod fn_make_struct {
83     use point::Point;
84
85     #[rustc_clean(label="TypeckTables", cfg="rpass2")]
86     pub fn make_origin() -> Point {
87         Point { x: 2.0, y: 2.0 }
88     }
89 }
90
91 /// A fn item that reads fields from `Point` but does not invoke methods
92 mod fn_read_field {
93     use point::Point;
94
95     #[rustc_clean(label="TypeckTables", cfg="rpass2")]
96     pub fn get_x(p: Point) -> f32 {
97         p.x
98     }
99 }
100
101 /// A fn item that writes to a field of `Point` but does not invoke methods
102 mod fn_write_field {
103     use point::Point;
104
105     #[rustc_clean(label="TypeckTables", cfg="rpass2")]
106     pub fn inc_x(p: &mut Point) {
107         p.x += 1.0;
108     }
109 }
110
111 fn main() {
112 }