Skip to content

Commit 30b97aa

Browse files
committed
add test for adding a field
1 parent 70a1459 commit 30b97aa

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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 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.
15+
16+
// revisions:rpass1 rpass2
17+
// compile-flags: -Z query-dep-graph
18+
19+
#![feature(rustc_attrs)]
20+
#![feature(stmt_expr_attributes)]
21+
#![feature(static_in_const)]
22+
#![allow(dead_code)]
23+
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")]
32+
33+
#![rustc_partition_reused(module="struct_point-call_fn_with_type_in_body", cfg="rpass2")]
34+
35+
mod point {
36+
#[cfg(rpass1)]
37+
pub struct Point {
38+
pub x: f32,
39+
pub y: f32,
40+
}
41+
42+
#[cfg(rpass2)]
43+
pub struct Point {
44+
pub x: f32,
45+
pub y: f32,
46+
pub z: f32,
47+
}
48+
49+
impl Point {
50+
pub fn origin() -> Point {
51+
#[cfg(rpass1)]
52+
return Point { x: 0.0, y: 0.0 };
53+
54+
#[cfg(rpass2)]
55+
return Point { x: 0.0, y: 0.0, z: 0.0 };
56+
}
57+
58+
pub fn total(&self) -> f32 {
59+
#[cfg(rpass1)]
60+
return self.x + self.y;
61+
62+
#[cfg(rpass2)]
63+
return self.x + self.y + self.z;
64+
}
65+
66+
pub fn x(&self) -> f32 {
67+
self.x
68+
}
69+
}
70+
}
71+
72+
/// A fn item that calls (public) methods on `Point` from the same impl which changed
73+
mod fn_with_type_in_sig {
74+
use point::Point;
75+
76+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
77+
pub fn boop(p: Option<&Point>) -> f32 {
78+
p.map(|p| p.total()).unwrap_or(0.0)
79+
}
80+
}
81+
82+
mod call_fn_with_type_in_sig {
83+
use fn_with_type_in_sig;
84+
85+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
86+
pub fn bip() -> f32 {
87+
fn_with_type_in_sig::boop(None)
88+
}
89+
}
90+
91+
/// A fn item that calls (public) methods on `Point` from the same impl which changed
92+
mod fn_with_type_in_body {
93+
use point::Point;
94+
95+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
96+
pub fn boop() -> f32 {
97+
Point::origin().total()
98+
}
99+
}
100+
101+
/// A fn item that calls (public) methods on `Point` from the same impl which changed
102+
mod call_fn_with_type_in_body {
103+
use fn_with_type_in_body;
104+
105+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
106+
pub fn bip() -> f32 {
107+
fn_with_type_in_body::boop()
108+
}
109+
}
110+
111+
/// A fn item that makes an instance of `Point` but does not invoke methods
112+
mod fn_make_struct {
113+
use point::Point;
114+
115+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
116+
pub fn make_origin(p: Point) -> Point {
117+
Point { ..p }
118+
}
119+
}
120+
121+
/// A fn item that reads fields from `Point` but does not invoke methods
122+
mod fn_read_field {
123+
use point::Point;
124+
125+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
126+
pub fn get_x(p: Point) -> f32 {
127+
p.x
128+
}
129+
}
130+
131+
/// A fn item that writes to a field of `Point` but does not invoke methods
132+
mod fn_write_field {
133+
use point::Point;
134+
135+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
136+
pub fn inc_x(p: &mut Point) {
137+
p.x += 1.0;
138+
}
139+
}
140+
141+
fn main() {
142+
}

0 commit comments

Comments
 (0)