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.
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.
11 // Test where we change a type definition by adding a field. Fns with
12 // this type in their signature are recompiled, as are their callers.
13 // Fns with that type used only in their body are also recompiled, but
14 // their callers are not.
16 // revisions:rpass1 rpass2
17 // compile-flags: -Z query-dep-graph
19 #![feature(rustc_attrs)]
20 #![feature(stmt_expr_attributes)]
21 #![feature(static_in_const)]
24 // These are expected to require translation.
25 #![rustc_partition_translated(module="struct_point-point", cfg="rpass2")]
26 #![rustc_partition_translated(module="struct_point-fn_with_type_in_sig", cfg="rpass2")]
27 #![rustc_partition_translated(module="struct_point-call_fn_with_type_in_sig", cfg="rpass2")]
28 #![rustc_partition_translated(module="struct_point-fn_with_type_in_body", cfg="rpass2")]
29 #![rustc_partition_translated(module="struct_point-fn_make_struct", cfg="rpass2")]
30 #![rustc_partition_translated(module="struct_point-fn_read_field", cfg="rpass2")]
31 #![rustc_partition_translated(module="struct_point-fn_write_field", cfg="rpass2")]
33 #![rustc_partition_reused(module="struct_point-call_fn_with_type_in_body", cfg="rpass2")]
50 pub fn origin() -> Point
{
52 return Point { x: 0.0, y: 0.0 }
;
55 return Point { x: 0.0, y: 0.0, z: 0.0 }
;
58 pub fn total(&self) -> f32 {
60 return self.x
+ self.y
;
63 return self.x
+ self.y
+ self.z
;
66 pub fn x(&self) -> f32 {
72 /// A fn that has the changed type in its signature; must currently be
75 /// You could imagine that, in the future, if the change were
76 /// sufficiently "private", we might not need to type-check again.
77 /// Rebuilding is probably always necessary since the layout may be
79 mod fn_with_type_in_sig
{
82 #[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
83 pub fn boop(p
: Option
<&Point
>) -> f32 {
84 p
.map(|p
| p
.total()).unwrap_or(0.0)
88 /// Call a fn that has the changed type in its signature; this
89 /// currently must also be rebuilt.
91 /// You could imagine that, in the future, if the change were
92 /// sufficiently "private", we might not need to type-check again.
93 /// Rebuilding is probably always necessary since the layout may be
95 mod call_fn_with_type_in_sig
{
96 use fn_with_type_in_sig
;
98 #[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
100 fn_with_type_in_sig
::boop(None
)
104 /// A fn that uses the changed type, but only in its body, not its
107 /// You could imagine that, in the future, if the change were
108 /// sufficiently "private", we might not need to type-check again.
109 /// Rebuilding is probably always necessary since the layout may be
111 mod fn_with_type_in_body
{
114 #[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
115 pub fn boop() -> f32 {
116 Point
::origin().total()
120 /// A fn X that calls a fn Y, where Y uses the changed type in its
121 /// body. In this case, the effects of the change should be contained
122 /// to Y; X should not have to be rebuilt, nor should it need to be
123 /// typechecked again.
124 mod call_fn_with_type_in_body
{
125 use fn_with_type_in_body
;
127 #[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
128 pub fn bip() -> f32 {
129 fn_with_type_in_body
::boop()
133 /// A fn item that makes an instance of `Point` but does not invoke methods
137 #[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
138 pub fn make_origin(p
: Point
) -> Point
{
143 /// A fn item that reads fields from `Point` but does not invoke methods
147 #[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
148 pub fn get_x(p
: Point
) -> f32 {
153 /// A fn item that writes to a field of `Point` but does not invoke methods
157 #[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
158 pub fn inc_x(p
: &mut Point
) {