]> git.proxmox.com Git - rustc.git/blame - src/test/incremental/change_pub_inherent_method_sig/struct_point.rs
Update unsuspicious file list
[rustc.git] / src / test / incremental / change_pub_inherent_method_sig / struct_point.rs
CommitLineData
476ff2be
SL
1// Test where we change the *signature* of a public, inherent method.
2
abe05a73 3// revisions:cfail1 cfail2
476ff2be 4// compile-flags: -Z query-dep-graph
fc512014 5// build-pass
476ff2be 6
abe05a73 7#![crate_type = "rlib"]
476ff2be
SL
8#![feature(rustc_attrs)]
9#![feature(stmt_expr_attributes)]
476ff2be
SL
10#![allow(dead_code)]
11
94b46f34
XL
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")]
476ff2be 15
abe05a73
XL
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")]
476ff2be 20
abe05a73 21pub mod point {
476ff2be
SL
22 pub struct Point {
23 pub x: f32,
24 pub y: f32,
25 }
26
27 impl Point {
abe05a73 28 #[cfg(cfail1)]
476ff2be
SL
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
abe05a73 36 #[cfg(cfail2)]
476ff2be
SL
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
abe05a73 52pub mod fn_calls_changed_method {
476ff2be
SL
53 use point::Point;
54
17df50a5 55 #[rustc_clean(except="typeck,optimized_mir", cfg="cfail2")]
476ff2be
SL
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
abe05a73 63pub mod fn_calls_another_method {
476ff2be
SL
64 use point::Point;
65
17df50a5 66 #[rustc_clean(cfg="cfail2")]
476ff2be
SL
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
abe05a73 74pub mod fn_make_struct {
476ff2be
SL
75 use point::Point;
76
17df50a5 77 #[rustc_clean(cfg="cfail2")]
476ff2be
SL
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
abe05a73 84pub mod fn_read_field {
476ff2be
SL
85 use point::Point;
86
17df50a5 87 #[rustc_clean(cfg="cfail2")]
476ff2be
SL
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
abe05a73 94pub mod fn_write_field {
476ff2be
SL
95 use point::Point;
96
17df50a5 97 #[rustc_clean(cfg="cfail2")]
476ff2be
SL
98 pub fn inc_x(p: &mut Point) {
99 p.x += 1.0;
100 }
101}