]> git.proxmox.com Git - rustc.git/blob - src/test/incremental/change_private_impl_method/struct_point.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / test / incremental / change_private_impl_method / 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 body of a private method in an impl.
12 // We then test what sort of functions must be rebuilt as a result.
13
14 // revisions:cfail1 cfail2
15 // compile-flags: -Z query-dep-graph
16 // must-compile-successfully
17
18 #![feature(rustc_attrs)]
19 #![feature(stmt_expr_attributes)]
20 #![allow(dead_code)]
21 #![crate_type = "rlib"]
22
23 #![rustc_partition_translated(module="struct_point-point", cfg="cfail2")]
24
25 #![rustc_partition_reused(module="struct_point-fn_calls_methods_in_same_impl", cfg="cfail2")]
26 #![rustc_partition_reused(module="struct_point-fn_calls_methods_in_another_impl", cfg="cfail2")]
27 #![rustc_partition_reused(module="struct_point-fn_make_struct", cfg="cfail2")]
28 #![rustc_partition_reused(module="struct_point-fn_read_field", cfg="cfail2")]
29 #![rustc_partition_reused(module="struct_point-fn_write_field", cfg="cfail2")]
30
31 pub mod point {
32 pub struct Point {
33 pub x: f32,
34 pub y: f32,
35 }
36
37 impl Point {
38 pub fn distance_squared(&self) -> f32 {
39 #[cfg(cfail1)]
40 return self.x + self.y;
41
42 #[cfg(cfail2)]
43 return self.x * self.x + self.y * self.y;
44 }
45
46 pub fn distance_from_origin(&self) -> f32 {
47 self.distance_squared().sqrt()
48 }
49 }
50
51 impl Point {
52 pub fn translate(&mut self, x: f32, y: f32) {
53 self.x += x;
54 self.y += y;
55 }
56 }
57
58 }
59
60 /// A fn item that calls (public) methods on `Point` from the same impl which changed
61 pub mod fn_calls_methods_in_same_impl {
62 use point::Point;
63
64 #[rustc_clean(label="TypeckTables", cfg="cfail2")]
65 pub fn check() {
66 let x = Point { x: 2.0, y: 2.0 };
67 x.distance_from_origin();
68 }
69 }
70
71 /// A fn item that calls (public) methods on `Point` from another impl
72 pub mod fn_calls_methods_in_another_impl {
73 use point::Point;
74
75 #[rustc_clean(label="TypeckTables", cfg="cfail2")]
76 pub fn check() {
77 let mut x = Point { x: 2.0, y: 2.0 };
78 x.translate(3.0, 3.0);
79 }
80 }
81
82 /// A fn item that makes an instance of `Point` but does not invoke methods
83 pub mod fn_make_struct {
84 use point::Point;
85
86 #[rustc_clean(label="TypeckTables", cfg="cfail2")]
87 pub fn make_origin() -> Point {
88 Point { x: 2.0, y: 2.0 }
89 }
90 }
91
92 /// A fn item that reads fields from `Point` but does not invoke methods
93 pub mod fn_read_field {
94 use point::Point;
95
96 #[rustc_clean(label="TypeckTables", cfg="cfail2")]
97 pub fn get_x(p: Point) -> f32 {
98 p.x
99 }
100 }
101
102 /// A fn item that writes to a field of `Point` but does not invoke methods
103 pub mod fn_write_field {
104 use point::Point;
105
106 #[rustc_clean(label="TypeckTables", cfg="cfail2")]
107 pub fn inc_x(p: &mut Point) {
108 p.x += 1.0;
109 }
110 }