Skip to content

Commit a488979

Browse files
committed
add test for changing pub inherent method body
Ideally, callers should not be affected, but they currently are.
1 parent 01d061f commit a488979

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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:rpass1 rpass2
15+
// compile-flags: -Z query-dep-graph
16+
17+
#![feature(rustc_attrs)]
18+
#![feature(stmt_expr_attributes)]
19+
#![allow(dead_code)]
20+
21+
#![rustc_partition_translated(module="struct_point-point", cfg="rpass2")]
22+
23+
// FIXME(#35078) -- this gets recompiled because we don't separate sig from body
24+
#![rustc_partition_translated(module="struct_point-fn_calls_changed_method", cfg="rpass2")]
25+
// FIXME(#36349) -- this gets recompiled because we don't separate items from impl
26+
#![rustc_partition_translated(module="struct_point-fn_calls_another_method", cfg="rpass2")]
27+
#![rustc_partition_reused(module="struct_point-fn_make_struct", cfg="rpass2")]
28+
#![rustc_partition_reused(module="struct_point-fn_read_field", cfg="rpass2")]
29+
#![rustc_partition_reused(module="struct_point-fn_write_field", cfg="rpass2")]
30+
31+
mod point {
32+
pub struct Point {
33+
pub x: f32,
34+
pub y: f32,
35+
}
36+
37+
impl Point {
38+
pub fn distance_from_origin(&self) -> f32 {
39+
#[cfg(rpass1)]
40+
return self.x * self.x + self.y * self.y;
41+
42+
#[cfg(rpass2)]
43+
return (self.x * self.x + self.y * self.y).sqrt();
44+
}
45+
46+
pub fn x(&self) -> f32 {
47+
self.x
48+
}
49+
}
50+
}
51+
52+
/// A fn item that calls (public) methods on `Point` from the same impl which changed
53+
mod fn_calls_changed_method {
54+
use point::Point;
55+
56+
// FIXME(#35078) -- this gets recompiled because we don't separate sig from body
57+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
58+
pub fn check() {
59+
let p = Point { x: 2.0, y: 2.0 };
60+
p.distance_from_origin();
61+
}
62+
}
63+
64+
/// A fn item that calls (public) methods on `Point` from the same impl which changed
65+
mod fn_calls_another_method {
66+
use point::Point;
67+
68+
// FIXME(#36349) -- this gets recompiled because we don't separate items from impl
69+
#[rustc_dirty(label="TypeckItemBody", cfg="rpass2")]
70+
pub fn check() {
71+
let p = Point { x: 2.0, y: 2.0 };
72+
p.x();
73+
}
74+
}
75+
76+
/// A fn item that makes an instance of `Point` but does not invoke methods
77+
mod fn_make_struct {
78+
use point::Point;
79+
80+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
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+
mod fn_read_field {
88+
use point::Point;
89+
90+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
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+
mod fn_write_field {
98+
use point::Point;
99+
100+
#[rustc_clean(label="TypeckItemBody", cfg="rpass2")]
101+
pub fn inc_x(p: &mut Point) {
102+
p.x += 1.0;
103+
}
104+
}
105+
106+
fn main() {
107+
}

0 commit comments

Comments
 (0)