]> git.lizzy.rs Git - rust.git/blob - tests/incremental/change_pub_inherent_method_sig/struct_point.rs
Encode whether foreign opaques are TAITs or not
[rust.git] / tests / incremental / change_pub_inherent_method_sig / struct_point.rs
1 // Test where we change the *signature* of a public, inherent method.
2
3 // revisions:cfail1 cfail2
4 // compile-flags: -Z query-dep-graph
5 // build-pass
6
7 #![crate_type = "rlib"]
8 #![feature(rustc_attrs)]
9 #![feature(stmt_expr_attributes)]
10 #![allow(dead_code)]
11
12 // These are expected to require codegen.
13 #![rustc_partition_codegened(module="struct_point-point", cfg="cfail2")]
14 #![rustc_partition_codegened(module="struct_point-fn_calls_changed_method", cfg="cfail2")]
15
16 #![rustc_partition_reused(module="struct_point-fn_calls_another_method", cfg="cfail2")]
17 #![rustc_partition_reused(module="struct_point-fn_make_struct", cfg="cfail2")]
18 #![rustc_partition_reused(module="struct_point-fn_read_field", cfg="cfail2")]
19 #![rustc_partition_reused(module="struct_point-fn_write_field", cfg="cfail2")]
20
21 pub mod point {
22     pub struct Point {
23         pub x: f32,
24         pub y: f32,
25     }
26
27     impl Point {
28         #[cfg(cfail1)]
29         pub fn distance_from_point(&self, p: Option<Point>) -> f32 {
30             let p = p.unwrap_or(Point { x: 0.0, y: 0.0 });
31             let x_diff = self.x - p.x;
32             let y_diff = self.y - p.y;
33             return x_diff * x_diff + y_diff * y_diff;
34         }
35
36         #[cfg(cfail2)]
37         pub fn distance_from_point(&self, p: Option<&Point>) -> f32 {
38             const ORIGIN: &Point = &Point { x: 0.0, y: 0.0 };
39             let p = p.unwrap_or(ORIGIN);
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         pub fn x(&self) -> f32 {
46             self.x
47         }
48     }
49 }
50
51 /// A fn item that calls the method that was changed
52 pub mod fn_calls_changed_method {
53     use point::Point;
54
55     #[rustc_clean(except="typeck,optimized_mir", cfg="cfail2")]
56     pub fn check() {
57         let p = Point { x: 2.0, y: 2.0 };
58         p.distance_from_point(None);
59     }
60 }
61
62 /// A fn item that calls a method that was not changed
63 pub mod fn_calls_another_method {
64     use point::Point;
65
66     #[rustc_clean(cfg="cfail2")]
67     pub fn check() {
68         let p = Point { x: 2.0, y: 2.0 };
69         p.x();
70     }
71 }
72
73 /// A fn item that makes an instance of `Point` but does not invoke methods
74 pub mod fn_make_struct {
75     use point::Point;
76
77     #[rustc_clean(cfg="cfail2")]
78     pub fn make_origin() -> Point {
79         Point { x: 2.0, y: 2.0 }
80     }
81 }
82
83 /// A fn item that reads fields from `Point` but does not invoke methods
84 pub mod fn_read_field {
85     use point::Point;
86
87     #[rustc_clean(cfg="cfail2")]
88     pub fn get_x(p: Point) -> f32 {
89         p.x
90     }
91 }
92
93 /// A fn item that writes to a field of `Point` but does not invoke methods
94 pub mod fn_write_field {
95     use point::Point;
96
97     #[rustc_clean(cfg="cfail2")]
98     pub fn inc_x(p: &mut Point) {
99         p.x += 1.0;
100     }
101 }