2017-10-04 10:47:19 -05:00
|
|
|
// revisions: ast mir
|
2017-11-19 16:37:59 -06:00
|
|
|
//[mir]compile-flags: -Z borrowck=mir
|
2017-10-04 10:47:19 -05:00
|
|
|
|
|
|
|
// Check that do not allow access to fields of uninitialized or moved
|
|
|
|
// structs.
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct Point {
|
|
|
|
x: isize,
|
|
|
|
y: isize,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
struct Line {
|
|
|
|
origin: Point,
|
|
|
|
middle: Point,
|
|
|
|
target: Point,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Line { fn consume(self) { } }
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut a: Point;
|
|
|
|
let _ = a.x + 1; //[ast]~ ERROR use of possibly uninitialized variable: `a.x`
|
2017-11-19 16:37:59 -06:00
|
|
|
//[mir]~^ ERROR [E0381]
|
2017-10-04 10:47:19 -05:00
|
|
|
|
|
|
|
let mut line1 = Line::default();
|
|
|
|
let _moved = line1.origin;
|
2018-04-04 19:20:21 -05:00
|
|
|
let _ = line1.origin.x + 1; //[ast]~ ERROR use of moved value: `line1.origin.x`
|
2017-11-19 16:37:59 -06:00
|
|
|
//[mir]~^ [E0382]
|
2017-10-04 10:47:19 -05:00
|
|
|
|
|
|
|
let mut line2 = Line::default();
|
|
|
|
let _moved = (line2.origin, line2.middle);
|
|
|
|
line2.consume(); //[ast]~ ERROR use of partially moved value: `line2` [E0382]
|
2017-11-19 16:37:59 -06:00
|
|
|
//[mir]~^ [E0382]
|
2017-10-04 10:47:19 -05:00
|
|
|
}
|