]> git.proxmox.com Git - rustc.git/blob - src/test/incremental/change_private_fn/struct_point.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / incremental / change_private_fn / struct_point.rs
1 // Test where we change the body of a private method in an impl.
2 // We then test what sort of functions must be rebuilt as a result.
3
4 // revisions:cfail1 cfail2
5 // compile-flags: -Z query-dep-graph
6 // build-pass (FIXME(62277): could be check-pass?)
7
8 #![feature(rustc_attrs)]
9 #![feature(stmt_expr_attributes)]
10 #![allow(dead_code)]
11 #![crate_type = "rlib"]
12
13 #![rustc_partition_codegened(module="struct_point-point", cfg="cfail2")]
14
15 #![rustc_partition_reused(module="struct_point-fn_calls_methods_in_same_impl", cfg="cfail2")]
16 #![rustc_partition_reused(module="struct_point-fn_calls_methods_in_another_impl", 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 fn distance_squared(this: &Point) -> f32 {
28 #[cfg(cfail1)]
29 return this.x + this.y;
30
31 #[cfg(cfail2)]
32 return this.x * this.x + this.y * this.y;
33 }
34
35 impl Point {
36 pub fn distance_from_origin(&self) -> f32 {
37 distance_squared(self).sqrt()
38 }
39 }
40
41 impl Point {
42 pub fn translate(&mut self, x: f32, y: f32) {
43 self.x += x;
44 self.y += y;
45 }
46 }
47
48 }
49
50 /// A fn item that calls (public) methods on `Point` from the same impl which changed
51 pub mod fn_calls_methods_in_same_impl {
52 use point::Point;
53
54 // The cached result should actually be loaded from disk
55 // (not just marked green) - for example, `DeadVisitor`
56 // always runs during compilation as a "pass", and loads
57 // the typeck results for bodies.
58 #[rustc_clean(cfg="cfail2", loaded_from_disk="typeck")]
59 pub fn check() {
60 let x = Point { x: 2.0, y: 2.0 };
61 x.distance_from_origin();
62 }
63 }
64
65 /// A fn item that calls (public) methods on `Point` from another impl
66 pub mod fn_calls_methods_in_another_impl {
67 use point::Point;
68
69 #[rustc_clean(cfg="cfail2")]
70 pub fn check() {
71 let mut x = Point { x: 2.0, y: 2.0 };
72 x.translate(3.0, 3.0);
73 }
74 }
75
76 /// A fn item that makes an instance of `Point` but does not invoke methods
77 pub mod fn_make_struct {
78 use point::Point;
79
80 #[rustc_clean(cfg="cfail2")]
81 pub fn make_origin() -> Point {
82 Point { x: 2.0, y: 2.0 }
83 }
84 }
85
86 /// A fn item that reads fields from `Point` but does not invoke methods
87 pub mod fn_read_field {
88 use point::Point;
89
90 #[rustc_clean(cfg="cfail2")]
91 pub fn get_x(p: Point) -> f32 {
92 p.x
93 }
94 }
95
96 /// A fn item that writes to a field of `Point` but does not invoke methods
97 pub mod fn_write_field {
98 use point::Point;
99
100 #[rustc_clean(cfg="cfail2")]
101 pub fn inc_x(p: &mut Point) {
102 p.x += 1.0;
103 }
104 }