]> git.lizzy.rs Git - rust.git/blob - tests/incremental/change_pub_inherent_method_body/struct_point.rs
Encode whether foreign opaques are TAITs or not
[rust.git] / tests / incremental / change_pub_inherent_method_body / struct_point.rs
1 // Test where we change the body 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 #![rustc_partition_codegened(module="struct_point-point", cfg="cfail2")]
13
14 #![rustc_partition_reused(module="struct_point-fn_calls_changed_method", cfg="cfail2")]
15 #![rustc_partition_reused(module="struct_point-fn_calls_another_method", cfg="cfail2")]
16 #![rustc_partition_reused(module="struct_point-fn_make_struct", cfg="cfail2")]
17 #![rustc_partition_reused(module="struct_point-fn_read_field", cfg="cfail2")]
18 #![rustc_partition_reused(module="struct_point-fn_write_field", cfg="cfail2")]
19
20 pub mod point {
21     pub struct Point {
22         pub x: f32,
23         pub y: f32,
24     }
25
26     impl Point {
27         pub fn distance_from_origin(&self) -> f32 {
28             #[cfg(cfail1)]
29             return self.x * self.x + self.y * self.y;
30
31             #[cfg(cfail2)]
32             return (self.x * self.x + self.y * self.y).sqrt();
33         }
34
35         pub fn x(&self) -> f32 {
36             self.x
37         }
38     }
39 }
40
41 /// A fn item that calls the method on `Point` which changed
42 pub mod fn_calls_changed_method {
43     use point::Point;
44
45     #[rustc_clean(cfg="cfail2")]
46     pub fn check() {
47         let p = Point { x: 2.0, y: 2.0 };
48         p.distance_from_origin();
49     }
50 }
51
52 /// A fn item that calls a method on `Point` which did not change
53 pub mod fn_calls_another_method {
54     use point::Point;
55
56     #[rustc_clean(cfg="cfail2")]
57     pub fn check() {
58         let p = Point { x: 2.0, y: 2.0 };
59         p.x();
60     }
61 }
62
63 /// A fn item that makes an instance of `Point` but does not invoke methods
64 pub mod fn_make_struct {
65     use point::Point;
66
67     #[rustc_clean(cfg="cfail2")]
68     pub fn make_origin() -> Point {
69         Point { x: 2.0, y: 2.0 }
70     }
71 }
72
73 /// A fn item that reads fields from `Point` but does not invoke methods
74 pub mod fn_read_field {
75     use point::Point;
76
77     #[rustc_clean(cfg="cfail2")]
78     pub fn get_x(p: Point) -> f32 {
79         p.x
80     }
81 }
82
83 /// A fn item that writes to a field of `Point` but does not invoke methods
84 pub mod fn_write_field {
85     use point::Point;
86
87     #[rustc_clean(cfg="cfail2")]
88     pub fn inc_x(p: &mut Point) {
89         p.x += 1.0;
90     }
91 }